Basic Linux commands in action
Introduction to Linux File Operations
Linux provides simple but powerful commands to manage your files and folders. Unlike graphical interfaces, command-line tools give you precise control. Let’s learn three essential operations: deleting, copying, and moving files.
🔥 1. Deleting Files and Folders
Key commands: rm
(remove) and rmdir
(remove directory)
Delete a file:
rm filename.txt
Delete multiple files:
rm file1.jpg file2.txt file3.log
Delete a folder (and its contents):
rm -r my_folder
⚠️ Warning: rm -r
is permanent! Linux has no recycle bin.
Delete empty folder:
rmdir empty_folder
📋 2. Copying Files and Folders
Key command: cp
(copy)
Copy a file:
cp original.txt duplicate.txt
Copy to another directory:
cp document.pdf ~/Documents/
Copy a folder recursively:
cp -r Photos/ Vacation_Photos/
Preserve file attributes:
cp -p source_file backup_file
🚚 3. Moving/Renaming Files and Folders
Key command: mv
(move)
Move a file:
mv report.docx /archive/
Rename a file:
mv oldname.txt newname.txt
Move multiple files:
mv *.png ~/Pictures/
Move a folder:
mv Project/ /backup/project_archive/
⚠️ Critical Safety Tips
- Double-check paths before deleting
- Use
ls
to verify files before runningrm
- Add
-i
for interactive confirmation:rm -i important_file.txt cp -i source.txt existing_file.txt
- Use tab completion (type partial name + press
Tab
)
💡 Practice Exercise
- Create test files:
touch file1 file2 file3
- Make a folder:
mkdir test_backup
- Copy files:
cp file* test_backup/
- Rename one:
mv test_backup/file1 test_backup/renamed
- Delete originals:
rm file*
- Verify with
ls test_backup
Conclusion
Mastering rm
, cp
, and mv
gives you fundamental control over your Linux system. Start with simple operations and gradually incorporate options like -r
(recursive) and -i
(interactive). Remember: With great power comes great responsibility! 🔐
> 💻 Pro Tip: Use man cp
, man rm
, or man mv
to explore more options in the manual pages!