Progress: 0/62 (0%)

✂️ Creating, Copying, Moving, Deleting

Creating, Copying, Moving, Deleting Files

Now that you know how to view files, it's time to learn how to manage them — creating new files, copying them for backup, moving or renaming them, and cleaning up by deleting. These are the essential file operations you'll use every day in Linux.

touch — Creating New Files

The touch command is primarily used to create empty files quickly. It can also update the timestamp of an existing file, but we'll focus on creating files for now. Think of it like grabbing a blank notebook and putting it on your desk — ready to write in.

Basic usage
touch filename.txt
📌 Example:
touch notes.txt

✅ This creates an empty file called notes.txt in your current directory.

Create multiple files at once
touch file1.txt file2.txt file3.txt

Creates 3 empty files in one command. Super handy when you're starting a project and need multiple placeholders.

Update file timestamp

If the file already exists, touch will update its last modified time:

touch notes.txt

This doesn't change the content — just the "last edited" timestamp.

cp — Copying Files and Directories

The cp command is used to make copies of files or directories. Think of it like photocopying a document — the original stays, and you get a duplicate to work with.

Basic usage
cp source_file destination_file
📌 Example:
cp notes.txt backup_notes.txt
  • notes.txt stays intact
  • backup_notes.txt is the new copy
Copying multiple files
cp file1.txt file2.txt backup_folder/

Copies both file1.txt and file2.txt into backup_folder.

Note: The folder must exist beforehand.

Copying directories (-r)

To copy entire folders, use -r (recursive):

cp -r Projects/ Projects_backup/

Projects/ folder and all its contents are copied to Projects_backup/.

Overwrite confirmation (-i)

If the destination file exists, you can ask Linux to prompt before overwriting:

cp -i notes.txt backup_notes.txt

It will ask "overwrite? y/n" before replacing the file.

mv — Moving or Renaming Files

The mv command is like the "cut & paste" or "rename" tool in Linux. It can move files/folders to a new location or rename them in the same directory. Think of it like reorganizing your desk: moving a notebook to a drawer, or renaming it so it's easier to find.

Moving a file
mv filename.txt /path/to/destination/
📌 Example:
mv notes.txt Documents/

Moves notes.txt into the Documents folder. The file no longer exists in the original location.

Renaming a file

You can rename a file by giving a new name in the same location:

mv oldname.txt newname.txt
📌 Example:
mv notes.txt class_notes.txt

notes.txt is now renamed to class_notes.txt.

Move multiple files
mv file1.txt file2.txt /path/to/folder/

Moves both files into the target folder.

Overwrite confirmation (-i)

Like cp, you can ask Linux to prompt before overwriting:

mv -i notes.txt Documents/

It will ask "overwrite? y/n" if the destination has the same filename.

rm — Deleting Files and Directories

The rm command is used to delete files or directories. Think of it as throwing something in the trash — but in Linux, it permanently deletes unless you take extra care.

Delete a file
rm filename.txt
📌 Example:
rm notes.txt

notes.txt is permanently removed from your directory.

Delete multiple files
rm file1.txt file2.txt

Deletes both files at once.

Delete directories (-r)

To delete a folder and all its contents, use -r (recursive):

rm -r Projects/

Deletes Projects/ and everything inside it.

Ask before deleting (-i)

You can make Linux confirm before deleting:

rm -i notes.txt

It will ask "remove file? y/n" before deletion.

Force delete (-f) ⚠️ DANGEROUS

To ignore warnings and delete without confirmation:

rm -rf OldProjects/

⚠️ Be careful — this is dangerous. It will permanently delete everything in OldProjects/ without asking.

Real-life analogies

touch = Grabbing a blank notebook and placing it on your desk — ready to write in

cp = Making photocopies — you keep the original safe and work on the copy

mv = Reorganizing your desk — moving notebooks to drawers or renaming them for clarity

rm file.txt = Throwing a single paper in the trash

rm -r folder/ = Dumping a whole box of files

rm -rf folder/ = Nuclear option — makes sure nothing is left behind