d3xitfl0w@web: ~$ |

d3xitfl0w / ... / Useful Linux Commands

Created Fri, 09 May 2025 14:56:39 +0000 Modified Wed, 14 May 2025 17:11:33 +0000
4943 Words

Useful Linux commands with examples that helps you start and work with a Linux administration.

Useful Linux Commands

Note 💡 You can use Ctrl+f to search keywords in desktop browsers. For mobile go to menu -> Find in Page.

List of Basic Linux Commands

Basic File and Directory Management

ls - List files and directories contents.
cd - Change directory.
pwd - Print name of current/working directory.
mkdir - Create a new directory.
rm - Remove files or directories.
cp - Copy files or directories.
mv - Move or rename files and directories.
cat - Concatenate files and print file content on the standard output.
touch - Create an empty file or update the timestamp of an existing file.

File Permissions, Ownership and User Management

chmod - Change files/directories permissions.
chown - Change files/directories ownership.
chgrp - Change files/directories group ownership.
umask - Set default permissions for newly created files.
getfacl - Get the access control list (ACL) for a file.
setfacl - Set the access control list (ACL) for a file.
sudo - Execute a command with superuser privileges.

System Monitoring and Process Management

pgrep - Search for processes by name.
ps - Display running processes.
kill - Terminate processes.
killall - Terminate all processes by name.
uptime - Show how long the system has been running.
top - Display system resource usage and running processes.
htop - Interactive process viewer (more user-friendly than top).
free - Display amount of free and used memory in the system.
mount - Mount a filesystem. df - Display mounting points and disk space usage.
du - Estimate file and directory space usage.

Package Management

apt - Package manager for Debian-based distributions.
yum - Package manager for RPM-based distributions.

Text Processing and Viewing

head - Display the firs part of a file/files.
tail - Display the last part of a file/files.
more - View the contents of a file one page at a time.
less - View file content interactively. Allows searching in the file.
sort - Sort lines of text files.
uniq - Remove all the duplicates in a file.
grep - Search for patterns in files.
tr - Translate/Convert or delete characters.
sed - Stream editor for text manipulation.
awk - Text processing language.
cut - Extract sections from lines of files.
wc - Count lines, words, and characters in files.
diff - Compare files line by line.

Networking

ssh - Securely connect to a remote system.
ssh-keygen - Generate SSH key pairs.
scp - Securely copy files between systems.
rsync - Synchronize files and directories between locations.
ping - Send ICMP echo requests to a target host.
nslookup - Query DNS to obtain domain name or IP address mapping.
dig - Query DNS to obtain domain name or IP address mapping.
ip - Display or configure network interfaces (modern replacement for ifconfig).
ifconfig - Display network interfaces and configurations.
netstat - Display network statistics and connections.
ss - Utility to investigate sockets (replacement for netstat).
nmcli - Control and modify NetworkManager.
wget - Download files from the web.
curl - Transfer data from or to a server via various protocols.

System Utilities

uname - Print system information with kernel version.
man - Display the manual for a command.
history - Display command history.
tar - Archive files and directories.
gzip - Compress files using gzip compression.
gunzip - Decompress files compressed with gzip.
find - Search for files and directories.
locate - Quickly find files by name using a prebuilt database.
updatedb- Update db for locate command.
whereis - Locate the binary, source, and manual page files for a command.
ln - Create links between files.
alias - Create custom command aliases.
unalias - Remove alias.
echo - Display a line of text or variables.
date - Display or set the system date and time.
clear - Clear the terminal screen.
reboot - Reboot the system.
shutdown - Shutdown the system.
sleep - Delay for a specified amount of time.
time - Measure the duration of command execution.
watch - Execute a program periodically, showing output fullscreen.

Useful Linux Commands with Examples:

Basic File and Directory Management

ls

List files and directories contents.

# List files and directories in the current directory
ls
# List files and directories with permissions in the current directory 
ls -l
# List files and directories with permissions in the current directory and hidden files (hidden files are preceded with a period '.' in UNIX-like systems) 
ls -la
# List files and sort them by time (newest first), with reverse order, and human-readable format. The newest file will be at the bottom of the screen.
ls -ltrh
# Colorize the listing 
ls --color=auto
# De-colorize the listing 
ls --color=never

