Contents

Cheatsheet for command line

usefull tools for linux command line

Make terminal cool, install OhMyZsh

1
2
3
4
5
6
7
8
# install zsh
sudo apt-get install zsh # ubuntu
# change default shell to zsh
chsh -s /usr/bin/zsh
# install ohmyzsh
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

source ~/.zshrc

ssh login withoutpassword

  1. on your local machine, run
1
ssh-keygen

press Enter 3 time until finished. a "~/.ssh/id_rsa.pub" and "~/.ssh.id_rsa" will be generated.

  1. copy the public key file to the remote machine
1
ssh-copy-id remote_username@remote_server_ip_address
  1. then you can login without password
1
ssh remote_username@remote_server_ip_address

Terminal keyboard shortcuts

  • Jump to head: Ctrl + a
  • Jump to end: Ctrl + e
  • Delete strings ahead: Ctrl + u
  • Delete strings follow: Ctrl + k

Program keeps running in the background

Run cmd using nohup

1
nohup command [options] &

Run cmd using zellij.

zellij is drop-in replacement of tmux

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

# create a new session
zellij 
# specify a new session, named bio
zellij -s bio

# subcommds 
zellij ls # list all session
zellij a bio # attach session
zellij ka # kill all sessions
zellij k bio # kill a specfic session, bio
zellij da # delete all session
zellji d bio # detelete a specifc session, bio

Run cmd using Tmux

Outside Tmux:
Typically these are run outside, but you can also run them inside an existing session

a. Start New Session

1
tmux new -s myname

b. Attach To Existing Session

1
2
tmux attach -t myname          #by name 
tmux attach 4                  #by number (in this case 4)

c. List Sessions

1
tmux ls

d. Kill Session

1
tmux kill-session -t myname

Inside Tmux Session:
Start each command with CTRL + b, release, then press one of the following:

Panes
%vertical split
"horizontal split
ddetach from session (it keeps running in the background)
xkill pane
Up/Down/Left/Rightmove between panes
PageUP/PageDownCTRL+c to exit the PageUp/Down mode
Fn+Up/DownPageUp/Down: Mac keyboard
: + resize-pane -DResizes the current pane down
: + resize-pane -UResizes the current pane upward
: + resize-pane -LResizes the current pane left
: + resize-pane -RResizes the current pane right
: + resize-pane -D 20Resizes the current pane down by 20 cells

File compression and decompression

Decompression

File typeCmde.g.
*.tartar -xvf
*.tar.gz or *.tgztar -xvzf
*bz2bzip2 -d or bunzip2
*.tar.bz2tar -xjf
*.Zuncompress
*.tar.Ztar -xZf
*.rarunrar e or rar xunrar e file.rar
*.zipunzip
*.gzgunzip

Compression

File typeCmde.g.
*.tartar -cvf
*.tar.gz or *.tgztar -cvzf
*bz2bzip2 -z
*.tar.bz2tar -cjf
*.Zcompress
*.tar.Ztar -cZf
*.rarrar arar a -ep1 newname /home/user/cpp
*.zipzip
*.gzgzip

For rar installation

1
sudo apt-get install rar

Handy tricks for handling filepath

very useful to strip file sufix, path et.al.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# e.g.
var=./home/fastq/filename_R1.fq.gz

# extract filename
${var#*/} # -> home/fastq/filename_R1.fq.gz
var1=${var##*/}  # -> filename_R1.fq.gz

# remove file suffix
${var1%.*} # -> filename_R1.fq
${var1%%.*} # -> filename_R1

# get basebame
var2=$(basename "${var}" .fq.gz) #-> filename_R1

vim shortcuts

In view mode, curso movement

1
2
3
4
5
6
7
8
9
^ (shift + 6): jump to the start of current line
$ (shift + 4): jump to the end of current line

gg: go to the first line of the document
G: go to the last line of the document

H: move to the top of screen
M: move to the middle of screen
L: move to the bottom of screen