File Operations

Commands for creating, copying, moving, and deleting files and directories.

Create and Copy

Command

Description

Examples

mkdir <dir>

Create directory

mkdir folder1
mkdir -p parent/child (nested)

cp <src> <dest>

Copy file or directory

cp file1.txt backup.txt
cp file.txt /home/user/
cp -r dir1 dir2 (directories)

Move and Rename

Command

Description

Examples

mv <src> <dest>

Move or rename

mv file.txt newname.txt (rename)
mv file.txt /home/user/ (move)

Delete

Command

Description

Examples

rm <file>

Remove file/directory

rm file.txt
rm -r folder/ (recursive)

rmdir <dir>

Remove empty directory

rmdir empty_folder

Warning

Commands that write to files (cp, mv, rm) will overwrite existing files without warning. There is no undo button—be deliberate with these commands.

Common Patterns

ls -la                 # List all (including hidden)
cp source dest         # Copy
mv old new             # Move/rename
rm file                # Delete (be careful!)
rm -r dir              # Delete directory
mkdir -p a/b/c         # Create nested directories

Tips

  • Always double-check paths before running rm

  • Use rm -i for interactive confirmation before deleting

  • cp -i prompts before overwriting files

  • Test commands with ls first to verify paths