Computers & Internet

100 Most Useful Linux Commands: A Comprehensive Guide with Syntax and Examples

100 Most Useful Linux Commands: A Comprehensive Guide with Syntax and Examples
Spread the love

The Linux operating system is a versatile and powerful platform that provides users with a wide range of commands to perform various tasks. Whether you are a seasoned Linux user or a beginner, having a solid understanding of the most useful commands can greatly enhance your productivity and efficiency.

ls: Lists the contents of a directory.

Syntax: ls [options] [path/to/directory]

Example: ls /usr/bin

cd: Changes the current working directory.

Syntax: cd [path/to/directory]

Example: cd ~/Documents

pwd: Prints the current working directory.

Syntax/Example: pwd

mkdir: Creates a new directory.

Syntax: mkdir [options] [dirname(s)]

Example: mkdir mydir

rm: Deletes files or directories.

Syntax: rm [options] [file(s) or dir(s)]

Example: rm file.txt

cp: Copies files or directories.

Syntax: cp [options] [source] [destination]

Example: cp file.txt backup/

mv: Renames or moves files or directories.

Syntax: mv [options] [source] [destination]

Example: mv file.txt file_backup.txt

chmod: Changes file or directory permissions.

Syntax: chmod [options] [mode] [file(s) or dir(s)]

Example: chmod +x file.sh

chown: Changes the owner or group of a file or directory.

Syntax: chown [options] [owner][:group] [file(s) or dir(s)]

Example: chown root:root file.sh

echo: Displays text on the terminal.

Syntax: echo [options] [string(s)]

Example: echo Hello, World!

grep: Searches for text in files or output.

Syntax: grep [options] [pattern] [file(s)]

Example: grep “ERROR” logfile.txt

ps: Displays information about the current running processes.

Syntax: ps [options]

Example: ps aux

top: Displays the system’s resource usage and processes.

Syntax: top

Example: top

kill: Sends signals to processes to terminate them.

Syntax: kill [options] [pid(s)]

Example: kill 1234

ping: Tests the connectivity between two systems.

Syntax: ping [options] [destination]

Example: ping google.com

ssh: Establishes a secure shell connection to a remote system.

Syntax: ssh [options] [user@]hostname

Example: ssh [email protected]

scp: Copies files securely between systems.

Syntax: scp [options] [source] [destination]

Example: scp file.txt [email protected]:/path/to/destination

tar: Compresses or extracts files and directories.

Syntax: tar [options] [operation] [compressed_file] [file(s) or dir(s)]

Example: tar -czvf archive.tar.gz mydir/

find: Searches for files and directories matching specified criteria.

Syntax: find [path/to/search] [options] [expression]

Example: find / -name “*.txt”

cat: Concatenates and displays the contents of files.

Syntax: cat [options] [file(s)]

Example: cat file.txt

sort: Sorts the contents of files or input.

Syntax: sort [options] [file(s)]

Example: sort file.txt

uniq: Filters out or reports repeated lines in a file or input.

Syntax: uniq [options] [file]

Example: uniq file.txt

cut: Selects and displays specific columns from a file or input.

Syntax: cut [options] [delimiter] [file(s)]

Example: cut -f 1 -d ” ” file.txt

sed: Modifies the contents of files or input.

Syntax: sed [options] [expression] [file(s)]

Example: sed ‘s/old/new/g’ file.txt

awk: Processes and manipulates text data.

Syntax: awk [options] ‘program’ [file(s)]

Example: awk ‘{ print $1 }’ file.txt

ls: Lists the contents of a directory.

Syntax: ls [options] [dirname(s)]

Example: ls

df: Shows the amount of disk space available and used.

Syntax: df [options] [filesystem(s)]

Example: df

du: Shows the disk usage of files and directories.

Syntax: du [options] [dirname(s)]

Example: du -h /

free: Shows the amount of free and used system memory.

Syntax: free [options]

Example: free -h

uptime: Shows the system uptime and load average.

Syntax: uptime

Example: uptime

crontab: Schedules tasks to run automatically.

Syntax: crontab [options] [file]

Example: crontab -l

history: Shows the command line history.

