CheatSheet | Linux


chmod

$ chmod -R [777] FOLDER_NAME


conda

# show the list of envs
$ conda info --envs
# Create conda ENV using specific python version
$ conda create --name myenv python=3.5
# Create conda ENV using the existing ENV
$ conda create --name myclone --clone myenv
# Remove activated #!/usr/bin/env
$ conda remove --name myenv --all

# Backup conda env
$ conda env export > [filename].yaml
# create conda env from yaml file
$ conda env create -f [filename].yaml


cron

# *(m) *(h) *(d) *(m) *(w)
$ crontab -e

# run every minute
* * * * * /home/script/test.sh

# run every 10min
0/10 * * * * 
# run every day
0 0 * * * 

curl

# -s, --silent
$ curl -s URL 

# -X, --request <command> Specify request command to use
$ curl -X GET URL 
$ curl -X POST URL


envsubst

  • changes ${VARNAME} in string
  • apt-get install gettext-base
# put /opt/nginx.conf and redirection output to /etc/ngix...
$ envsubst < /opt/nginx.conf > /etc/nginx/conf.d/default.conf


kill

# kill sends signal to process (-15:quit, -9:force quit)
$ kill -15 PID 
$ kill -9 PID

# pkill quit process bt name
$ pkill -f PROCESS_NAME


ls

# the number of directories in working directory
$ ls -l | grep ^d | wc -l
# the number of files in working directory
$ ls -l | grep ^- | wc -l
# the number of files in working directory
$ ls ./ | wc -l

# print all the files in dir
ls | gawk "BEGIN {\"pwd\" | getline cwd} {printf(\"%s/%s\n\", cwd, \$0)}"


ln

# Symbolic Link
$ ln -s ${SYM_SRC} ${SYM_DST} 
# Hard Link
$ ln ${HARD_SRC} ${HARD_DST}


ps

# show all processes
ps aux | grep PROCESS_NAME
# show the list of process, you can find Process ID using command below
$ ps -ef | grep python
# show the number of processes
$ ps -ef | grep -ic palantir


screen

# Create new session with name
$ screen -S name
# Create new session
$ Ctrl+a+c
# Move to next session
$ Ctrl+a+a
# Move to previous session
$ Ctrl+a+n

# quit the current screen session
$ Ctrl+d
# Detach current screen session
$ Ctrl+a+d
# Detach screen from remote
$ screen -d <SCREENID>

# connect to specific screen session using ID
$ screen -r <SCREENID>
# connect to specific screen session using name
$ screen -r name

# show the list of screen sessions
$ screen -ls
# kill the screen session using SCREENID
$ screen -X -S SCREENID quit


# split the screen 
$ Ctrl+a+|
# split the screen
$ Ctrl+a+S
# Resize the screen pane
$ Ctrl+a+: # to commmand mode
$ resize 30% 
# save layout
$ Ctrl+a+:
$ layout save default


ssh

# start ssh connection to remote server
$ ssh koreanbear@192.168.0.1
# start ssh connection to remote server using private key
$ ssh -i ~/Desktop/key.pem koreanbear@192.168.0.1
# copy test.txt from local PC to remote server
$ scp ./test.txt koreanbear@192.168.0.1:~/Desktop
$ rsync options source destination


tar

# tar
$ tar -cvf <FILENAME.tar> <DIRNAME>
# untar
$ tar -xvf <FILENAME.tar>
# tar.gz
$ tar -zcvf <FILENAME.tar.gz> <DIRNAME>
# untar.gz 
$ tar -zxvf <FILENAME.tar.gz>


tmux

  • Components:

    • Socket : composed of multiple sessions

    • Session : composed of multiple windows

    • Window : composed of multiple panes

    • Pane : windows can be splited into multiple panes (vertical, horizontal)

# Create new session with 
$ tmux -S "/PATH/TO/SOCKET" -s SESSION_NAME

# Show environment
$ tmux showenv -g