Linux/Unix: File & Directory Operations β Manage Files, Folders & Links Efficiently
Introduction β Why Learn Linux File & Directory Commands?
Mastering file and directory operations in Linux/Unix is a must for developers, system administrators, and power users. Whether you’re navigating file systems, manipulating files, or understanding symbolic and hard linksβLinux provides concise, powerful commands for every task.
In this guide, youβll learn:
- How to copy, move, and remove files
- How to navigate and manage directories
- How to use file system utilities like
df,du,ln, andtouch - How file types, permissions, and usage statistics are handled
Topics Covered
| Subtopic | Description |
|---|---|
| Linux/Unix: File Management | Use of cp, mv, rm for file operations |
| Linux/Unix: Directory Handling | Commands like ls, cd, mkdir, rmdir for folder navigation and management |
| Linux/Unix: File Links & File System Basics | Create links (ln), view usage (df, du), get metadata (stat, file) |
Linux/Unix: File Management (cp, mv, rm)
cp β Copy Files or Directories
cp file1.txt backup/
Copies file1.txt into the backup folder.
mv β Move or Rename Files
mv report.txt old_report.txt
Renames or moves report.txt.
rm β Delete Files or Directories
rm temp.txt
rm -r folder/
Deletes a file or recursively removes a directory.
Caution: rm permanently deletes filesβno recycle bin!
Linux/Unix: Directory Handling (ls, cd, mkdir, rmdir)
ls β List Directory Contents
ls -l /etc
Shows detailed contents including permissions, owners, sizes.
cd β Change Directory
cd /var/log
Navigates to /var/log.
mkdir β Create New Directory
mkdir new_project
Creates a folder named new_project.
rmdir β Remove Empty Directory
rmdir old_folder
Deletes a folder if itβs empty.
Use rm -r to remove non-empty directories.
Linux/Unix: File Links (ln), File System Basics (df, du, stat, file, touch)
ln β Create Links
- Hard Link:
ln original.txt link.txt
- Symbolic (Soft) Link:
ln -s original.txt shortcut.txt
Hard links share the same inode; symbolic links point to the file path.
df β Disk Free Space
df -h
Shows available and used disk space in human-readable format.
du β Directory Usage
du -sh *
Summarizes disk usage per file/folder.
stat β File Metadata
stat file.txt
Displays file size, permissions, timestamps, and inode info.
file β Detect File Type
file filename
Identifies if a file is ASCII text, binary, script, etc.
touch β Create/Update File Timestamp
touch newfile.txt
Creates a new empty file or updates the modification time.
Summary β Recap & Next Steps
File and directory operations form the core foundation of any Unix/Linux workflow. These commands are fast, scriptable, and give full control over files and system resources.
Key Takeaways:
- Use
cp,mv,rmfor file management ls,cd,mkdir,rmdirhelp manage directorieslncreates links;df,du,stat, andfilehelp inspect and audittouchis great for scripting placeholder files or resetting timestamps
Practical Use Cases:
- Backup and rename log files with
cpandmv - Clean up space using
duanddf - Organize projects using
mkdirand symbolic links
Frequently Asked Questions
What is the difference between rm and rmdir?
rm removes files or directories (use -r for folders), while rmdir only removes empty directories.
What are symbolic vs hard links?
Hard links share the same inode; symbolic links are pointers to the original file path.
How do I check disk usage?
Use:
df -h # For filesystem-level usage
du -sh * # For per-directory usage
Share Now :