Syntax: history [options] [number of commands]

Example: history

alias: Creates short commands or macros.

Syntax: alias [name=’command’]

Example: alias l=’ls -la’

sudo: Executes a command with superuser privileges.

Syntax: sudo [command]

Example: sudo apt-get update

reboot: Restarts the system.

Syntax: reboot [options]

Example: sudo reboot

top: Shows the system processes and resource usage.

Syntax: top

Example: top

ps: Shows information about the system processes.

Syntax: ps [options]

Example: ps -ef

kill: Terminates a process.

Syntax: kill [options] pid

Example: kill -9 1234

chmod: Changes the permissions of files and directories.

Syntax: chmod [options] mode [file(s)]

Example: chmod +x file.sh

chown: Changes the owner and/or group of files and directories.

Syntax: chown [options] owner:group [file(s)]

Example: chown root:root file.txt

chgrp: Changes the group of files and directories.

Syntax: chgrp [options] group [file(s)]

Example: chgrp staff file.txt

ln: Creates a link between files.

Syntax: ln [options] source [destination]

Example: ln -s source.txt destination.txt

cp: Copies files and directories.

Syntax: cp [options] source [destination]

Example: cp file.txt destination/

mv: Moves or renames files and directories.

Syntax: mv [options] source [destination]

Example: mv file.txt destination/

rm: Removes files and directories.

Syntax: rm [options] file(s)

Example: rm file.txt

find: Searches for files and directories.

Syntax: find [path(s)] [expression]

Example: find / -name file.txt

grep: Searches for patterns in files.

Syntax: grep [options] pattern [file(s)]

Example: grep “text” file.txt

sed: Stream editor for transforming text.

Syntax: sed [options] [expression] [file(s)]

Example: sed ‘s/text/replace/g’ file.txt

awk: Text processing and manipulation tool.

Syntax: awk [options] ‘program’ [file(s)]

Example: awk ‘{print $1}’ file.txt

tar: Archiving utility for files and directories.

Syntax: tar [options] archive [file(s)]

Example: tar -cvf archive.tar file/

gzip: Compresses or decompresses files.

Syntax: gzip [options] [file(s)]

Example: gzip file.txt

gunzip: Decompresses gzip files.

Syntax: gunzip [options] [file(s)]

Example: gunzip file.gz

bzip2: Compresses or decompresses files.

Syntax: bzip2 [options] [file(s)]

Example: bzip2 file.txt

bunzip2: Decompresses bzip2 files.

Syntax: bunzip2 [options] [file(s)]

Example: bunzip2 file.bz2

unzip: Decompresses zip files.

Syntax: unzip [options] [file(s)]

Example: unzip file.zip

df: Shows information about the file systems.

Syntax: df [options] [file(s)]

Example: df -h

du: Shows information about the disk usage of files and directories.

Syntax: du [options] [file(s)]

Example: du -sh *

free: Shows information about the system’s memory usage.

Syntax: free [options]

Example: free -m

ping: Tests the connectivity to a network host.

Syntax: ping [options] host

Example: ping google.com

traceroute: Traces the path of a network packet to a destination host.

Syntax: traceroute [options] host

Example: traceroute google.com

netstat: Shows network statistics.

Syntax: netstat [options]

Example: netstat -ant

nslookup: Queries the DNS to obtain domain name or IP address information.

Syntax: nslookup [options] [hostname]

Example: nslookup google.com

whois: Queries the whois database for information about a domain.

Syntax: whois [options] domain

Example: whois google.com

ssh: Secure shell client for connecting to remote systems.

Syntax: ssh [options] [user@]host

Example: ssh user@host

scp: Secure copy utility for copying files between systems.

Syntax: scp [options] [user@]host:source [destination]

Example: scp file.txt user@host:/destination/

rsync: Utility for synchronizing files between systems.

Syntax: rsync [options] source [destination]

Example: rsync -avz file.txt user@host:/destination/

ftp: File Transfer Protocol client for transferring files between systems.

Syntax: ftp [options] [host]

Example: ftp ftp.example.com

sftp: Secure File Transfer Protocol client for transferring files between systems.

