You can navigate the file system. Now it is time to manipulate files, creating them, copying them, moving them, and deleting them. This is where the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell. starts to feel like a superpower. You will learn to create entire project structures in seconds, copy hundreds of files with one command, and safely manage permanent deletion.
Creating files and directories
Creating a new file in a file manager means right-click, select "New Document", wait for the menu, type a name. In the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell.:
touch readme.txt # Create one file
touch index.html style.css script.js # Create multiple files
touch ~/Documents/notes.txt # Create in specific locationFor directories, use mkdir. The -p flag creates the entire nested path at once:
mkdir my-project # Create one folder
mkdir -p my-project/src/components # Create entire nested structureThe -p flag is idempotentWhat is idempotent?An operation that produces the same result whether you perform it once or multiple times, making retries safe., you can run the same command multiple times safely. If the directories already exist, it will not complain.
Copying: the cp command
cp original.txt backup.txt # Copy file in same directory
cp document.txt Documents/ # Copy to another directory
cp -r my-folder/ backup-folder/ # Copy directory (requires -r)Without -r (recursive), copying a directory gives an error. The -r flag tells cp to go inside and copy everything within it.
| Flag | What it does | When to use it |
|---|---|---|
-r | Recursive (copy directories) | Always needed for folders |
-i | Interactive (ask before overwrite) | Safety when files might exist |
-v | Verbose (show what is happening) | Debugging or confirmation |
-p | Preserve attributes | Backup scenarios |
Moving and renaming: the mv command
There is no separate "rename" command. Renaming is just moving a file to a new name in the same location.
mv oldname.txt newname.txt # Rename
mv file.txt Documents/ # Move to another directory
mv draft.txt Documents/final.txt # Move and rename at the same time
mv old-folder/ new-location/ # Move directory (no -r needed)Deleting: the rm command (handle with care)
This is serious business because the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell. does not have a trash can. When you delete something with rm, it is gone immediately. No undo.
rm unwanted-file.txt # Delete one file
rm file1.txt file2.txt file3.txt # Delete multiple files
rm -r old-folder/ # Delete directory and contents
rm -i file.txt # Ask for confirmation first (safe)| Command | Risk level | What it does |
|---|---|---|
rm file.txt | Medium | Deletes one file permanently |
rm -i file.txt | Low | Asks for confirmation first |
rm -r folder/ | High | Deletes folder and all contents |
rm -rf folder/ | Extreme | Force deletes without confirmation |
rm -rf casually, as if it is no big deal. They also suggest sudo without explaining that it runs commands as the administrator, one wrong sudo rm -rf and you can wipe your entire system. Never run sudo unless you understand exactly why it is needed, and never run rm -rf on a path you have not verified. Use ls first to preview what matches your pattern.Safer deletion practice
Always preview before deleting:
ls *.log # See what .log files exist
rm *.log # Now delete them (you know what you are removing)Viewing file contents
You do not always need to open a full editor to see what is in a file.
cat readme.txt # Display entire file (small files only)
head -n 20 log.txt # First 20 lines
tail -n 50 log.txt # Last 50 lines
tail -f server.log # Follow new entries in real-time
less huge-file.txt # Interactive viewer for large filesless opens an interactive viewer where you can scroll and search:
| Key | Action |
|---|---|
Space or f | Next page |
b | Previous page |
/searchterm | Search for text |
n | Next search result |
q | Quit |
Wildcards: working with multiple files
The asterisk (*) matches any characters. This is where the terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell. really shines compared to graphical file managers.
ls *.txt # All .txt files
cp *.jpg Photos/ # Copy all .jpg files to Photos
rm temp-* # Delete all files starting with "temp-"
mv *.log archive/ # Move all log files to archiveSelecting 47 specific files by hand is tedious. Selecting them with a pattern is instant.
Quick reference
| Task | Command | Notes |
|---|---|---|
| Create empty file | touch file.txt | Multiple: touch a.txt b.txt |
| Create folder | mkdir folder | Nested: mkdir -p path/to/folder |
| Copy file | cp source dest | Use -r for directories |
| Move/rename | mv source dest | Works for files and directories |
| Delete file | rm file | Permanent, no undo |
| Delete folder | rm -r folder/ | Recursive deletion |
| View file | cat file.txt | Small files only |
| Browse large file | less file.txt | Interactive viewer |
| Watch log | tail -f log.txt | Real-time updates |