금. 7월 25th, 2025

Mastering file operations is essential for Linux beginners. Here’s a clear guide to key commands with practical examples:

🖼️ Understanding the Linux File Structure

Linux Directory Structure
Linux uses a tree-like directory structure starting from root (/). Always know your current location with pwd.


🗑️ 1. Deleting Files and Folders

Delete a file:

rm filename.txt

Delete empty folder:

rmdir folder_name

Delete folder with contents:

rm -r folder_name

Terminal showing rm command
Use -i for confirmation prompts: rm -i file.txt

⚠️ Danger Zone:
rm -rf / will delete EVERYTHING! Triple-check paths before using -rf.


📑 2. Copying Files and Folders

Copy a file:

cp source.txt destination/

Copy folder recursively:

cp -r source_folder/ destination/

Preserve file attributes:

cp -p important_doc.conf backup/

File copy visualization
Use TAB key for path auto-completion to avoid typos


🚚 3. Moving/Renaming Files and Folders

Move a file:

mv file.txt /new/location/

Rename a file:

mv oldname.txt newname.txt

Move folder:

mv project/ ~/backups/

mv command example
Same mv command handles both moving and renaming


💡 Pro Tips for Beginners

  1. Dry-run first: Add -v (verbose) to see what will happen:
    cp -rv source/ destination/

  2. Undo protection:

    alias rm='rm -i'   # Adds confirmation prompt
    alias cp='cp -i'
    alias mv='mv -i'

    Add these to ~/.bashrc for safety

  3. Restore deleted files?
    Install trash-cli for recycle bin functionality:
    sudo apt install trash-cli && trash file.txt


✅ Practice Exercise

mkdir test
cd test
touch file1.txt
cp file1.txt file2.txt
mv file2.txt renamed.txt
rm renamed.txt
cd ..
rm -r test

📌 Key Takeaway:
Always double-check paths before executing destructive commands. Start with safe options (-i) until you’re confident!

Linux terminal practice
Practice these commands in a test directory first to build confidence

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다