Master Essential Linux Commands: From ls to chmod Explained
This guide provides concise explanations and practical examples for dozens of fundamental Linux commands—including ls, cd, pwd, mkdir, rm, rmdir, mv, cp, cat, more, less, head, tail, which, whereis, locate, find, chmod, tar, and chown—helping users navigate the shell efficiently and manage files, permissions, and system resources.
Linux offers a rich set of command‑line tools that are essential for file management, system navigation, and administration. Below is a concise reference for the most commonly used commands.
1. ls command
The ls command lists directory contents and can display file permissions, owners, and timestamps. ls -a – list all files, including hidden ones starting with
. ls -A– list all except . and
.. ls -r– reverse order ls -t – sort by modification time ls -S – sort by size ls -h – human‑readable sizes ls -l – detailed list with permissions, owners, etc.
Examples: ls -lhrt – human‑readable, reverse time order with details ls -lrS – size‑sorted reverse order with details ls -l t* – detailed list of entries starting with “t” ls | sed "s:^:`pwd`/:" – prepend absolute path (excluding hidden files) find $pwd -maxdepth 1 | xargs ls -ld – list absolute paths including hidden files
2. cd command
cd(change directory) switches the current working directory. cd / – go to root cd ~ – go to home directory cd - – return to previous directory cd !$ – use the last argument of the previous command as the target
3. pwd command
pwdprints the current working directory. pwd – show current path pwd -P – show the physical path, resolving symlinks
4. mkdir command
mkdircreates new directories. -m – set access mode (permissions) at creation -p – create parent directories as needed
Examples: mkdir t – create directory t in the current location mkdir -p /tmp/test/t1/t – create nested path, creating missing parents
5. rm command
rmremoves files or directories. Use -r to delete directories recursively. rm -i *.log – interactively delete all .log files rm -rf test – forcefully delete directory test and its contents rm -- -f* – delete files whose names start with
-f6. rmdir command
rmdirremoves empty directories. rmdir -p parent/child/child11 – remove the specified directory and its empty ancestors
7. mv command
mvmoves or renames files. mv test.log test1.txt – rename file mv llog1.txt log2.txt log3.txt /test3 – move multiple files to
/test3 mv -i log1.txt log2.txt– interactive overwrite prompt mv * ../ – move all files in the current directory up one level
8. cp command
cpcopies files or directories. cp -ai a.txt test – copy a.txt to test preserving timestamps and prompting before overwrite cp -s a.txt link_a.txt – create a symbolic link named
link_a.txt9. cat command
catconcatenates and displays file contents. cat filename – display entire file cat > filename – create a new file from keyboard input cat file1 file2 > file – merge files into a new file cat -n log2012.log log2013.log – add line numbers to output cat -b log2012.log log2013.log log.log – number non‑blank lines
cat >log.txt <<EOF
Hello
World
PWD=$(pwd)
EOF– here‑document example tac log.txt – display file in reverse order
10. more command
morepaginates output, allowing forward navigation. more +3 text.txt – start display at line 3 ls -l | more -5 – show 5 lines per page
Key bindings: Space – next page, b – previous page, q – quit
11. less command
lessprovides bidirectional pagination and searching. less -i – ignore case in searches less -N – show line numbers /pattern – search forward, ?pattern – search backward n / N – repeat last search forward/backward ps -aux | less -N – view process list with line numbers less 1.log 2.log – view multiple files
12. head command
headoutputs the beginning of a file (default first 10 lines). head 1.log -n 20 – first 20 lines head -c 20 log2014.log – first 20 bytes head -n -10 t.log – last 10 lines
13. tail command
tailoutputs the end of a file and can follow updates. tail -f ping.log – continuously display new lines as the file grows tail -n 20 file.log – last 20 lines
14. which command
whichlocates the executable file associated with a command in the PATH. which ls – show path of
ls which cd– reports not found because cd is a shell builtin echo $PATH – display current PATH variable
15. whereis command
whereissearches for binaries, sources, and manuals. whereis locate – locate binary, source, and man page whereis -s locate – source only whereis -m locate – manual only
16. locate command
locatequeries a prebuilt database for fast filename searches. locate pwd – find files containing “pwd” in their names locate /etc/sh – find files in /etc starting with “sh” locate -r '^/var.*reason$' – regex search for paths ending with “reason” under
/var17. find command
findsearches directory trees for files matching criteria. find -atime -2 – files accessed within the last 48 hours find ./ -name '*.log' – .log files in current directory find /opt -perm 777 – files with permission 777 find -size +1000c – files larger than 1000 bytes find . -type f -mtime +10 -exec rm -f {} \; – delete files older than 10 days without prompt find . -name '*.log' -exec cp {} test3 \; – copy all .log files to
test3 find . -type f -print | xargs file– determine file types via
xargs18. chmod command
chmodchanges file or directory permissions. chmod a+x t.log – add execute permission for all users chmod u=r t.log -c – set owner read‑only and report changes chmod 751 t.log – owner rwx, group r‑x, others x chmod u+r,g+r,o+r -R text/ -c – add read permission recursively
19. tar command
tarcreates and extracts archive files; compression is delegated to other utilities. tar -cvf log.tar 1.log 2.log – create archive tar -zcvf /tmp/etc.tar.gz /etc – create gzip‑compressed archive of
/etc tar -ztvf /tmp/etc.tar.gz– list contents of gzip archive tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc – archive while excluding a path
20. chown command
chownchanges file ownership. chown -c mail:mail log2012.log – change owner and group, show changes chown -c :mail t.log – change group only chown -cR mail: test/ – recursively change owner and group of a directory
These commands form the backbone of everyday Linux system usage, enabling efficient file handling, permission management, and system navigation.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
