Quick reference of commonly used Linux commands

Looking to find the size of a directory? Or hunt for a rogue running process and terminate it? Here's a list of commonly used linux commands along with examples

Quick reference of commonly used Linux commands
Photo by Gabriel Heinzer / Unsplash

Create and change to a new directory

mkdir new_dir && cd $_

Or with a path

mkdir -p /home/ubuntu/new_dir && cd $_

Copy

all files and folders from Downloads to Archived

cp -a ~/Downloads/. ~/Archived/

brace expansion - copies index.php to index.php.bak

cp /var/www/vhosts/domain.com/httpdocs/index.php{,.bak}

Move/Rename

all the files and folders from Downloads to Archived

mv  -v ~/Downloads/* ~/Archived/

brace expansion - renames index.php to index.php.bak

mv /var/www/vhosts/domain.com/httpdocs/index.php{,.bak}

Delete

files and subfolders inside a folder

rm -rf ~/Downloads/*

only subfolders inside a folder

rm -rf ~/Downloads/*/

Check for running processes by name

look for a running MySQL instance

ps aux | grep mysql

most likely to kill it

kill -s 9 <PID_AS_OBTAINED_PREVIOUSLY>

Quickly check the size of a directory

du -sh /home/ubuntu/apps

or the current directory

du -sh .

biggest directories in CWD

du -hs * | sort -rh | head -5

Check which ports are listening

netstat -tulnp

Disk space overview

df -h
df -hT

By size

find /var/www/ -xdev -type f -size +100M

Introduction to tmux - How to run multiple terminal sessions and long running processes on a remote server
Looking to run an intense grep on your remote server? But now, you also need to compile node from source. Then, there’s the fear of your connection dropping and having to redo all of this from scratch. tmux is the way out of this potential mess.