File management commands are used to:
- Create files
- Create directories
- Copy files
- Move files
- Delete files
- Create links
Most commonly used commands:
- touch
- mkdir
- cp
- mv
- rm
- ln
These commands are heavily used in:
- Linux administration
- DevOps
- Cloud engineering
- Automation
- Application deployment
1. touch Command
Purpose
Creates empty files or updates file timestamps.
Syntax
touch filename
Example
touch app.log
Creates:
app.log
Create Multiple Files
touch file1.txt file2.txt file3.txt
Real-World Usage
Create Log File
touch /var/log/custom.log
Create Configuration Placeholder
touch nginx.conf
2. mkdir Command
Purpose
Creates directories.
Syntax
mkdir directory_name
Example
mkdir projects
Creates:
projects/
Create Multiple Directories
mkdir dev test prod
Create Nested Directories
mkdir -p app/backend/config
Creates:
app/
└── backend/
└── config/
Real-World Usage
Deployment Structure
mkdir -p /opt/app/logs
Kubernetes Manifest Folder
mkdir -p k8s/deployments
3. cp Command
Purpose
Copies files and directories.
Syntax
cp source destination
Example
cp file.txt backup.txt
Copies:
file.txt → backup.txt
Copy Directory
cp -r project backup_project
- r = recursive
Important Options
| Option | Purpose |
|---|---|
| -r | Copy directories |
| -v | Verbose output |
| -p | Preserve permissions |
| -i | Ask before overwrite |
Real-World Usage
Backup Configuration
cp /etc/nginx/nginx.conf nginx.conf.bak
Copy Deployment Files
cp -r build/ /var/www/html/
4. mv Command
Purpose
Moves or renames files/directories.
Syntax
mv source destination
Rename File
mv old.txt new.txt
Move File
mv app.log /var/log/
Move Directory
mv project /opt/
Real-World Usage
Rotate Logs
mv app.log app.log.old
Move Deployment Files
mv release/ /opt/application/
5. rm Command
Purpose
Deletes files and directories.
Syntax
rm filename
Example
rm file.txt
Deletes:
file.txt
Remove Directory
rm -r project
Important Options
| Option | Purpose |
|---|---|
| -r | Recursive delete |
| -f | Force delete |
| -i | Ask before deleting |
Real-World Usage
Remove Old Logs
rm -f old.log
Remove Temporary Files
rm -rf /tmp/cache
Dangerous Command
rm -rf /
This can destroy the entire Linux system.
Never run unknown rm -rf commands.
6. ln Command
Purpose
Creates links between files.
Two types:
- Hard link
- Symbolic (soft) link
Symbolic Link
Syntax
ln -s target link_name
Example
ln -s /var/log/app.log applog
Creates:
applog -> /var/log/app.log
Hard Link
ln file1 hardlink1
Difference Between Hard and Soft Links
| Hard Link | Soft Link |
|---|---|
| Direct inode reference | Points to file path |
| Cannot cross filesystems | Can cross filesystems |
| Works even if original deleted | Breaks if original deleted |
Real-World Usage
Application Symlink
ln -s /opt/app/current app
Common in deployments.
Shared Configuration
ln -s /etc/nginx/sites-enabled/app.conf app.conf
Top comments (0)