CmdEnv

Working in command line environment

Job control

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# use kill to send signals
$ sleep 10000 &
[1] 5108
$ jobs
[1] + running sleep 10000
$ kill -STOP %1
[1] + suspended (signal) sleep 10000
$ jobs
[1] + suspended (signal) sleep 10000
$ kill -CONT %1
$ jobs
[1] + running sleep 10000
$ kill -QUIT %1
[1] + quit sleep 10000
$ jobs
$
# see more in the manual
$ man kill
$ man signal

use nohup tool to wrap your program in order to not disrupt by SIGHUP

1
$ man nohup

Terminal multiplexer

You may really want to have multiple separated space in your terminal, for example one side your editor and program running on the other side

Tmux

(screen is also useful)

Key concept in tmux(hierarchy)

Sessions

  • Windows(like tabs in browser)
    • Panes
1
2
3
4
5
6
$ tmux
# start a new session
$ ^Bd
[detached (from session 0)]
$ tmux ls
0: 1 windows (created Wed Nov 17 14:23:38 2021) [110x32]
1
2
3
4
$ tmux new -t hello
# create a new tmux session named hello, -t stands for target
$ tmux a -t 0
# attach to session 0, a short for attach, -t stands for target
1
2
3
4
5
6
$ tmux
$ ^Bc # create a new window in the session
$ python3
[mysess-2]0:bash- 1:python3*
$ ^Bp # previous window
[mysess-2]0:bash* 1:python3-
1
2
3
4
$ ^Bc
$ ^B, # rename the current window
$ ^B0 # jump to window 0
$ ^B2 # jump to window 2

windows

1
2
3
$ ^B% # split a window, creating a new pane
$ ^B+arrow key # focus on different panes
$ ^B+white space # like layout next in gdb, shift different layout
1
$ ^Bz # zoom in/out the current pane

  • using tmux is just similar to open new terminal

  • ^D can exit everything, no matter it is a session, a window or a pane

Configure cmd(Dot files, files starting with a .)

1
2
3
4
5
6
7
8
# in bash prompt string is $PS1
$ PS1='> '
> echo ok
ok
>
$ PS1="\w > "
~ > cd tempdir
~/tempdir >

Don’t want to spend time configuring all the things? Search on github!

(Read them and try to understand the part you want to copy instead of copying blindly)


  • You can use symbolic link to store your dotfiles in some other location

Working with remote machine

Upload file

1
2
$ scp /path/to/local/file user@ip:path/to/remote/file
$ man rsync

You can use tmux on remote machine to make thing continue running on remote machine even you ssh out