Table of contents
- 1. To view what is written in a file :
- 2. To change the access permissions of files:
- 3. To check which commands you have run till now :
- 4. To Remove a directory/folder :
- 5. To create a fruits.txt file and view the content:
- 6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava :
- 7. Show only the top three fruits from the file:
- 8. Show only the bottom three fruits from the file:
- 9. To create another file Colors.txt and view the
- content :
- 10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey :
- 11. To find the difference between the fruits.txt and Colors.txt files:
1. To view what is written in a file :
To view the content of a file we can use the "cat command" like this :
$ cat <filename>
$ cat test.txt
2. To change the access permissions of files:
"chmod" is the command which stands for change mode, used to change the file permissions.
“0” represents “no permission”.
“1” represents “execute permission”.
“2” represents “write permission”.
“4” represents “read permission”.
We can give permissions to the Owner, Group and Others of a file. So if I want to give all permissions to the Owner, read and execute permissions to the group, and only read permission to others so it will be like this:
$ chmod 754 <filename>
3. To check which commands you have run till now :
To check all previously executed commands we use the "history command"
$ history
4. To Remove a directory/folder :
we use the "rmdir command" to remove a directory,
$ rmdir <directory name>
5. To create a fruits.txt file and view the content:
To create a file we use the touch command and to view the content(if any) of a file we use the cat command :
$ touch fruits.txt
$ cat fruits.txt
6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava :
To do the whole task once at a time we can use the echo command, as it will add the contents and also print the content too.
$ echo "Apple" >> devops.txt
$ echo "Mango" >> devops.txt
$ echo "Banana" >> devops.txt
$ echo "Cherry" >> devops.txt
$ echo "Kiwi" >> devops.txt
$ echo "Orange" >> devops.txt
$ echo "Guava" >> devops.txt
7. Show only the top three fruits from the file:
Use the head command to show the top three from the file as :
$ head -3 <file name>
$ head -3 devops.txt
8. Show only the bottom three fruits from the file:
Use the tail command to show the top three from the file as :
$ tail -3 <file name>
$ tail -3 devops.txt
9. To create another file Colors.txt and view the
content :
To create a file we use the touch command and to view the content(if any) of a file we use the cat command :
$ touch Colors.txt
$ cat Colors.txt
10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, and Grey :
To do the whole task once at a time we can use the echo command, as it will add the contents and also print the content too.
$ echo "Red" >> Colors.txt
$ echo "Pink" >> Colors.txt
$ echo "white" >> Colors.txt
$ echo "Black" >> Colors.txt
$ echo "Blue" >> Colors.txt
$ echo "Orange" >> Colors.txt
$ echo "Purple" >> Colors.txt
$ echo "Grey" >> Colors.txt
11. To find the difference between the fruits.txt and Colors.txt files:
We can use the diff command to check the difference between two files like :
$ diff <filename 1 > <filename 2 >
$ diff <fruits.txt > <Colors.txt>