Command Line Cheatsheet

Command Line Cheatsheet

January 1, 2020
★ Star me on GitHub

Get the meaning of shell command: just copy it and paste to explainshell

Change the default Shell:

chsh -s /bin/zsh

Check the size of a file/Directory:

du -sh [filePath/Directory]

Force delete files inside directory:

rm -rf dir
# -f for force, -r for recursive

Find file with a given pattern

find / -name filename.xx

Remove files with a given pattern

find . -name '*.pyc' -delete # remove all .pyc files from a project

Find all proccess with a name:

ps aux | grep [name]

Kill proccess with a name:

kill $(ps aux | grep [name] | awk '{print $2}')

View a log in realtime:

tail -f filename.log

Check netwok connectivity:

nc -z -v [ip] [port]

Check used port:

lsof -n -P | grep [port number] 

Downloading file with breakpoint resume:

wget -c [url]

Download file from remote server:

scp -i ssh-key-file [user]@[ip]:remote/file/path local/file/path

Upload file to remote server:

scp -i ssh-key-file [file/to/send] [user]@[ip]:[dest/path]

Give a script the execution permission:

chmod +x ./


Generate New SSH key files:

ssh-keygen -t rsa -C "remark"

Start SSH agent:

eval `ssh-agent -s`

Limit ssh key file access:

chmod 400 [key-path]

Enable a ssh key:

ssh-add [key-path] # without .pub

Create a socks v5 proxy with SSH:

ssh -i ssh-key-file -o IdentitiesOnly=yes [username]@[ip]  -D

Shell Loop:

for i in `seq -w 000 3`;do echo test_"${i}";done
# Output:
#  test_000
#  test_001
#  test_002
#  test_003


say hello world
# list all langs
say -v '?'
# list all file format
say --file-format=?
say -v Ting-Ting -o test.aac hello world