0% found this document useful (0 votes)
31 views5 pages

Linux Assignment

The document outlines basic file and directory operations in a Linux environment, including creating, renaming, and viewing files, as well as searching for patterns. It also covers zipping and unzipping directories, downloading files, changing file permissions, and working with environment variables. Each section includes command examples and brief explanations of their functions.

Uploaded by

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

Linux Assignment

The document outlines basic file and directory operations in a Linux environment, including creating, renaming, and viewing files, as well as searching for patterns. It also covers zipping and unzipping directories, downloading files, changing file permissions, and working with environment variables. Each section includes command examples and brief explanations of their functions.

Uploaded by

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

1.

Creating and Renaming Files/Directories

Create a directory named test_dir using mkdir.

Inside test_dir, create an empty file called example.txt.

Rename example.txt to renamed_example.txt using mv


Explanation:​
mkdir test_dir → Creates a directory named test_dir.​

●​ cd test_dir → Moves into that directory.​

●​ touch example.txt → Creates an empty file named example.txt.​

●​ mv example.txt renamed_example.txt → Renames example.txt to


renamed_example.txt.​

2. Viewing File Contents

Use cat to display the contents of /etc/passwd.

Display only the first 5 lines of /etc/passwd using head.Display only the last 5 lines of
/etc/passwd using tail.​

Explanation:

●​ cat /etc/passwd → Displays the full content of /etc/passwd (system


user information file).​

●​ head -n 5 /etc/passwd → Shows the first 5 lines of /etc/passwd.​

●​ tail -n 5 /etc/passwd → Shows the last 5 lines of /etc/passwd.


3.Searching for Patterns

Use grep to find all lines containing the word "root" in /etc/passwd.

Explanation:

●​ grep "root" /etc/passwd → Searches for the word root in


/etc/passwd and displays matching lines.​


4. Zipping and Unzipping Compress the test_dir directory into a file named
test_dir.zip using zip. Unzip test_dir.zip into a new directory named unzipped_dir.​



Explanation:

●​ zip -r test_dir.zip test_dir → Compresses the test_dir directory


into a ZIP file named test_dir.zip.​

○​ -r → Recursively include all files and subdirectories.​

●​ unzip test_dir.zip -d unzipped_dir → Extracts the ZIP file into a


folder named unzipped_dir.

5. Downloading Files
Use wget to download a file from a URL (e.g., https://example.com/sample.txt).


Explanation:

●​ wget → Downloads files from the internet.

6. Changing Permissions
Create a file named secure.txt and change its permissions to read-only for everyone
using chmod.​


Explanation:

●​ touch secure.txt → Creates an empty file.​

●​ chmod 444 secure.txt → Sets permissions to read-only for owner,


group, and others.​

○​ 4 = Read, 2 = Write, 1 = Execute.

7. Working with Environment Variables


Use export to set a new environment variable called MY_VAR with the value "Hello,
Linux!".

Explanation:

●​ export MY_VAR="Hello, Linux!" → Creates an environment variable


named MY_VAR with the value "Hello, Linux!".​

●​ echo $MY_VAR → Displays the value of MY_VAR.

You might also like