Useful Linux commands with examples

|

This post provides useful Linux commands with examples. There are many more basic commands than those listed here. However, I only listed the commands that can sometimes be confusing or forgotten, not the basic ones.

grep

Search a file for a pattern of characters, then display all matching lines.

grep -rnw path/to/dir -e ā€˜patternā€™

find

Search and locate the list of files and directories

find path/to/dir -name 'pattern'

scp

Copy file (folder with -r option) from a remote host to local host

scp user_id@IP_address:/path/to/target_file path/to/dir
scp -r user_id@IP_address:/path/to/target_folder path/to/dir

Copy file (folder with -r option) from local host to a remote host

scp path/to/target_file user_id@IP_address:/path/to/dir
scp -r path/to/target_dir user_id@IP_address:/path/to/dir

tar

Compress .tar

tar -cvf target.tar path/to/dir

Extract .tar

tar -xvf target.tar

zip

Compress .zip

zip -r target.zip path/to/dir
zip -r target.zip path/to/dir1 path/to/dir2 path/to/dir3

unzip

Extract .zip in current directory

unzip target.zip

Extract .zip in specific directory with -d option

unzip target.zip -d path/to/dir

df

Show all filesystems and their disk usage in human-readable form

df -h

du

Show the size of a single directory, in human-readable units

du -sh path/to/dir

chmod

Give full access to user and group (i.e read, write, and execute) on a specific file (or folder with -R option)

chmod ug+rwx target.file
chmod -R ug+rwx path/to/dir

Comments