Day 3 Task: Basic Linux Commands

Day 3 Task: Basic Linux Commands

Table of contents

No heading

No headings in the article.

#Task1: To view what's written in a file:

To view the contents of a file, we can use the cat command. For example, if we have a file named test.txt

ubuntu@hostip$ cat >test.txt 
hey this is test file
ubuntu@hostip$ ls
test.txt
ubuntu@hostip$ cat test.txt
hey this is test file
ubuntu@hostip$

#Task2: To change the access permissions of files:

To change the access permissions of files in Linux, you can use the chmod command. The chmod command allows you to modify the read (r), write (w), and execute (x) permissions for the owner, group, and others.

The general syntax for the chmod command is as follows:

chmod [permissions] filename

Here's an overview of the various ways to modify permissions:

Numeric Mode:

Each permission (read, write, execute) is assigned a numeric value: read (4), write (2), execute (1).

The sum of the values represents the desired permission. For example, read and write (4+2=6).

The command format is:

chmod [numeric value] filename

Example: To give read and write permissions to the owner, and read-only permissions to the group and others:

chmod 400 filename

#Task3: Linux command to check which commands you have run till now.

This command is used to check the history.

history
cat test.txt
cat >test.txt
ls
cat test.txt
ls -l
chmod 400 test.txt

#Task4: Linux command to remove a directory/ Folder.

To remove a directory or folder, we can use the rmdir or rm command. The rmdir command is used specifically to remove empty directories, while the rm command can be used to remove directories with contents and files.

ls
datafile
rmdir datafile

#Task5: Linux command to create a fruits.txt file and to view the content.

The cat command is used to create the file and show the file content.

cat >fruits.txt
cat fruits.txt

#Task6: Linux command to add content in fruits.txt (One in each line) — Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

we are going to add content in fruits.txt file by using vim editor

ls
fruits.txt
vi fruits.txt 
instert i 
Apple 
Mango 
Banana 
Cherry 
Kiwi 
Orange
Guava
esc :wq

#Task7: Linux command to show only the top three fruits from the file.

To show only the first three fruits we will use head command with -n option

head -3 fruits.txt
Apple 
Mango 
Banana

#Task8: Linux command to show only the bottom three fruits from the file.

To show only the bottom three fruits we will use tail command with -n option

tail -3 fruits.txt
Kiwi 
Orange
Guava

#Task9: To create another file Colors.txt and to view the content.

We are going to use the touch command to create the file and the cat command to view the content of the file

touch colors.txt
cat colors.txt

#Task10: Add content in Colors.txt (One in each line) — Red, Pink, White, Black, Blue, Orange, Purple, Grey.

To add content to the Colors.txt file we can use the vim command.

vim colors.txt
Press i(insert)
Red
Pink
White
Black
Blue
Esc(escape)
:wq(write and quit that file)

#Task11: To find the difference between the fruits.txt and Colors.txt files.

To find the difference between the content of two files we can use the diff command.

diff fruits.txt Colors.txt

Thank you for reading!

Contact me at :

linkedin: https://www.linkedin.com/in/sutish-pradhan/

E-mail: psutish@gmail.com