Course:Internet & Tools/
Lesson

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 location

For 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 structure

The -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.

02

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.

FlagWhat it doesWhen to use it
-rRecursive (copy directories)Always needed for folders
-iInteractive (ask before overwrite)Safety when files might exist
-vVerbose (show what is happening)Debugging or confirmation
-pPreserve attributesBackup scenarios
03

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)
04

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)
CommandRisk levelWhat it does
rm file.txtMediumDeletes one file permanently
rm -i file.txtLowAsks for confirmation first
rm -r folder/HighDeletes folder and all contents
rm -rf folder/ExtremeForce deletes without confirmation
AI pitfall
AI assistants suggest 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)
05

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 files

less opens an interactive viewer where you can scroll and search:

KeyAction
Space or fNext page
bPrevious page
/searchtermSearch for text
nNext search result
qQuit
06

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 archive

Selecting 47 specific files by hand is tedious. Selecting them with a pattern is instant.

07

Quick reference

TaskCommandNotes
Create empty filetouch file.txtMultiple: touch a.txt b.txt
Create foldermkdir folderNested: mkdir -p path/to/folder
Copy filecp source destUse -r for directories
Move/renamemv source destWorks for files and directories
Delete filerm filePermanent, no undo
Delete folderrm -r folder/Recursive deletion
View filecat file.txtSmall files only
Browse large fileless file.txtInteractive viewer
Watch logtail -f log.txtReal-time updates