# Command and useful linux commands

December 23, 2025 Linux Fundamentals

Knowing how to use the command line effectively is a super power. Pair that with the knowledge of a shell scripting language like Bash and and even complex tasks can be performed in just a few lines of code.

File and folder

# make nested directories
$ mkdir -p /some/nested/path

# get size of a folder or folder.
$ du -hs /path/to/folder

# preview difference between two files
$ diff <file_one> <file_two>

# obfuscate a file (currupt without delete)
$ shred <file>

# view start of file
$ head <file>

# view end of file 
$ tail <file>

# view file one page at a time
$ less <file>

Copy files on remote machine

# using rsync. (RECOMMENDED)
$ rsync -avz --progress ./local/file <user>@<host>:'/remote/path/'

# copy file from remote machine.
$ rsync -avz --progress <user>@<host>:'/remote/path/filename' ./local/file

# using scp (i.e. ssh copy). Additional args: -i <ssh_key.pem> -P <port>
$ scp <username>@<ip_address>:/path/to/remote/file ./<local_directory>/file

Find files and folders

# find by name.
$ find /path/to/directory -name '*node-project*'

# find by name ignoring case.
$ find /path/to/directory -iname '*node-project*'

# find files over 1 MB in size. (k = KB, M = Mb, G = Gb)
$ find /folder -type f -size +1M

# find in directory and sub-directory
$ find /path/to/directory -iname '*.jpg' -ls

# find directories only.
$ find ~/Public/ -type d

# find a path.
$ find / -type d -name 'img' -ipath "*public_html/example.com*"

Archives

# compress multiple files.
$ zip archive.zip file1.txt file2.txt

# compress folder will all content.
$ zip -r archive.zip /path/to/folder

# unzip archive.
$ unzip archive.zip -d /output/directory
# compress directory using tar.
$ tar -czvf archive_name.tar.gz directory_name/

# uncompress tar.gz archive.
$ tar -xzvf archive_name.tar.gz

Processes

# find process by program name.
$ px aux | grep <program-name>

# find process using an system port.
$ lsof -i :<port>

# kill a process using PID.
$ kill -9 <pid>

IP

# find network interface names.
$ ip link show | grep -E '.: '

# find local IP address
$ ip addr | grep '<interface-name>'

SSH

# simply connect using username and password.
$ ssh <username>@<host>

# connect to remote server using ssh key
$ ssh -i <ssh_key.pem> <username>@<host>

Users

# add new user to the system
# without password
$ sudo useradd <username>

# with password
$ sudo adduser <username>
# act as another user
$ su <username>
# set password for a user
$ sudo passwd <username>