Linux/Unix Tutorial
Estimated reading: 3 minutes 34 views

πŸ—ƒοΈ 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, and touch
  • How file types, permissions, and usage statistics are handled

πŸ“˜ Topics Covered

πŸ”΅ SubtopicπŸ“– Description
Linux/Unix: File ManagementUse of cp, mv, rm for file operations
Linux/Unix: Directory HandlingCommands like ls, cd, mkdir, rmdir for folder navigation and management
Linux/Unix: File Links & File System BasicsCreate 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, rm for file management
  • ls, cd, mkdir, rmdir help manage directories
  • ln creates links; df, du, stat, and file help inspect and audit
  • touch is great for scripting placeholder files or resetting timestamps

βš™οΈ Practical Use Cases:

  • Backup and rename log files with cp and mv
  • Clean up space using du and df
  • Organize projects using mkdir and 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

πŸ—ƒοΈ Linux/Unix: File & Directory Operations

Or Copy Link

CONTENTS
Scroll to Top