Linux / Bash
Beginner
1 min read
Creating, Copying, and Moving Files
Example
# Create an empty file
touch notes.txt
# Create multiple files at once
touch file1.txt file2.txt file3.txt
# Update timestamp of an existing file
touch -t 202401151200 notes.txt
# Create a directory
mkdir projects
# Create nested directories in one command
mkdir -p projects/webapp/src/components
# Copy a file
cp notes.txt notes_backup.txt
# Copy a file to a directory
cp notes.txt /tmp/
# Copy a directory recursively
cp -r projects/ projects_backup/
# Copy preserving metadata (permissions, timestamps)
cp -rp projects/ /backup/projects/
# Move (rename) a file
mv notes.txt notes_v2.txt
# Move a file to another directory
mv notes_v2.txt /tmp/
# Move multiple files into a directory
mv file1.txt file2.txt file3.txt /tmp/
# Remove a file
rm file1.txt
# Remove a file with confirmation
rm -i file2.txt
# Remove a directory and all contents
rm -rf projects_backup/
# Remove empty directory
rmdir empty_dir/
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash