0% found this document useful (0 votes)
7 views2 pages

Exercise 3 LINUX

Uploaded by

balvirparilok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Exercise 3 LINUX

Uploaded by

balvirparilok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise 3: File Management

Task 1: Create, Move, Copy, and Delete Files and Directories

Objective: To practice basic file and directory operations in Linux.

Steps:

Step 1: Create Files and Directories

• Use the ‘mkdir‘ command to create a new directory:

1 mkdir my_directory

• Use the ‘touch‘ command to create a new file:

1 touch my_file.txt

Step 2: Move and Rename Files and Directories

• Use the ‘mv‘ command to move a file or directory to a new location or rename it:

1 mv my_file.txt my_directory/

2 mv oldname.txt newname.txt

Step 3: Copy Files and Directories

• Use the ‘cp‘ command to copy files or directories:

1 cp my_file.txt my_directory/

2 cp-r my_directory/ my_backup/

Step 4: Delete Files and Directories

• Use the ‘rm‘ command to remove files:

1 rm my_file.txt

• Use ‘rm-r‘ to remove directories and their contents:

1 rm-r my_directory/

Task 2: Organize Files into Directories and Subdirectories

Objective: To structure files in a hierarchical manner for better organization.

Steps:
Step 1: Create Directories and Subdirectories

• Use the ‘mkdir‘ command with the ‘-p‘ option to create directories and subdirectories:

1 mkdir-p parent_directory/child_directory/grandchild_directory

Step 2: Move Files into Directories

• Move files into the newly created directories:

1 mv file1.txt parent_directory/

2 mv file2.txt parent_directory/child_directory/

Step 3: Verify Directory Structure

• List the contents of the directories to ensure files are organized correctly:

1 ls-R parent_directory/

Task 3: Search for Files and Content Within Files

Objective: To find files and search for content within files using various commands.

Steps:

Step 1: Search for Files Using ‘find‘

• Use the ‘find‘ command to locate files:

1 find /path/to/search-name "filename.txt"

2 find .-type f-name "*.txt" # Search for all .txt files in the current directory and

subdirectories

Step 2: Locate Files Using ‘locate‘

• Use the ‘locate‘ command to quickly find files:

1 locate filename.txt

Step 3: Search for Content Within Files Using ‘grep‘

• Use the ‘grep‘ command to search for specific content within files:

1 grep "search_term" filename.txt

2 grep-r "search_term" /path/to/search/ # Recursively search for content in all files in

a director

You might also like