๐Ÿง Beginner Linux Training ยท Module 3

File Management

Learn how to create, copy, move, rename, delete, view, and search files using simple Linux commands. This module is designed for first-time Linux users and classroom demonstrations.

$ mkdir project
$ touch app.log
$ echo "Linux training" > app.log
$ cat app.log
Linux training
1

Learning Objectives

๐Ÿ“

Create files

Use commands like touch and echo to create files and add basic content.

๐Ÿ“‹

Copy files

Use cp to create another copy of a file without changing the original.

๐Ÿšš

Move and rename

Use mv both for moving files between directories and renaming files.

๐Ÿ—‘๏ธ

Delete files

Use rm carefully because deleted files are usually not moved to a recycle bin.

๐Ÿ‘€

View content

Use cat, less, head, and tail to read file content.

๐Ÿ”Ž

Search inside files

Use grep to find matching words or lines inside text files.

2

Core Concepts

Beginner idea:

In Linux, most work is done with files and directories. A directory is like a folder. A file can contain text, logs, configuration, scripts, or application data.

File management means controlling files: creating, reading, copying, moving, renaming, searching, and deleting them.

ActionCommandSimple meaning
Create empty filetouch file.txtCreate a new blank file or update timestamp.
Add textecho "text" > file.txtWrite text into a file.
Copycp source targetMake a duplicate file.
Move / Renamemv old newMove or rename a file.
Deleterm file.txtRemove a file permanently.
Searchgrep "word" file.txtFind lines containing a word.
3

Command Reference

๐Ÿ“

Create a directory

mkdir creates a new directory.

Command
mkdir project
๐Ÿ“„

Create an empty file

touch creates a file if it does not exist.

Command
touch app.log
โœ๏ธ

Write text to a file

> writes output into a file. It replaces old content.

Command
echo "Linux training" > app.log
๐Ÿ‘๏ธ

View file content

cat prints the complete file content on screen.

Command
cat app.log
๐Ÿงฌ

Copy a file

cp copies content from source file to destination file.

Command
cp app.log backup.log
๐Ÿท๏ธ

Rename a file

mv can rename a file when source and destination are in the same directory.

Command
mv backup.log old.log
๐Ÿงญ

Move a file

mv can also move a file into another directory.

Command
mv app.log project/
๐Ÿงน

Delete a file

rm deletes a file. Use it carefully.

Command
rm old.log
๐Ÿ”

Search inside a file

grep prints lines that match a search word or pattern.

Command
grep "Linux" app.log
4

Important Notes for Beginners

Be careful with delete commands

rm file usually deletes the file permanently from the command line. There may be no recycle bin.

Avoid running rm -rf unless you clearly understand the path and impact.

Redirection symbols

> overwrites file content.

>> appends new content at the end of the file without removing existing content.

Example
echo "Second line" >> app.log
5

Hands-on Lab: File Management

Run the following commands in a Linux terminal. The goal is to create a project folder, create a log file, add text, view it, copy it, rename the copy, and delete the renamed file.

Create a project directory

This creates a folder named project.

Lab command
mkdir project

Create an empty log file

This creates app.log in the current directory.

Lab command
touch app.log

Write text into the file

This writes Linux training into app.log.

Lab command
echo "Linux training" > app.log

View file content

This displays the content of app.log.

Lab command
cat app.log

Copy the file

This creates a second file named backup.log with the same content.

Lab command
cp app.log backup.log

Rename the copied file

This renames backup.log to old.log.

Lab command
mv backup.log old.log

Delete the renamed file

This removes old.log.

Lab command
rm old.log
Complete lab script
mkdir project
touch app.log
echo "Linux training" > app.log
cat app.log
cp app.log backup.log
mv backup.log old.log
rm old.log
6

Practice Checks

What command creates an empty file named notes.txt?

touch notes.txt

Which command copies app.log to backup.log?

cp app.log backup.log

Which command renames backup.log to old.log?

mv backup.log old.log

Which command searches for the word Linux inside app.log?

grep "Linux" app.log

What is the difference between > and >>?

> overwrites file content. >> appends content to the end of the file.

7

Module Summary

NeedUse this commandExample
Create directorymkdirmkdir project
Create filetouchtouch app.log
Add textecho with >echo "Linux training" > app.log
View filecatcat app.log
Copy filecpcp app.log backup.log
Rename filemvmv backup.log old.log
Delete filermrm old.log
Search textgrepgrep "Linux" app.log