Operations 23 min read

Master Essential Linux Commands: From pwd to umask Explained

This comprehensive guide walks you through the most frequently used Linux commands—including pwd, cd, tree, mkdir, touch, ls, cp, mv, rm, rmdir, ln, readlink, find, xargs, rename, basename, dirname, chattr, lsattr, file, md5sum, chown, chmod and umask—detailing their purpose, syntax, common options, and practical examples to help you navigate and manage the command line efficiently.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Essential Linux Commands: From pwd to umask Explained

pwd – Show Current Directory

The pwd command (print working directory) displays the absolute path of the current directory.

Syntax: pwd [option] Usually used without options.

cd – Change Directory

The cd command (change directory) switches the working directory to the specified path.

Syntax: cd [option] [dir] Without arguments, it jumps to the user's home directory defined by $HOME.

It is a built‑in Bash command; use help cd for help.

tree – Display Directory Tree

tree

lists the contents of a directory in a hierarchical tree format.

Syntax: tree [option] [directory] Common options are shown in the original tables (e.g., -L for depth, -a to include hidden files).

mkdir – Create Directories

mkdir

creates one or more new directories.

Syntax: mkdir [option] [directory] Use -p to create parent directories as needed.

Multiple directories can be created in a single command.

touch – Create Empty Files or Update Timestamps

touch

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

Syntax: touch [option] [file] Do not confuse with mkdir, which creates directories.

ls – List Directory Contents

ls

lists files and directories with optional details.

Syntax: ls [option] [file] Common options: -l (long format), -a (all files), -h (human‑readable sizes), -i (inode), -t (sort by modification time).

Typical output columns: inode, permissions, link count, owner, group, size, modification time, name.

cp – Copy Files or Directories

cp

copies source files or directories to a destination.

Syntax: cp [option] [source] [dest] Use -r or -R for recursive directory copy.

Preserve attributes with -p.

mv – Move or Rename Files

mv

moves or renames files and directories.

Syntax: mv [option] [source] [dest] Use -i for interactive prompting before overwriting.

rm – Remove Files or Directories

rm

deletes files or directories (dangerous operation).

Syntax: rm [option] [file] Use -r to remove directories recursively.

Prefer rm -i or move to a temporary location before deletion.

rmdir – Remove Empty Directories

rmdir

removes a directory only if it is empty.

Syntax:

rmdir [option] [directory]

ln – Create Links

ln

creates hard links or symbolic (soft) links.

Syntax: ln [option] [source] [target] Hard link: ln source target (both share the same inode).

Symbolic link: ln -s source target (creates a separate file with its own inode).

readlink – Show Symbolic Link Target

readlink

displays the path that a symbolic link points to.

Syntax:

readlink [option] [file]

find – Search Files

find

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

Syntax: find [-H] [-L] [-P] [pathname] [expression] Common options include -name, -type, -size, -exec, etc.

xargs – Build and Execute Command Lines from Standard Input

xargs

reads items from standard input and constructs command lines to run another command.

Syntax:

xargs [option]

rename – Batch Rename Files

rename

renames files by applying a string substitution.

Syntax: rename from to file Example: rename "finished" "" * removes the word "finished" from all filenames.

Example: rename .jpg .png *.jpg changes extensions.

basename – Strip Directory and Suffix

basename

prints the filename portion of a path, optionally removing a suffix.

Syntax:

basename [name] [suffix]

dirname – Strip Filename

dirname

prints the directory portion of a path.

Syntax:

dirname [name]

chattr – Change File Attributes

chattr

modifies extended attributes of a file (e.g., immutable, append‑only).

Syntax: chattr [option] [mode] [files] Example: chattr +i file makes the file immutable.

Example: chattr +a .bash_history sets append‑only mode.

lsattr – List File Attributes

lsattr

displays the extended attributes of files or directories.

Syntax:

lsattr [options] [files]

file – Determine File Type

file

reports the type of a file based on its content.

Syntax:

file [option] [file]

md5sum – Compute and Verify MD5 Checksums

md5sum

calculates the MD5 hash of files and can verify them against stored values.

Syntax: md5sum [option] [file] Useful for verifying integrity of downloaded or backed‑up files.

chown – Change Owner and Group

chown

changes the user and/or group ownership of files and directories.

Syntax: chown [option] [OWNER] [:[GROUP]] [file] Examples: chown user file, chown :group file, chown user:group file.

chmod – Change Permissions

chmod

modifies the read/write/execute permissions of files and directories.

Syntax: chmod [option] [mode] [file] Modes can be symbolic (e.g., u+x) or numeric (e.g., 755).

Common options: -R for recursive changes.

umask – Set Default Permission Mask

umask

defines the default permission bits that are masked out when new files or directories are created.

Syntax: umask [option] [mode] Default file creation permission is 666; directory creation is 777.

The resulting permission is calculated as default - umask, adjusting odd digits upward to the next even value.

Example: umask 022 yields files with 644 and directories with 755 permissions.

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 Administrationbasics
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.