Files and Directories
touch, mkdir, cp, mv, rm — creating, copying, moving, and deleting
Skills taught: linux.touch, linux.mkdir, linux.cp, linux.mv, linux.rm
Creating files and directories
# Create an empty file (or update its timestamp if it exists)
touch notes.txt
touch index.html style.css app.js # create multiple files
# Create a directory
mkdir projects
mkdir -p projects/myapp/src # -p creates parent dirs as needed
mkdir -p {images,css,js} # brace expansion: creates 3 dirs
# Check what was created
ls -la
Copying and moving
# Copy a file
cp README.md README.md.bak # copy to same directory with new name
cp notes.txt ~/Documents/ # copy to a different directory
cp -r src/ backup/ # -r: copy directory recursively
# Move (also used for renaming)
mv oldname.txt newname.txt # rename
mv notes.txt ~/Documents/ # move to different directory
mv *.log /var/log/archive/ # move all .log files
# Move multiple files into a directory
mv file1.txt file2.txt destination/
Deleting files — be careful, no Trash
# Delete a file
rm notes.txt
# Delete multiple files
rm file1.txt file2.txt file3.txt
# Delete a directory and its contents
rm -r myproject/ # recursive delete
rm -rf node_modules/ # force + recursive (no prompts)
# Safer: interactive delete (asks before each file)
rm -i *.log
# Delete an empty directory
rmdir empty_folder/
Warning: rm is permanent — there is no Trash. There is no undo. rm -rf / would delete everything on the system. Always double-check the path before running rm -rf. Consider using trash-cli (a safe alternative) or adding an alias: alias rm='rm -i' in your .bashrc.
Frequently Asked Questions
How do I rename a directory?
mv old_name/ new_name/ — mv works for both files and directories. You don't need -r to rename (only to copy with cp -r). Example: mv my-project/ kernal-app/