1. pwd – Print Working Directory
Definition:pwd stands for Print Working Directory. In a Linux/Unix filesystem, you are always “inside” a directory, similar to being in a folder on a desktop. The pwd command tells you exactly where you are at any given moment by printing the full absolute path from the root (/) down to your current location.
Why it matters: When you open a terminal, you land in a default directory (usually your home folder). As you navigate deeper into subdirectories, it can be easy to lose track of your position. pwd is your GPS it always tells you your precise location in the filesystem tree.
Syntax:
pwd [OPTION]
Options:
| Option | Description |
|---|---|
pwd -L | Logical path – follows symbolic links (default behavior) |
pwd -P | Physical path – resolves symlinks and shows the real underlying path |
Usage:
$ pwd
/home/user/documents/projects
| Absolute Path | Relative Path |
|---|---|
Starts from the root directory / | Starts from the current directory |
| Complete path to a file or folder | Partial path based on current location |
| Does not depend on current directory | Depends on current directory |
| Always the same location | Changes based on where you are |
Example: /home/user/docs/file.txt | Example: docs/file.txt |
Uses / at the beginning in Linux | Usually does not start with / |
2. cd – Change Directory
Definition:cd stands for Change Directory. It is one of the most fundamental Linux commands it allows you to move between directories in the filesystem. Unlike most commands, cd is a shell built-in, meaning it’s part of the shell itself (not a separate program), because it must change the shell’s own working directory.
Why it matters: Without cd, you’d be stuck in one place. Every time you want to work in a different folder access logs, edit configs, run scripts you use cd to get there first.
Syntax:
cd [DIRECTORY]
Types / Navigation Shortcuts:
| Command | Description |
|---|---|
cd /absolute/path | Navigate to an absolute path from root |
cd relative/path | Navigate to a path relative to current location |
cd .. | Move up one directory level (parent folder) |
cd ../.. | Move up two directory levels |
cd ~ | Go to your home directory |
cd - | Toggle back to the previous directory |
cd / | Go to the root of the filesystem |
Usage:
$ cd /var/log # absolute path
$ cd Documents # relative path
$ cd .. # go back one level
$ cd ~ # go home
$ cd - # go back to where you just were
For more insights and updates, follow us on Google News, Twitter, and LinkedIn.
3. ls – List Directory Contents
Definition:ls stands for List. It displays the contents of a directory all the files, subdirectories, and links inside it. By default, it shows the contents of the current working directory. ls is arguably the most-used Linux command because you constantly need to see what’s inside a folder before working with it.
Why it matters: Before you copy, delete, move, or edit files, you need to know what exists. ls gives you that visibility. It also shows you critical metadata like file permissions, ownership, size, and modification time when used with options.
Syntax:
ls [OPTIONS] [PATH]
Options:
| Option | Description |
|---|---|
ls -l | Long listing shows permissions, owner, size, and date |
ls -a | Show all files, including hidden files (files starting with .) |
ls -la | Combine long format with hidden files |
ls -lh | Long format with human-readable file sizes (KB, MB, GB) |
ls -R | Recursively list all subdirectories |
ls -t | Sort by last modification time (newest first) |
ls -S | Sort by file size (largest first) |
ls -r | Reverse sort order |
ls --color | Highlight files by type with color |
Usage:
$ ls
$ ls -la
$ ls -lh /var/log
$ ls -lt ~/Downloads
4. touch
Definition:touch has two primary purposes: create a new empty file if the file doesn’t exist, or update the access and modification timestamps of an existing file without altering its content. The name “touch” comes from the idea of “touching” a file you’re telling the system the file was accessed right now.
Why it matters: In scripting and development, touch is commonly used to create placeholder files, trigger file-watcher events, or reset timestamps. It’s also used to quickly create multiple blank files at once.
Syntax:
touch [OPTIONS] filename(s)
Options:
| Option | Description |
|---|---|
touch file | Create a new empty file or update timestamp |
touch -a | Update only the access time |
touch -m | Update only the modification time |
touch -c | Do not create file if it doesn’t exist |
touch -t [[CC]YY]MMDDhhmm[.ss] | Set a specific timestamp manually |
touch -r ref_file file | Use the timestamp of another file |
Usage:
$ touch newfile.txt
$ touch file1.txt file2.txt file3.txt # create multiple files
$ touch -t 202601011200 report.txt # set custom timestamp
$ touch -a access.log # update access time only
5. file
Definition:
The file command determines and displays the type of a file based on its actual content not its extension. Linux doesn’t rely on file extensions to identify file types like Windows does. file reads the internal structure of the file (called “magic bytes” or “magic numbers”) to determine what it really is.
Why it matters: A file named document.pdf could actually be a plain text file, or a binary named image.jpg might be a disguised script. file reveals the truth. This is especially important in security analysis identifying suspicious or disguised files.
Syntax:
file [OPTIONS] filename
Options:
| Option | Description |
|---|---|
file filename | Show type of the file |
file -i | Display MIME type instead of text description |
file -b | Brief mode don’t print the filename |
file -z | Look inside compressed files |
file -s | Read block/character special files |
file * | Check all files in current directory |
Usage:
$ file image.png
image.png: PNG image data, 800 x 600, 8-bit/color RGBA
$ file /bin/bash
/bin/bash: ELF 64-bit LSB pie executable, x86-64
$ file -i script.sh
script.sh: text/x-shellscript; charset=us-ascii
$ file archive.tar.gz
archive.tar.gz: gzip compressed data
6. cat – Concatenate
Definition:cat stands for Concatenate. Its primary design is to concatenate (join) multiple files and print their combined output to the screen. In practice, it’s most commonly used to quickly display the full contents of a file. It reads files sequentially and writes them to standard output, making it a simple but powerful tool for both viewing and combining files.
Why it matters: It’s the fastest way to read a small file without opening an editor. It’s also used in pipelines to feed file content into other commands.
Syntax:
cat [OPTIONS] [FILE(s)]
Options:
| Option | Description |
|---|---|
cat file | Display file contents |
cat -n | Show line numbers for all lines |
cat -b | Show line numbers only for non-blank lines |
cat -A | Show all non-printing characters (tabs, line endings) |
cat -s | Squeeze multiple blank lines into one |
cat file1 file2 | Concatenate and display both files |
cat > file | Create a new file and type content into it |
cat >> file | Append content to an existing file |
Usage:
$ cat /etc/hostname
$ cat -n script.sh
$ cat file1.txt file2.txt > combined.txt
$ cat >> notes.txt # then type content, Ctrl+D to save
For more insights and updates, follow us on Google News, Twitter, and LinkedIn.
7. less
Definition:less is a terminal pager program it allows you to view the contents of large files one screen (page) at a time, with the ability to scroll both forward and backward. Unlike cat which dumps everything at once, less gives you full control over navigation. The name is a play on the older more command “less is more.”
Why it matters: When reading huge log files, configuration files, or command output that spans hundreds of lines, cat would flood your screen. less keeps it manageable and searchable without loading the entire file into memory.
Syntax:
less [OPTIONS] filename
Navigation Keys (while inside less):
| Key | Action |
|---|---|
Space or f | Scroll forward one page |
b | Scroll backward one page |
↑ / ↓ arrows | Scroll line by line |
/pattern | Search forward for a pattern |
?pattern | Search backward for a pattern |
n | Jump to next search match |
N | Jump to previous search match |
g | Go to beginning of file |
G | Go to end of file |
q | Quit and return to terminal |
Options:
| Option | Description |
|---|---|
less -N | Show line numbers |
less -S | Don’t wrap long lines |
less +F | Follow mode (like tail -f) |
Usage:
$ less /var/log/syslog
$ cat access.log | less
$ less -N /etc/nginx/nginx.conf
8. history
Definition:history displays a numbered list of all previously executed commands in the current shell session. Your shell (bash/zsh) automatically saves every command you type into a history file (typically ~/.bash_history). The history command lets you view, reuse, search, and manage this command log.
Why it matters: You often need to re-run complex commands you wrote earlier. Instead of retyping them, history lets you recall them by number or pattern. It’s also useful for auditing what was run on a system.
Syntax:
history [OPTIONS] [n]
Options & Special Expansions:
| Command | Description |
|---|---|
history | Show full command history with numbers |
history N | Show last N commands |
history -c | Clear all history from current session |
history -d N | Delete history entry number N |
history -w | Write current history to the history file |
!N | Re-execute command number N |
!! | Re-execute the very last command |
!string | Run last command that starts with “string” |
Ctrl+R | Interactive reverse search through history |
Usage:
$ history
$ history 15
$ !42 # run command #42
$ !! # repeat last command
$ sudo !! # run last command as root
$ !grep # run last grep command
9. cp – Copy
Definition:cp stands for Copy. It copies files or entire directories from one location to another. The original file remains untouched cp creates a new, independent copy at the destination. You can copy single files, multiple files, or entire directory trees.
Why it matters: Essential for creating backups, duplicating configurations, and deploying files. Understanding cp options prevents accidental overwrites and data loss.
Syntax:
cp [OPTIONS] source destination
Options:
| Option | Description |
|---|---|
cp src dest | Copy a single file |
cp -r dir/ dest/ | Recursively copy a directory and its contents |
cp -i | Interactive prompt before overwriting existing files |
cp -u | Update only copy if source is newer than destination |
cp -v | Verbose display each file being copied |
cp -p | Preserve file attributes (timestamps, permissions, owner) |
cp -a | Archive mode equivalent to -dR --preserve=all |
cp -n | No-clobber never overwrite existing files |
Usage:
$ cp report.txt /backup/
$ cp -r /home/user/projects /mnt/usb/
$ cp -iv config.yaml config.yaml.bak
$ cp -a /website/ /website_backup/
10. mv – Move
Definition:mv stands for Move. It either moves a file/directory to a new location, or renames it both operations are handled by the same command. When renaming, the file stays in the same directory but gets a new name. When moving, it goes to a different directory. Unlike cp, the original is removed after the operation.
Why it matters: mv is how you reorganize your filesystem rename files, move them into folders, or archive them. It’s also instant when moving within the same filesystem (no data is physically copied).
Syntax:
mv [OPTIONS] source destination
Options:
| Option | Description |
|---|---|
mv old new | Rename a file |
mv file /dir/ | Move file to a directory |
mv -i | Interactive prompt before overwriting |
mv -u | Update only move if source is newer |
mv -v | Verbose show what is being moved |
mv -n | No-clobber never overwrite destination |
mv -b | Make a backup of destination if it exists |
Usage:
$ mv oldname.txt newname.txt # rename
$ mv report.txt /home/user/Documents/ # move
$ mv -iv *.log /var/log/archive/ # move all .log files
$ mv -n source.txt dest.txt # won't overwrite
For more insights and updates, follow us on Google News, Twitter, and LinkedIn.
11. mkdir – Make Directory
Definition:mkdir stands for Make Directory. It creates one or more new directories at the specified path. If the parent directories in the path don’t exist, you either need to create them first or use the -p flag to create them automatically in a single command.
Why it matters: Organizing your work into directories is fundamental to managing any project or system. mkdir is how every new folder comes to life from the terminal.
Syntax:
bashmkdir [OPTIONS] directory_name(s)
Options:
| Option | Description |
|---|---|
mkdir dir | Create a single directory |
mkdir dir1 dir2 dir3 | Create multiple directories at once |
mkdir -p a/b/c/d | Create full nested path (parents included) |
mkdir -v dir | Verbose confirm directory creation |
mkdir -m 755 dir | Set directory permissions at creation time |
Usage:
$ mkdir projects
$ mkdir logs reports backups # multiple at once
$ mkdir -p /opt/app/config/logs # create full nested path
$ mkdir -m 700 private # only owner can access
$ mkdir -pv /data/{raw,processed,output} # brace expansion
12. rm – Remove
Definition:rm stands for Remove. It permanently deletes files and directories from the filesystem. There is no Recycle Bin or Trash once a file is removed with rm, it is gone immediately and cannot be recovered through normal means. This makes rm one of the most powerful and potentially dangerous commands in Linux.
Why it matters: Disk management, cleanup scripts, and system administration all depend on rm. But one wrong command (especially with -rf) can wipe critical data. Always double-check before running.
Syntax:
rm [OPTIONS] file/directory
Options:
| Option | Description |
|---|---|
rm file | Delete a single file |
rm file1 file2 | Delete multiple files |
rm -r dir/ | Recursively delete a directory and all its contents |
rm -f file | Force delete no error if file doesn’t exist, no prompt |
rm -rf dir/ | Force recursive delete ⚠️ very dangerous |
rm -i file | Interactive confirm each deletion |
rm -v file | Verbose show each file as it’s deleted |
Usage:
$ rm oldfile.txt
$ rm -i important.log # ask before deleting
$ rm -rf /tmp/cache/ # force delete directory
$ rm -v *.tmp # delete all .tmp with confirmation
Warning: Never run
rm -rf /orrm -rf /*it will destroy your entire filesystem.
13. find
Definition:find is a powerful command that searches for files and directories across the filesystem based on criteria you define such as name, type, size, owner, permissions, or modification time. Unlike ls, which only shows the contents of a specific directory, find can search recursively through an entire directory tree.
Why it matters: When you don’t know where a file is, or need to find all files matching a pattern (e.g., all .log files older than 7 days), find is indispensable. It can also execute actions on what it find like deleting or changing permissions.
Syntax:
find [PATH] [OPTIONS] [EXPRESSION]
Options / Expressions:
| Expression | Description |
|---|---|
-name "*.txt" | Find by filename/pattern (case-sensitive) |
-iname "*.txt" | Case-insensitive name match |
-type f | Find files only |
-type d | Find directories only |
-type l | Find symbolic links only |
-size +10M | Larger than 10 MB |
-size -1k | Smaller than 1 KB |
-mtime -7 | Modified within the last 7 days |
-mtime +30 | Modified more than 30 days ago |
-user username | Find files owned by a user |
-perm 644 | Find files with specific permissions |
-empty | Find empty files or directories |
-exec cmd {} \; | Run a command on each result |
Usage:
$ find /home -name "*.log"
$ find / -type f -size +100M
$ find . -mtime -3 -type f
$ find /tmp -name "*.tmp" -exec rm {} \;
$ find . -empty -type f -delete
14. help
Definition:help is a bash built-in command that displays usage information and documentation for other bash built-in commands. Shell built-ins are commands like cd, echo, exit, alias that are part of the shell program itself not separate executables installed on the system. For those commands, man doesn’t always work, but help does.
Why it matters: Beginners often try man cd and get confused when it doesn’t work normally. help cd is the correct way to get documentation for shell built-ins. It’s a quick, offline reference directly in the shell.
Syntax:
help [OPTIONS] [command]
Options:
| Option | Description |
|---|---|
help | List all bash built-in commands |
help command | Show detailed help for a specific built-in |
help -d command | Show a short one-line description |
help -m command | Display help in man-page style format |
help -s command | Show only the usage synopsis |
Usage:
$ help
$ help cd
$ help -d echo
$ help -m alias
$ help -s for
Note:
helponly works for bash built-ins. For external programs (likels,find,grep), useman commandorcommand --help.
For more insights and updates, follow us on Google News, Twitter, and LinkedIn.
15. man – Manual
Definition:man stands for Manual. It opens the official, comprehensive manual page (called a “man page”) for a command, system call, library function, or configuration file. Man pages are the official documentation included with Linux/Unix systems they cover every option, argument, and behavior of a command in precise detail.
Why it matters: man is the definitive reference on any Linux system. No internet required all documentation is stored locally. Every serious Linux user relies on it for learning and troubleshooting.
Syntax:
man [SECTION] command
Manual Sections:
| Section | Content |
|---|---|
| 1 | User commands (shell commands) |
| 2 | System calls (kernel functions) |
| 3 | C library functions |
| 4 | Special files and devices |
| 5 | File formats and conventions |
| 6 | Games and screensavers |
| 7 | Miscellaneous |
| 8 | System administration commands |
Options:
| Option | Description |
|---|---|
man command | Open the man page for a command |
man N command | Open man page in section N |
man -k keyword | Search all man pages by keyword |
man -f command | Show one-line description (same as whatis) |
man -a command | Show all man pages for the command |
Usage:
$ man ls
$ man 5 passwd # section 5: file format of /etc/passwd
$ man -k "list files" # keyword search
$ man -f chmod # one-line description
16. whatis
Definition:whatis searches the manual page index database and returns a brief one-line description of a command. It’s essentially a quick-lookup tool like the index of a book that tells you what a command does in a single sentence without opening the full man page.
Why it matters: When you encounter an unfamiliar command name and just want to know “what does this do?” whatis gives you the answer instantly. It’s faster than man when you just need a quick ID.
Syntax:
whatis [OPTIONS] command
Options:
| Option | Description |
|---|---|
whatis command | Show one-line description from man index |
whatis -r pattern | Use regex to search descriptions |
whatis -w "ls*" | Wildcard search |
whatis cmd1 cmd2 | Look up multiple commands at once |
Usage:
$ whatis ls
ls (1) - list directory contents
$ whatis pwd
pwd (1) - print name of current/working directory
$ whatis find grep awk # look up multiple commands
$ whatis -r "copy" # find all commands related to "copy"
Note: If
whatisreturns “nothing appropriate”, runsudo mandbto rebuild the manual database index.
17. alias
Definition:alias allows you to create custom shortcut names for commands especially long, complex, or frequently used ones. Instead of typing ls -la --color=auto every time, you can define alias ll='ls -la --color=auto' and just type ll. Aliases exist only in the current session unless saved to a configuration file.
Why it matters: Aliases dramatically improve terminal productivity. Power users maintain libraries of aliases to simplify their workflows. They can also be used to add safety defaults (e.g., alias rm='rm -i' to always confirm deletions).
Syntax:
alias [name='command']
Options:
| Command | Description |
|---|---|
alias | List all currently active aliases |
alias name='command' | Create a new alias |
unalias name | Remove a specific alias |
unalias -a | Remove all active aliases |
Usage:
$ alias ll='ls -la'
$ alias gs='git status'
$ alias cls='clear'
$ alias update='sudo apt update && sudo apt upgrade -y'
$ alias rm='rm -i' # safer rm with confirmation
# List all aliases
$ alias
# Remove an alias
$ unalias ll
Making Aliases Permanent:
Add to ~/.bashrc or ~/.bash_aliases:
echo "alias ll='ls -la'" >> ~/.bashrc
source ~/.bashrc
18. exit
Definition:exit terminates the current shell session or running script. When used in a terminal, it closes that shell instance. When used inside a shell script, it stops execution of the script at that point. It optionally accepts an exit status code a number that tells the calling process whether execution succeeded or failed. This is crucial in scripting and automation.
Why it matters: In shell scripting, exit codes are the standard way programs communicate success or failure to each other. A code of 0 means success; anything else indicates an error. This enables conditional logic in pipelines and automation systems (CI/CD, cron jobs, etc.).
Syntax:
exit [STATUS_CODE]
Exit Status Codes:
| Code | Meaning |
|---|---|
0 | Success — command/script completed without errors |
1 | General error |
2 | Misuse of shell built-in |
126 | Command found but not executable |
127 | Command not found |
128+N | Fatal error signal N |
130 | Script interrupted by Ctrl+C (signal 2) |
Usage:
$ exit # close terminal session
$ exit 0 # exit with success
$ exit 1 # exit with error
# In a shell script:
#!/bin/bash
if [ ! -f config.txt ]; then
echo "Error: Config file not found!"
exit 1
fi
echo "Config found, continuing..."
exit 0
# Check last command's exit code:
$ ls /nonexistent
$ echo $? # prints: 2 (error code)