cd

Change directory.

# Change current directory to /var/tmp
cd /var/tmp
# Change directory to your home's Desktop directory. ('~' means home directory) 
cd ~/Desktop
# Change directory to Desktop using relative path. Let's assume your are in /home/username/ directory
cd Desktop
# Change current directory back to the previous directory (path)
cd -
# Change directory one directory up (to the parent directory)
cd ..
# Change directory two directories up
cd ../../

pwd

Print name of current/working directory.

# Print current directory
pwd

mkdir

Create a new directory.

# Create empty directory
mkdir new_dir1
# Create mulilple empty directories
mkdir new_dir1 new_dir2 new_dir2
# Create subdirectories inside in a directory that is being created or an existing one
mdkir -p new_dir1/new_dir2/new_dir2
# Create a directory while specifying permissions e.g. full access (read,write,execute) 777.
mkdir -m 777 new_dir1

rm

Remove files or directories.

# Remove a file
rm file1
# Remove files 
rm file1 file2 file3 file4
# Remove a directory
rm -r dir1
# Remove directories
rm -r dir1 dir2 dir3

cp

Copy files or directories.

# Copy file1 and change its new clone's name to file1-clone
cp file1 file1-clone
# Copy file1 to new location/directory e.g. /tmp 
cp file1 /tmp/
# Copy dir1 and change its new clone's name to dir1-clone
cp -r file1 dir1-clone

mv

Move or rename files and directories.

# Move file1 from current directory to /tmp directory
mv file1 /tmp/
# Rename file1 to file2
mv file1 file2
# Move directory 'dir1' from current directory to '/tmp' directory
mv dir1 /tmp/
# Rename dir1 to dir2
mv dir1 dir2

cat

Concatenate files and print file content on the standard output.

# Display content of a file
cat file
# Concatenate and display 2 files 
cat file1 file2
# Concatenate 2 files and redirect output to a another file 
cat file1 file2 > file3
# Insert a separator '+++++++++' between 2 concatenated files. '-' means standard input
echo '+++++++++' | cat file1 - file2

touch

Create an empty file or update the timestamp of an existing file.

# Create new empty file
touch <new_file>
# Update access date for a file
touch <existing_file>

File Permissions, Ownership and User Management

chmod

Change files/directories permissions.

# Change permissions for file.txt. User Owner=rwx, Group Owner=rx, Other=rx, 
# Write (w), Read (r), Execute (x)
chmod 755 file.txt

Note: Link permissions don’t have meaning for permissions. The referenced file has the permissions that are taken under consideration. Don't change permissions for the link, but for the referenced/original file instead. 

chown

Change files/directories ownership.

# Change file owner and group owner  
chown user:group file.txt

chgrp

Change files/directories group ownership


# Change the group ownership of a file or directory
chgrp group_name file_name
# Change the group of all the files in the directories and in the sub-directories
chgrp -R group_name path/to/directory
# Changing the group based on a reference file instead of using the name of the group 
chgrp --reference=file2 file1

umask

Set default permissions for newly created files.

umask 

getfacl

Get the access control list (ACL) for a file.

# Display the ACL permission for a file named file1
$ getfacl file1
# owner: bob
# group: bob
user::rw-
group::rw-
other::r--

# Display the ACL entries only.
$ getfacl file1 
user::rw-
group::rw-
other::r--

# Display recursive ACL entries
$ getfacl -R dir1
# file: dir1
# owner: bob
# group: bob
user::rwx
group::rwx
other::r-x

# file: dir1/dir2
# owner: bob
# group: bob
user::rwx
group::rwx
other::r-x

# Displaying default ACL entries
$ getfacl -d dir1
# file: dir1
# owner: bob
# group: bob 
user::rwx
user:bob:rwx
group::rwx
mask::rwx
other::r-x

# Display extended ACL entries
$ getfacl -e file1
# file: file1
# owner: bob
# group: bob
user::rw-
user:bob:rw-	  #effective:rw-
group::rw-		  #effective:rw-
mask::rw-
other::r--

