Master Essential Linux Commands: From ls to xargs in 8 Minutes
This guide provides concise explanations and practical examples of core Linux commands—including ls, cd, pwd, mkdir, cp, mv, rm, du, df, cat, echo, more, less, clear, head, tail, wc, grep, man, logout, pipelines, xargs, basename, dirname, and set—helping readers quickly master command‑line navigation and file manipulation.
Essential Linux Commands Overview
1. ls – list directory contents, similar to Windows dir. Common options: -a (show hidden files), -l (detailed list), -F (append file‑type symbols).
2. cd – change the current directory. Examples: cd aaa (enter aaa), cd or cd ~ (go to home), cd - (return to previous directory), cd .. (up one level).
3. pwd – display the present working directory.
4. mkdir & rmdir – create and remove directories. Both support -p to create parent directories or remove a directory tree. Example: mkdir -p 1/2/3, rmdir -p 1/2/3.
5. cp – copy files or directories. Examples: cp 1.txt ../test2 (copy to another directory), cp 1.txt 2.txt (copy and rename), cp -r a b (copy directory a to b).
6. mv – move or rename files. Examples: mv 1.txt ../test1, mv 1.txt 2.txt, mv 1.txt ../test1/2.txt.
7. rm – delete files. Common options: -i (prompt before each removal), -r (recursive, also removes directories), -f (force, no prompt).
8. du & df – du shows disk usage of files/directories; df shows free space on filesystems. Useful forms: du -hs ./* (human‑readable sizes of all items), df -h (human‑readable free space).
9. cat – concatenate and display file contents. Examples: cat file1, cat file1 file2, cat file1 file2 > file3 (redirect output), cat >file1 (type input until Ctrl+D).
10. echo – output strings to the terminal. Syntax: echo [-ne] [string]. Options: -n (no trailing newline), -e (enable backslash escapes). Common escapes: \a (alert), \b (backspace), \n (newline), \t (tab), etc.
11. more, less, clear – paging utilities. more pauses after each screen; less allows forward/backward navigation with keys (e.g., Space, b, g, G, /pattern, q). clear clears the terminal (equivalent to Windows cls).
12. head & tail – view the beginning or end of a file. Default 10 lines; specify number with -n (e.g., head -100 file, tail -100 file). tail -f follows a file in real time.
13. wc – word count. Options: -l (lines), -w (words), -c (bytes). Example: wc -l 1.txt.
14. grep – search files for patterns using regular expressions. Returns matching lines and exit status (0 = match, 1 = no match, 2 = error). Example: ls -l | grep '^a' shows entries starting with “a”.
15. man & logout – man displays manual pages for commands (e.g., man ls); logout exits the current shell session.
16. Pipelines & xargs – the pipe | passes output of one command as input to the next (e.g., ls | grep a). xargs builds command lines from standard input, useful for handling large argument lists (e.g., find / -name "core" -print | xargs echo > /tmp/core.log, ls | xargs rm).
17. basename & dirname – basename extracts the filename without its path; dirname extracts the directory path. Examples: basename /home/hj/1.txt → 1.txt, dirname /home/hj/1.txt → /home/hj.
18. set (no arguments) – displays all shell variables and functions.
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.