Syntax: sftp [options] [user@]host

Example: sftp user@host

curl: Utility for transferring data with URLs.

Syntax: curl [options] [URL(s)]

Example: curl http://example.com

wget: Utility for downloading files from the web.

Syntax: wget [options] [URL(s)]

Example: wget http://example.com/file.txt

telnet: Telnet client for connecting to remote systems.

Syntax: telnet [options] host [port]

Example: telnet host

top: Shows information about the system’s running processes.

Syntax: top

Example: top

ps: Shows information about the system’s running processes.

Syntax: ps [options]

Example: ps -ef

kill: Sends a signal to a process to terminate it.

Syntax: kill [options] pid(s)

Example: kill 12345

killall: Sends a signal to all processes with a specified name to terminate them.

Syntax: killall [options] name

Example: killall firefox

htop: An interactive process viewer.

Syntax: htop

Example: htop

lsof: Shows information about open files.

Syntax: lsof [options] [file(s)]

Example: lsof -p 12345

locate: Shows the location of files in the system.

Syntax: locate [options] [pattern]

Example: locate file.txt

find: Finds files in the file system.

Syntax: find [path(s)] [expression]

Example: find / -name file.txt

grep: Searches for patterns in text.

Syntax: grep [options] pattern [file(s)]

Example: grep ‘pattern’ file.txt

sed: Stream editor for filtering and transforming text.

Syntax: sed [options] [script] [file(s)]

Example: sed ‘s/old/new/g’ file.txt

awk: Pattern scanning and processing language.

Syntax: awk [options] ‘program’ [file(s)]

Example: awk ‘{print $1}’ file.txt

cut: Cuts sections from each line of files.

Syntax: cut [options] [file(s)]

Example: cut -f1 -d, file.txt

sort: Sorts lines of text files.

Syntax: sort [options] [file(s)]

Example: sort file.txt

uniq: Removes or reports repeated lines from a file.

Syntax: uniq [options] [file(s)]

Example: uniq file.txt

head: Shows the beginning of a file.

Syntax: head [options] [file(s)]

Example: head file.txt

tail: Shows the end of a file.

Syntax: tail [options] [file(s)]

Example: tail file.txt

more: Shows the contents of a file one screen at a time.

Syntax: more [options] [file(s)]

Example: more file.txt

less: Shows the contents of a file one screen at a time.

Syntax: less [options] [file(s)]

Example: less file.txt

cat: Concatenates and displays files.

Syntax: cat [options] [file(s)]

Example: cat file.txt

tac: Concatenates and displays files in reverse.

Syntax: tac [options] [file(s)]

Example: tac file.txt

nl: Numbers the lines of a file.

Syntax: nl [options] [file(s)]

Example: nl file.txt

od: Dumps files in various formats.

Syntax: od [options] [file(s)]

Example: od -t x1 file.bin

hexdump: Displays files in hexadecimal format.

Syntax: hexdump [options] [file(s)]

Example: hexdump -C file.bin

strings: Shows printable strings in a file.

Syntax: strings [options] [file(s)]

Example: strings file.bin

diff: Compares files line by line.

Syntax: diff [options] file1 file2

Example: diff file1.txt file2.txt

patch: Applies a patch file to a source file.

Syntax: patch [options] [originalfile patchfile

Example: patch originalfile.txt patchfile.txt

md5sum: Calculates the MD5 checksum of a file.

Syntax: md5sum [options] [file(s)]

Example: md5sum file.txt

sha1sum: Calculates the SHA-1 checksum of a file.

Syntax: sha1sum [options] [file(s)]

Example: sha1sum file.txt

sha256sum: Calculates the SHA-256 checksum of a file.

Syntax: sha256sum [options] [file(s)]

Example: sha256sum file.txt

In conclusion, these 100 Linux commands represent just a fraction of the total number of commands available in the Linux environment. However, they provide a solid foundation for you to build upon as you continue to learn and explore the world of Linux.

Remember to practice these commands and experiment with different options to fully understand how they work. With time and experience, you will become more proficient and confident in your ability to navigate and manipulate the Linux operating system.