Fundamentals 25 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: From ls to chmod Explained

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

pwd

prints the current working directory. pwd – show current path pwd -P – show the physical path, resolving symlinks

4. mkdir command

mkdir

creates 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

rm

removes 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

-f

6. rmdir command

rmdir

removes empty directories. rmdir -p parent/child/child11 – remove the specified directory and its empty ancestors

7. mv command

mv

moves 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

cp

copies 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.txt

9. cat command

cat

concatenates 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

more

paginates 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

less

provides 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

head

outputs 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

tail

outputs 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

which

locates 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

whereis

searches 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

locate

queries 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

/var

17. find command

find

searches 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

xargs

18. chmod command

chmod

changes 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

tar

creates 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

chown

changes 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem Administrationfile management
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.