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.
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
treelists 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
mkdircreates 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
touchcreates 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
lslists 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
cpcopies 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
mvmoves or renames files and directories.
Syntax: mv [option] [source] [dest] Use -i for interactive prompting before overwriting.
rm – Remove Files or Directories
rmdeletes 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
rmdirremoves a directory only if it is empty.
Syntax:
rmdir [option] [directory]ln – Create Links
lncreates 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
readlinkdisplays the path that a symbolic link points to.
Syntax:
readlink [option] [file]find – Search Files
findsearches 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
xargsreads items from standard input and constructs command lines to run another command.
Syntax:
xargs [option]rename – Batch Rename Files
renamerenames 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
basenameprints the filename portion of a path, optionally removing a suffix.
Syntax:
basename [name] [suffix]dirname – Strip Filename
dirnameprints the directory portion of a path.
Syntax:
dirname [name]chattr – Change File Attributes
chattrmodifies 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
lsattrdisplays the extended attributes of files or directories.
Syntax:
lsattr [options] [files]file – Determine File Type
filereports the type of a file based on its content.
Syntax:
file [option] [file]md5sum – Compute and Verify MD5 Checksums
md5sumcalculates 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
chownchanges 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
chmodmodifies 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
umaskdefines 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.
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.
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.)
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.
