Linux/Unix Tutorial
Estimated reading: 3 minutes 265 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 :
Share

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

Or Copy Link

CONTENTS
Scroll to Top