ποΈ 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 :
