Modern QA2026File Operations
Log inJoin
4 / 8 · Book 19 · The Linux Directory Structure← prev⊞ allnext →Get the book →

1.4File Operations

These commands form the foundation of all file manipulation:

# Create directories (including parents)
mkdir -p tests/integration/api

# Copy files
cp source.json destination.json
cp -r tests/ tests-backup/       # Recursive copy (for directories)

# Move/rename files
mv old-name.ts new-name.ts
mv test-results/ archive/test-results-sprint23/

# Remove files
rm unwanted-file.txt
rm -r old-directory/              # Recursive remove
rm -rf node_modules/              # Force recursive remove (use carefully!)

# Create an empty file
touch new-test.spec.ts

# View file content
cat small-file.txt                # Entire file (for small files only)
head -20 large-file.log           # First 20 lines
tail -50 large-file.log           # Last 50 lines
tail -f /var/log/app.log          # Follow file in real-time (live log monitoring)
less large-file.log               # Paginated viewer (press q to quit)

Common Mistake: rm -rf is the most dangerous command in Linux. It recursively force-deletes everything in the specified path with no confirmation and no recycle bin. Double-check your path before pressing Enter. rm -rf / will attempt to delete your entire filesystem. Some horror stories involve a misplaced space: rm -rf / tmp/old-files (deletes root!) versus rm -rf /tmp/old-files (deletes only the temp directory).