1. cd — Change Directory
Changes the current working directory.
Syntax
cd <path>
Common Usage
cd / # Go to the root directory
cd ~ # Go to the current user's home directory
cd .. # Move up one directory
cd - # Return to the previous directory
cd ./Documents # Relative path
cd /var/log # Absolute path
Path Types
-
Absolute path: Starts with
/and specifies the full path from the root directory. -
Relative path: Starts from the current directory (e.g.
./,../, or a directory name).
Tips
- Press Tab for auto-completion.
- Use quotes for directory names containing spaces.
cd "My Folder"
2. ls — List Files and Directories
Displays the contents of a directory.
Syntax
ls [options] [path]
Common Options
ls # List files
ls -l # Long format
ls -a # Include hidden files
ls -la # Long format + hidden files
ls -lh # Human-readable file sizes
ls -t # Sort by modification time
ls -S # Sort by file size
ls -r # Reverse sort order
ls -R # Recursive listing
ls -d */ # Show directories only
Useful Combinations
ls -altr # Hidden files, long format, time sort, reverse order
ls -alF # Append indicators (/, *, etc.)
ls -lthr # Human-readable, time sort, newest at the bottom
3. pwd — Print Working Directory
Displays the absolute path of the current directory.
Syntax
pwd
Options
pwd -L # Logical path (default)
pwd -P # Physical path (resolve symbolic links)
Example:
/home/user/workspace
4. mkdir — Make Directory
Creates one or more directories.
Syntax
mkdir [options] <directory>
Common Usage
mkdir project
mkdir dir1 dir2 dir3
mkdir -p parent/child/grandchild
mkdir -v new_folder
mkdir -m 755 secure_folder
Useful Options
-
-p: Create parent directories if needed. -
-v: Show created directories. -
-m: Set permissions when creating the directory.
5. rm — Remove Files and Directories
Deletes files or directories permanently.
Warning: Deleted files cannot be recovered from the Trash.
Syntax
rm [options] <file>
Common Usage
rm file.txt
rm -i file.txt
rm -r directory
rm -f file.txt
rm -rf directory
Multiple Files & Wildcards
rm file1.txt file2.txt
rm *.log
Important Options
-
-i: Ask for confirmation. -
-r: Remove directories recursively. -
-f: Force deletion without prompts.
Never run
sudo rm -rf /This command can destroy the entire operating system.
6. cp — Copy Files and Directories
Copies files or directories while keeping the original intact.
Syntax
cp [options] <source> <destination>
Common Usage
cp file1.txt file2.txt
cp -r dir1 dir2
cp file1.txt file2.txt ~/backup/
cp -a /etc/config.conf ~/backup/
Useful Options
-
-r/-R: Copy directories recursively. -
-a: Archive mode (preserve attributes, permissions, timestamps, and symbolic links). -
-p: Preserve file metadata. -
-i: Confirm before overwriting. -
-f: Force overwrite.
7. mv — Move or Rename Files
Moves files/directories or renames them.
Syntax
mv [options] <source> <destination>
Common Usage
mv file1.txt ~/Documents/
mv file1.txt file2.txt
mv folder1 ~/backup/
mv file1.txt file2.txt ~/backup/
Useful Options
-
-i: Confirm before overwriting. -
-f: Force overwrite. -
-n: Never overwrite existing files. -
-v: Show each move operation.
Top comments (0)