Essential Linux Commands: Classification, Usage, and Tips
This article provides a comprehensive guide to common Linux commands, covering internal vs external classification, help lookup methods, command syntax, practical examples for file management, system monitoring, compression, shutdown, pipelines, quoting, and best learning habits.
Command Classification
Internal commands – part of the shell interpreter.
External commands – independent executable files.
Distinguish internal vs external with type : <code>type cd cd is a shell builtin type cat cat is /bin/cat</code> Help for internal commands: <code>man cd help cd info cd</code> Help for external commands: <code>man cat info cat cat --help</code>
Command Syntax
Format: command [options] [arguments] <code>ls -al /</code>
Common Commands
ls – List files or directories
Options: -l – detailed list. -a – include hidden entries.
Examples:
mkdir aaa
cd aaa/
touch 1.txt ls
1.txt ls -a
. .. 1.txt ls -l
total 0
-rw-rw-r--. 1 user user 0 Feb 7 15:03 1.txtcd – Change directory
Examples:
Go to the user home directory:
cd
# or
cd ~Enter directory aaa: cd aaa/ Return to previous directory: cd - Go up one level: cd .. Switch to another user's home:
cd ~test/pwd – Print working directory
cd tmp
pwdmkdir – Make directory
Option -p – create parent directories as needed.
Examples:
Create a single directory: mkdir bbb Create nested directories:
mkdir -p ccc/dddrmdir – Remove empty directory
rmdir bbbFails if the directory is not empty.
touch – Create an empty file
touch 1.txtrm – Remove files or directories
Options: -f, --force – force deletion. -r, -R – recursive delete.
Examples:
Delete a file: rm 1.txt Delete a directory recursively:
rm -r ccc/cat – Concatenate and display file contents
echo aaaa > 1.txt
cat 1.txthead – Show the first N lines (default 10)
Option -n, --lines=[-]K – show first K lines; a leading - excludes the last K lines.
Examples:
Show first 10 lines of a log: head /var/log/messages Show first 5 lines: head -n 5 /var/log/messages Exclude the last 5 lines:
head -n -5 /var/log/messagestail – Show the last N lines (default 10)
Option -n, --lines=[+]K – show last K lines; a leading + starts from line K to the end. -f – follow file growth. -F – like -f but continues after log rotation.
Examples:
Show last 10 lines: tail /var/log/messages Show last 5 lines: tail -n 5 /var/log/messages Follow a file:
tail -f /var/log/messagesmore – Page through output
Option -num – number of lines per screen.
Commands: SPACE – next screen. q – quit. / – search. = – show line number. ! or :! – run a command in a subshell.
less – Page through output with backward scrolling
Commands: b – scroll back one screen. f – scroll forward one screen. / – search.
echo – Display a line of text
echo hello worldcp – Copy files
Copy a single file: cp 1.txt /cc Copy multiple files using brace expansion:
cp ./{1.txt,2.txt} /ccmv – Move or rename files
Move a file: mv 1.txt /cc Move multiple files: mv ./{1.txt,2.txt} cc/ Rename a file:
mv 1.txt a.txtfind – Search for files
Find a specific file: find 1.txt Wildcard search:
find *.txtwc – Count lines, words, characters
Options: -m – characters. -w – words. -l – lines.
wc 1.txtgrep – Search text using patterns
Option -i – ignore case.
grep -i a 1.txtln – Create links
Option -s – create symbolic link.
Default creates a hard link; hard links remain valid if the source file is deleted, while symbolic links become dangling.
ln 1.txt x.txt 1.txtis the source; x.txt is the link.
System Management Commands
stat – Detailed file information (more than ls )
stat 1.txtwho – Show logged‑in users
whowhoami – Show current user
whoamihostname – Show or set the host name
Show: hostname Temporarily change:
hostname tempnameuname – Show system information
uname -atop – Interactive process viewer (press q to quit)
topps – Snapshot of processes
ps -auxdu – Estimate directory size
Option -h – human‑readable units.
du -h /homedf – Report file system disk space usage
Option -h – human‑readable.
df -hifconfig – Network interface configuration
Show current configuration: ifconfig Temporarily set IP address:
ifconfig eth0 192.168.1.125ping – Test network connectivity
ping 192.168.1.1netstat – Network statistics
Options: -a – all sockets. -l – listening services. -t – TCP connections. -p, --programs – show PID and program name.
netstat -altpnclear – Clear the terminal screen
clearalias – Define command shortcuts
alias showmeit="ps -aux"unalias – Remove an alias
unalias showmeitkill – Terminate processes
kill -9 52315231 is the process ID.
free – Show memory and swap usage
freePackaging and Compression Commands
gzip
bzip2
tar
Tar options: -c, --create – create archive. -x, --extract, --get – extract archive. -z – gzip compression. -j – bzip2 compression. -v – verbose (show progress).
Create archive: tar -cvf 1.txt.tar 1.txt Extract archive: tar -xvf 1.txt.tar Extract to a specific directory: tar -xvf 1.txt.tar -C bb/ Gzip archive: tar -zcvf 1.txt.tar.gz 1.txt Extract gzip archive: tar -zxvf 1.txt.tar.gz 1.txt Bzip2 archive: tar -jcvf 1.txt.tar.gz 1.txt Extract bzip2 archive:
tar -jxvf 1.txt.tar.gz 1.txtShutdown / Reboot Commands
shutdown– schedule shutdown or reboot. -r – reboot. -h – halt (no reboot). now – immediate action. halt – halt the system. reboot – reboot the system. poweroff – power off.
Linux Pipelines and Redirection
|– pipe output of one command to the next. > – redirect output to a file (overwrite). >> – append output to a file.
Command substitution with backticks: echo `date` Single quotes suppress special characters: echo '$PATH' Double quotes allow variable expansion but preserve most characters:
echo "$PATH"Good Linux Learning Habits
Read manual pages ( man) and other help documents.
Use the Tab key for auto‑completion.
Master useful shortcuts: Ctrl+C – interrupt current process. Ctrl+R – search command history. Ctrl+L – clear screen (same as clear).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ZhiKe AI
We dissect AI-era technologies, tools, and trends with a hardcore perspective. Focused on large models, agents, MCP, function calling, and hands‑on AI development. No fluff, no hype—only actionable insights, source code, and practical ideas. Get a daily dose of intelligence to simplify tech and make efficiency tangible.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
