Operations 17 min read

Master Linux Command Line: Detailed Guide to ls, pwd, cd, and More

This comprehensive tutorial walks you through the most common Linux commands—including ls, pwd, cd, mkdir, rmdir, rm, touch, man, cp, cat, less, find, tar, sz, and rz—covering their syntax, key options, practical examples, and visual illustrations to help both beginners and seasoned users master the shell.

Raymond Ops
Raymond Ops
Raymond Ops
Master Linux Command Line: Detailed Guide to ls, pwd, cd, and More

1. ls command

Syntax

ls [options] [directory|file]

Function

Lists the contents of a directory or displays information about a file.

Common options

-a – include hidden files (those starting with a dot).

-d – show directories themselves, not their contents.

-i – display the inode number.

-k – show file sizes in kilobytes.

-l – use a long listing format with detailed attributes.

-n – display numeric UID and GID instead of names.

-F – append a character to indicate file type (e.g., * for executables, / for directories).

-r – reverse the sort order.

-t – sort by modification time.

-s – show file size before the name.

-R – list sub‑directories recursively.

-1 – output one entry per line.

Example

ls -la
图片
图片

2. pwd command

Syntax

pwd

Function

Prints the absolute pathname of the current working directory.

Example

pwd
图片
图片

3. cd command

Syntax

cd directory_name

Function

Changes the current working directory to the specified path.

Example

cd ..            # go to parent directory
cd /root/Desktop/w   # absolute path
cd Desktop           # relative path
cd ~                 # home directory
cd -                 # previous directory
图片
图片

4. mkdir command

Syntax

mkdir [options] dirname...

Function

Creates one or more new directories.

Common options

-p, --parents – create parent directories as needed.

Example

mkdir -p path/to/newdir
图片
图片

5. rmdir command

Syntax

rmdir [options] directory_name

Function

Removes empty directories; fails if the directory is not empty.

Common options

-p, --parents – remove parent directories as long as they become empty.

-v, --verbose – show detailed removal information.

Example

rmdir -p a/b/c
图片
图片

6. rm command

Syntax

rm [options] file_name

Function

Deletes files or directories (with appropriate options).

Common options

-f, --force – ignore nonexistent files and never prompt.

-i – prompt before each removal.

-I – prompt once before removing many files or recursively.

-r, -R – remove directories and their contents recursively.

-d – remove empty directories.

-v, --verbose – explain what is being done.

Example

rm -rfv a.txt
图片
图片

7. touch command

Syntax

touch [options] file_name

Function

Creates an empty file or updates the access and modification timestamps of existing files.

Common options

-a – change only the access time.

-c, --no-create – do not create a new file if it does not exist.

-d, --date – use a specified date/time instead of the current time.

-m – change only the modification time.

-r, --reference – use timestamps from another file.

-t – specify a timestamp in the format [[CC]YY]MMDDhhmm[.ss].

Example

touch newfile.txt
图片
图片

8. man command

Syntax

man [options] command

Function

Displays the manual page for a given command, providing detailed usage, options, and examples.

Common options

-f, --whatis – show a one‑line description.

-k, --apropos – search manual page names and descriptions.

-a, --all – display all matching manual pages.

-w, --where – show the location of the manual file.

-l, --local-file – show a local (non‑translated) manual page.

-P, --pager – specify the pager program.

Example

man ls
图片
图片

9. cp command

Syntax

cp [options] source_file target_file

Function

Copies files or directories.

Common options

-a, --archive – copy recursively and preserve attributes (equivalent to -dR --preserve=all).

-f, --force – overwrite without prompting.

-i, --interactive – prompt before overwriting.

-r, -R, --recursive – copy directories recursively.

-u, --update – copy only when the source is newer.

-v, --verbose – show progress.

-p, --preserve – preserve mode, ownership, timestamps.

--backup – make a backup of each existing destination file.

--parents – preserve the source file’s path hierarchy.

--sparse – control creation of sparse files.

Example

cp -v a.txt file2.txt
图片
图片

10. cat command

Syntax

cat [options] [file_name...]

Function

Concatenates and displays file contents, creates new files, or merges multiple files.

Common options

-A – show all characters, including non‑printable ones.

-b – number non‑empty output lines.

-e – display non‑printable characters and a $ at line ends.

-n – number all output lines.

-s – squeeze multiple blank lines into a single blank line.

-T – display TAB characters as ^I.

-v – show non‑printable characters except TAB and line ends.

Example

cat -n file2.txt
图片
图片

11. less command

Syntax

less [options] file_name

Function

Pages through a file, allowing forward and backward navigation, searching, and more advanced features than the basic more command.

Common options

-N – display line numbers.

-X – do not clear the screen on exit.

-F – automatically display the whole file if it fits on one screen.

-S – do not wrap long lines.

-i – ignore case in searches.

-g – highlight only the last search match.

Example

less -N file2.txt
图片
图片

12. find command

Syntax

find [options] [path...] [expression]

Function

Searches for files and directories in a directory hierarchy and can execute actions on matches.

Common options

-name – case‑sensitive name match.

-iname – case‑insensitive name match.

-type – filter by file type (f, d, l, etc.).

-size – filter by file size.

-mtime – filter by modification time.

-user – filter by file owner.

-group – filter by group.

-perm – filter by permissions.

-exec – run a command on each matched file.

-delete – delete matched files.

-print – display matched files (default).

Example

find /home -name "*.txt"
图片
图片

13. tar command

Syntax

tar [options] [file]

Function

Creates, extracts, and manipulates archive files.

Common options

-c – create a new archive.

-x – extract files from an archive.

-f – specify the archive file name.

-v – verbosely list processed files.

-t – list archive contents.

-z – filter the archive through gzip.

-j – filter the archive through bzip2.

-r – append files to an existing archive.

-u – only append newer files.

-C – change to a directory before performing operations.

Example

tar -cvf archive.tar a.c w.c
图片
图片
tar -xvf archive.tar
图片
图片

14. sz command

Syntax

sz [options] file_name

Function

Transfers files from a Linux server to a local machine using the ZMODEM protocol.

Common options

-a – ASCII (text) transfer.

-b – binary transfer.

-e – escape control characters.

-r – resume an interrupted transfer.

-v – verbose output.

-y – overwrite existing files on the receiver.

Example

sz -a file.txt
图片
图片

15. rz command

Syntax

rz [options]

Function

Receives files from a local machine to a Linux server using the ZMODEM protocol.

Common options

-y – overwrite existing files.

-e – escape control characters.

-v – verbose output.

-b – binary transfer.

-a – ASCII (text) transfer.

Example

rz -y
rz -b
rz -a
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.

LinuxShellUnixSystem Administration
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

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.