Script Valley
Linux & Bash for Developers
Linux Fundamentals & File SystemLesson 1.4

Creating, copying, moving, and deleting files in Linux

touch, mkdir -p, cp flags, mv, rm -rf, wildcards, rename patterns, file vs directory operations

File Operations You Will Use Every Day

These five commands — touch, mkdir, cp, mv, rm — cover all basic file management. The danger is in rm: Linux has no trash bin by default. Deleted means gone.

Creating Files and Directories

# Create an empty file (or update its timestamp)
touch app.log

# Create nested directories in one command
mkdir -p projects/backend/src

# Create multiple files at once
touch index.js package.json .env

Copying and Moving

# Copy file
cp config.json config.json.bak

# Copy entire directory recursively
cp -r src/ src_backup/

# Move or rename
mv old_name.txt new_name.txt
mv file.txt /var/www/html/

Deleting Safely

# Delete a file
rm file.txt

# Delete directory and contents recursively
# WARNING: no confirmation, no undo
rm -rf build/

# Safer: use -i flag for interactive confirmation
rm -ri build/

Never run rm -rf / or rm -rf ~ or rm -rf * in your home directory. These wipe everything. Modern systems block the first one, but the others are fair game.

Up next

Linux file permissions and chmod explained

Sign in to track progress