File Management and Manipulation in Linux
1. Introduction
File management and manipulation in Linux refers to the process of creating, viewing, copying, moving, renaming, deleting, and modifying files and directories. Linux provides powerful command-line tools to handle files efficiently, making it ideal for multi-user systems, servers, and system administration.
2. File Management Basics
Linux treats everything as a file, including:
- Text files
- Directories
- Device files
- Configuration files
File management mainly involves:
- Creating files/directories
- Viewing file content
- Copying & moving files
- Deleting files
- Searching files
- Changing permissions & ownership
3. Creating Files and Directories
Creating Files
touch file.txt
Creates an empty file.
Creating Directories
mkdir folder
mkdir -p parent/child
4. Viewing and Displaying Files
Display File Content
cat file.txt
Page-wise Viewing
more file.txt
less file.txt
View File Start / End
head file.txt
tail file.txt
tail -f logfile.log
5. Copying Files and Directories
Copy File
cp file1.txt file2.txt
Copy Directory
cp -r folder1 folder2
Options:
-i→ Interactive-v→ Verbose
6. Moving and Renaming Files
Move File
mv file.txt /home/user/
Rename File
mv oldname.txt newname.txt
📌 mv is used for both moving and renaming.
7. Deleting Files and Directories
Delete File
rm file.txt
Delete Directory
rm -r folder
⚠️ Dangerous command, especially with root access.
8. Searching Files
Using find
find /home -name file.txt
Using locate
locate file.txt
(Requires updated database)
9. File Comparison
Compare Two Files
diff file1.txt file2.txt
Shows line-by-line differences.
10. File Information Commands
File Type
file file.txt
File Size & Details
ls -lh
stat file.txt
11. Sorting and Filtering File Content
Sort File Content
sort file.txt
Count Lines, Words, Characters
wc file.txt
Search Text in File
grep "word" file.txt
12. File Permissions & Ownership (Manipulation)
Change Permissions
chmod 644 file.txt
Change Owner
chown user file.txt
13. Archiving and Compression
Create Archive
tar -cvf files.tar folder/
Extract Archive
tar -xvf files.tar
Compressed Archive
tar -czvf files.tar.gz folder/
14. Backup and Restore (Basic)
cp -r /data /backup/data_backup
15. Real-World Example
- Web server files stored in
/var/www - Logs stored in
/var/log - Admin regularly:
- Views logs
- Compresses old files
- Deletes unnecessary data
16. Advantages of Linux File Management
- Powerful command-line tools
- High speed and efficiency
- Suitable for automation (scripts)
- Strong security control
- Ideal for servers
17. Summary Table (Exam-Friendly)
| Command | Purpose |
|---|---|
touch | Create file |
cp | Copy |
mv | Move/Rename |
rm | Delete |
find | Search |
grep | Search text |
chmod | Permissions |
tar | Archive |
18. Conclusion
File management and manipulation in Linux provide complete control over data handling. With powerful commands and strong security mechanisms, Linux ensures efficient, safe, and scalable file operations, especially in multi-user and server environments.