# Backup ACL permissions of multiple files
$ getfacl myweb morefiles > permissions.acl 
# -or- with absolute path
$ getfacl -p /var/www/myweb /home/linuxconfig/morefiles > permissions.acl 
# -or-  with *
$ getfacl -p /home/linuxconfig/* > permissions.acl 
# To restore ACL permissions use 'setfacl --restore=permissions.acl' command.

setfacl

Set the access control list (ACL) for a file.

# Modify ACLs of file
setfacl -m u:john:rw file
# Remove all extended ACL entries
setfacl -b file
# -or-
$ setfacl --remove-all file
# Remove group 'service2' from a file's ACL
$ setfacl -x g:service2 file
# -or-
$ setfacl --remove=g:service2 file
# Remove the default ACL
$ setfacl -k file
# -or-
$ setfacl --remove-default file
# Modify group in ACL recursively
$ setfacl -m g:service3:rw -R directory
# Restore ACL from backup
setfacl --restore=file

sudo

Execute a command with superuser privileges.

## Execute a command with superuser privileges to get content from unreadable directory to normal user
sudo ls /usr/local/protected

# Execute a command as user_name 
sudo -u user_name ls ~user_name
# Edit the index.html file as user www:
$ sudoedit -u www ~www/htdocs/index.html
# To  make  a usage listing of the directories in the /home partition.  The commands are run in a sub-shell to allow the 'cd' command and file redirection to work.
$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"

System Monitoring and Process Management

pgrep - Search for processes by name.

# Display PID of the process name given e.g. ssh
pgrep ssh
Output
xxxx
xxxx
xxx
# Display PID of the process name given e.g. ssh. pgrep prints each process ID on a newline. The -d option allows you to specify a different delimiter. Example for using a space as a delimiter
pgrep ssh -d' '
Output
xxxx xxxx xxx

# Show PID along with its name
pgrep ssh -l
# Match only the processes that names are exactly as the search pattern
pgrep '^ssh$' -l
# Display processes being run by a given user :
pgrep -u root
# Find the newest process started by the user 'john'
pgrep -lnu john

ps

Display running processes.

# Display a list of all running processes
ps -ef
# Display all process and grep to get lines with specified phrase e.g. root
ps -ef | grep root
# Display lines which don't contain the particular keyword e.g. ingore lines with grep phrase
ps -ef | grep -v grep

kill

Terminate processes.

# Kill process with specified ID
kill <process ID>

killall

Terminate all processes by name.

# Kill all processes with the specified name 
killall <process name>

uptime

Show how long the system has been running.

# Systme uptime and load
uptime

top

Display system resource usage and running processes in real-time

# Display real-time information about system processes and resource usage.
top
# Sort processes by memory usage
top -o MEM
# Display detailed information about a specific process. Replace PID with a process ID.
top -p PID
 

htop

Interactive process viewer (more user-friendly than top).

# Improved version of top. Display real-time information about system processes and resource usage
htop

mount

# Mount a filesystem. /dev/sdb1 to /mnt
mount /dev/sdb1 /mnt

free

Display amount of free and used memory in the system.

# Display the memory usage in a human-readable format
free -h

df

Display disk space usage.

# Display mounting points along with their disk space usage in a human-readable format.
df -h

du

Estimate file and directory space usage.

# Show directory/file size.
du -sh /path/to/directory

Package Management

apt

Package manager for Debian-based distributions.

# Install a package (debian based systems - new way)
apt install <package-name>
# Install a package (debian based systems - old way)
apt-get install <package-name>

yum/dnf

Package manager for RPM-based distributions.

# Install a package (Redhat, CentOS - new way)
dnf install <package name>
# Install a package (Redhat, CentOS - old way)
yum install <package name>

Text Processing and Viewing

Display the firs part of a file/files.

# Print first 10 lines of the file
head <filename>
# Print first 5 lines of the file
head -n 5 <filename>
# Print 10 lines from 11-20. 
head -n 20 <filename> | tail -10
# Print 10 lines from 10-20
head -n 20 <filename> | tail -n +10
# Print 13 lines from 8-20
head -n 20 <filename> | tail -n +8
# Print first 7 bytes (characters)  
head -c 7 <filename>

tail

Display the last part of a file/files.

# Print last 10 lines of the file
tail <filename>
# Print last 5 lines of the file
tail -n 5 <filename>
# Print all lines till the end starting from 5th line of the file
tail -n +5 <filename>
# Monitor log file in real time
tail -f <log-file>
# Monitor log file in real time but wait for the input file to be created if the file doesn’t exist
tail -F <log-file>
# List last 3 modified files
ls -ltr | tail -n3
# List last 3 lines numbered
nl <filename> | tail -3

more

View the contents of a file one page at a time.

# View the content of a file 
more /var/log/syslog

less

View file content interactively. Allows searching in the file.

q- Used to quit out of less and go back to your shell.
Page up, Page down, Up and Down - Navigate using the arrow keys and page keys.
g - Moves to beginning of the text file.
G - Moves to the end of the text file.
h - Get help

# View the content of a file 
less /var/log/syslog

sort

Sort lines of text files.

# sort by string
sort file 
# sort numerically (default sort is for string not numbers)
sort file -n
# Sort by months 
sort file  -M
# Save sorted results to another file
sort filename -n > filename_sorted
# Sort Specific Column 
sort file -k 2
# Sort the text by the numerals on the third column
sort filename -k 3n
# Sort and remove duplicates
sort filename.txt -u > filename_duplicates.txt
# Ignore case while sorting
sort filename -f
# Sort alphanumeric values like 1k (e.g. 1000)
sort filename -h

uniq

Remove all the duplicates in a file.

uniq file

grep

Search for patterns in files.

# Search for pattern in a file
grep "pattern" file
# Search for a patter with regular expression.
# Search for 4 letter words that ends with "ord" like "word", "work" etc. 
grep ".ord" file
# Find every line which starts with a capital letter
grep "^[A-Z]" file
# Find each line that contains an opening and closing parenthesis, with only letters and single spaces in between
grep "([A-Za-z ]*)" file
# Eescape meta characters using backslash character '\' in front of the characters. Find lines that end with "."
grep "^[A-Z].*\.$" file
# Extended Regex with -E option. Group multiple expressions and enclose them in a paratheses
grep -E "(Color|Colour)" file
# Find any words between chracter range. Use { } brackets to enclose the range. Example for words with 5 - 10 characters
grep -E "[[:alpha:]]{5,10}"
# Ignore any lines that are commented or blank
grep -vE '^(#|$)'

expand

Convert all the tabs to spaces.

# Convert all the tabs in a text file to spaces
expand file

unexpand

Convert all the spaces to tabs.

# Convert all the spaces in a text file to tabs
unexpand -a file

tr

Translate/Convert or delete characters

# Convert all lowercase characters to uppercase
tr a-z A-Z file

sed

Stream editor for text manipulation.

# Replace first occurance of a string with diffrent string e.g. start to START
sed 's/start/START/' file
# Replace all occurances (g - globbaly) of a string with diffrent string e.g. start to START
sed 's/start/START/g' file
# Replace a string with anohter string in place. Note: Use with caution! Before use take backup of the file
# Change first character of each word in a sentance e.g. Add () between a first leter of the word
echo "This Is The Best Name" | sed 's/\(\b[A-Z]\)/\(\1\)/g'
Output:
(T)his (I)s (T)he (B)est (N)ame

# Delete specific line e.g. 5th
sed '5d' file
# Delete a last line
sed '$d' filename
# Delete lines in a range
sed '3,6d' filename
# Delete pattern matching line
sed '/pattern/d' filename
# Insert text before line 3
sed '3i\new text' filename  
# Insert text after line 3  
sed '3a\new text' filename

awk

Text processing language.

# Search lines with a keyword.
awk '/some_text/ {print}' file
# Print specific columns e.g. 1 and 4
awk '{print $1,$4}'
# Print all collumns and rows where matched string is present
awk '{ if($3 == "access") print $0;}' file

cut

Extract sections from lines of files.

# Print bytes 1-3 and 5-7
cut -b 1-3,5-7 file
# Print field from 1-4 of each line with delimiter " "
cut -d " " -f 1-4 file
# Change input delimiter " " to output delimiter " --- " and print field 1 and 2
cut -d " " -f 1,2 file --output-delimiter=' --- '
# Take 1st and 3rd column from csv file and redirect to file
# cut -d',' -f1,3 file.csv > outputfile

wc

Count lines, words, and characters in files.

# Print the word counts
wc file1
# Print the line counts
wc -l file1
# Print the byte counts
wc -b file1

diff

Compare files line by line.

Example Output Interpretation:

  • @@ -1,3 +1,3 @@: This provides the context of the differences in the files. -1,3 indicates lines 1 to 3 in file1.txt, and +1,3 indicates lines 1 to 3 in file2.txt.
  • 1,4c1,4: Indicates that lines 1 to 3 in file1 need to be changed (c) to make it identical to file2 lines 1 to 3.
  • <: in the starting lines show the original content in file1.
  • —: separator between the content of file1 and file2.
  • >: in the starting lines show the corresponding content in file2.
# Create
diff file1 file2

# Creating and applaying patches with diff
cat file_original.txt
# -output-
# Hello World!
# As you can see that is a test file with some text.
# Nothing special, just to have some text to work with.
# Some text some text some text.
# Done! End of the file. Bye!

cat file_modified.txt
# Output:
# Hello!
# Thi is a test file with some text.
# I know this is a fancy text! :)
# Loooooooong teeeeeeeeeext..
# Some text some text some text.
# Done! End of the file. Bye!

diff -u file_original.txt file_modified.txt > file.patch
patch file_original.txt < file.patch
$ cat file_original.txt
Output:

Hello!
Thi is a test file with some text.
I know this is a fancy text! :)
Loooooooong teeeeeeeeeext..
Some text some text some text.
Done! End of the file. Bye!

Networking

ssh

Securely connect to a remote system.

# Connect via ssh to remote-server.com as user called username.
ssh username@remote-server.com

ssh-keygen

Generate SSH key pairs. It allso allows you to change ssh priv key password.

# Generate an SSH key pari with default aligorithm 
ssh-keygen
# Generate an SSH key pair with 4096-bit RSA key and appends a comment to the key
ssh-keygen -t rsa -b 4096 -C "youremail@example.com"
# Generat public–private key pair using the ECDSA algorithm 
ssh-keygen -t ecdsa -b 521 
# Change the passphrase of an existing private key
ssh-keygen -p -f ~/.ssh/id_rsa
# Show the fingerprint of a public key file
ssh-keygen -l -f ~/.ssh/id_rsa.pub
# Generate a KRL (Key Revocation List) file, which is used to revoke keys or certificates
ssh-keygen -k -f krl_file -z 1

scp

Securely copy files between systems.

# Securely copy files over SSH from a remote server to local destination path
scp user@remote:/path/to/file /path/to/local/destination
# Securely copy files over SSH from a local server to remote destination server
scp source_file user@remote:/path/to/remote/destination

rsync

Synchronize files and directories between locations.

## Synchronize directory with files to remote destination server
rsync -avz /local/directory/ user@remote:/path/to/destination

ping

Send ICMP echo requests to a target host.

# ICMP ping to example.com host
ping example.com

nslookup

Query DNS to obtain domain name or IP address mapping.

# Query DNS for a domain
dig example.com

dig

Query DNS to obtain domain name or IP address mapping.

# Query DNS for a domain
dig example.com

traceroute

Trace the path packets take to a network host.

# Trace path to example.com 
traceroute example.com

ip

Display or configure network interfaces (modern replacement for ifconfig).

# Display netwrok interfaces along with their IP addresses.
ip a
# -or-
ip add
# -or-
ip address
# Show interfaces along with their MAC addresses
ip link
# -or-
ip link show
# Show interface eth0 along with its MAC address
ip link show eth0
# Show interface statistics 
ip -s link show eth0
# Bring the interface up
# Bring the interface down 
ip link set eth0 up
ip link set eth0 down
# Add ip address to eth0 interface
ip address add 192.168.0.100/24 dev eth0
# Show routing table
ip route list
# Add a route for the ip address 
ip route add 192.168.0.100/24 via 10.10.20.5
# Remove a route
route delete 192.168.0.100/24
# Show routing table
sudo route -n
# Add a route for the ip address 
sudo route add -net 192.168.0.100/24 gw 10.10.20.5
# Remove a route
sudo route del -net 192.168.0.100/24

ifconfig

Display network interfaces and configurations.

# Display network interfaces along with their IP addresses
ifconfig
# Display information about given interface e.g. eth0 
ifconfig eth0
# Configure the interface eth0 and bring it up
ifconfig eth0 192.168.0.100 netmask 255.255.255.0 up
# Bring the interface up/Enable the interface eth0
ifup eth0
# Bring the interface down/Disable the interface eth0
ifdown eth0

netstat

Display network statistics and connections.

# Display all listening, tcp, upd ports with disabled service name resolution for ports.
netstat -tulpn

ss

Utility to investigate sockets (replacement for netstat).

# Display all listening, tcp, upd ports, disabled service name resolution for ports.
ss -tulpn

nmcli

Control and modify NetworkManager.

# Check general status of the networkmanager
sudo nmcli general status 
# View all connections
sudo nmcli connection show 
# Detailed information about a connection
sudo nmcli -p connection show connection-name
# Adding an interface
sudo nmcli connection add ifname <interface-name> type <connection-type> con-name <connection-name> ipv4.addresses <ip with subnet mask> ipv4.gateway <gateway> ipv4.dns <dns> ipv4.method <method>
#  Adding an interface
sudo nmcli connection add ifname enmp0s3 type ethernet con-name enp0s3 ipv4.addresses 192.168.0.105/24 ipv4.gateway 192.168.0.1 ipv4.dns 8.8.8.8 ipv4.method manual
# Modify an interface
nmcli connection modify enp0s3 ipv4.addresses 192.168.0.110/24
# Turn off wifi
nmcli radio wifi off
# Turn on wifi
nmcli radio wifi on
# Enable a connection
sudo nmcli connection up connection-name
# Disable a connection
sudo nmcli connection down connection-name
# Display the list of all nearby wifi connections 
sudo nmcli device wifi list
# Display saved password of an active wifi connection 
sudo nmcli device wifi show-password

wget

Download files from the web.

# Download a file from the website
wget http://example.com/file.zip

curl

Transfer data from or to a server via various protocols.

# Download file.zip and save it with the same name into a current directory 
curl -O http://example.com/file.zip
# Download file.zip and save it with the same name into /tmp directory 
curl -O http://example.com/file.zip --output-dir /tmp

System Utilities

uname

Print system information with kernel version.

# Print OS name 
uname
# Print kernel version 
uname -r
# Print all information
uname -a

man

Display the manual for a command.

# Display man page for 'ls' command.
man ls

history

Display command history.

# Display history
history
# Display last 5 commands from the history
history 5
# Execute command numbered 2001
!2001 
# Print but not execute command numbered 2001
!2001:p
# Search history for a specified phrase e.g. /etc
history | grep '/etc'
# Execute the most recent command
!!
# Execute a Command without Storing History
echo $HISTFILE
/home/user/.bash_history
unset HISTFILE
echo $HISTFILE
# Revert change to store history
set HISTFILE
# Remove a specific command from the history e.g. with the number 2005.
history -d 2005
# Clear up the whole command history. Note: Irreversable.
history -c
# Display last 10 commands
history | tail

tar

Archive files and directories

# Exctract .tar.gz archive 
tar -xvzf archive.tar.gz
# Archive and compress archive directory
$ tar -cvzf archive archive.tar.gz  

gzip

Compress files using gzip compression.

# Compress single file
gzip file.txt
# Compress multiple files at once
gzip file1.txt file2.txt file3.txt
# Compress a single file and keep the original
gzip -c file.txt > file.txt.gz
# Concatenate/Append multiple files into single file.
gzip -c file1.txt > files.gz
gzip -c file2.txt >> files.gz
# List compressed files
gzip -l archive.tar.gz

gunzip

Decompress files compressed with gzip.

# Decompress file without keeping the original file.
gunzip file.txt.gz
# Decompress and keeps both the files - the uncompressed and the original file - after the decompression
gunzip -k file.txt.gz 

find

Search for files and directories.

# Exclude or ignore certain file types e.g. .sh files
find . -not -name '*.sh'
# Search for .sh files but exclude archive.tar.gz file
find . -name '*.sh' ! -name 'archive.tar.gz'
# Search for files starting from the current dir but exclude 'images' directory
find . -name 'images' -prune -o -print
# The same as above but with permission listing.
find . -name 'images' -prune -o -ls
# Find any file whose name ends with either 'c' or 'asm'
find . -type f \( -iname "*.c" -or -iname "*.asm" \)
# Same command but POSIX compliant (-or vs. -o syntax)
find . -type f \( -iname "*.c" -o -iname "*.asm" \)
# Find all *.conf and (.txt) text files in the /etc/ directory
find . -type f \( -name "*.conf" -or -name "*.txt" \) -print
# POSIX compliant version:
find . -type f \( -name "*.conf" -o -name "*.txt" \) -print
# Search for all files but exclude ‘images’, ‘css’, and ‘js’ directories in the /var/www/html/ directory
find /var/www/html \( -name 'images' -o -name 'css' -o -name 'js' \) -prune -o -print
find /var/www/html \( -name 'images' -o -name 'css' -o -name 'js' \) -prune -o -ls
# Same command but not POSIX compliant
find /var/www/html \( -name 'images' -or -name 'css' -or -name 'js' \) -prune -o -print
find /var/www/html \( -name 'images' -or -name 'css' -or -name 'js' \) -prune -o -ls

locate

Quickly find files by name using a prebuilt database. In order to get up-to-date db sudo updatedb command might be required.

# Find filename
locate filename
# Find filename with case-insensitive search
locate -i filename

whereis

Locate the binary, source, and manual page files for a command.

whereis bash
Output:
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz

ln

Create links between files.

# Create new symbolic (`-s`) link called 'softlink1' to an existing file called 'file1'
ln -s /tmp/file1 softlink1
# Create new hard link called 'hardlink1' to an existing file called 'file2'
ln /tmp/file2 hardlink1
# Update existing soft link (force option without asking to overwrite existing file)
ln -sf <new_file> <existing_softlink>
# Update existing soft link (interactive option with asking to overwrite the existing file)
ln -si <new_file> <existing_softlink>

alias

Create custom command aliases.

# Create ll alias for 'ls -la' command
alias ll='ls -la'

unalias

Remove alias.

# Remove 'll' alias
unalias ll

echo

Display a line of text or variables.

echo "Hello World!"

date

date is used to display or set the system date and time.

# Display current date
date
# Display date and time 10 hours ago.
date --date="10 hour ago"
# Display tomorrow's date
date --date="tomorrow"
# Display date, but with 7 days back
date -d "7 days ago"
# Display current date with the format: 'Year: 2022, Month: 01, Day: 01'
date +"Year: %Y, Month: %m, Day: %d"
# Convert privided date into the format: "Saturday, January 01, 2022"
date -d "2022-01-01" +"%A, %B %d, %Y"
# Change time zone temporarily to America. Command: TZ='[country]/[city]' date 
TZ='America/New_York' date
# timedatectl list-timezones

clear

Clear the terminal screen.

# Clear the terminal screen to give you the clean window. 
clear

reboot

reboot reeboots the system.

# Reboot the system
reboot

shutdown

Shutdown the system.

# Reboot system in 1 minute (default)
sudo shutdown -r
# Reboot system immediately
sudo shutdown -r now
# Shutdown system immediately
sudo shutdown now
# Shedule a system reboot at 20:00
sudo shutdown -r 20:00
# Shut down the system in 10 minutes from now and notify the users with a message.
sudo shutdown -r +10 "System upgrade, machine will reboot."
# Cancel shedulled reboot
shutdown -c
# Cancel shedulled reboot and provide cancel message.
sudo shutdown -c "Canceling the reboot"

sleep

Make a delay for a specified amount of time.

sleep 5

time

Measures the duration of command execution.

# Measusre of execution `ls` command
time ls

watch

Execute a program periodically, showing output fullscreen.

watch -n 5 df -h

Feel free to play around with these commands to get practical grasp. This allows you master your skills and get more efficient when you work with Linux einvironments. There is a lot to explore, and if you want to discover another group of commands that is pentesting specific, you can check my another post - Pentesting Commands (comming soon).