Table of contents
- Basic Linux Commands
- 1. To View What's 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 to View the Content:
- 6.To Add Content in devops.txt (One in Each Line):
- 7.To Show Only Top Three Fruits from the File:
- 8.To Show Only the Bottom Three Fruits from the File:
- 9.To Create Another File Colors.txt and to View the Content:
Basic Linux Commands
1. To View What's Written in a File:
The cat
command is used to display the contents of a file on the terminal. For example, to view the contents of a file named fruits.txt
, run the following command:
cat fruits.txt
2.To Change the Access Permissions of Files:
The chmod
command is used to change the access permissions of files. For example, to give the owner of a file read, write, and execute permissions and everyone else only read and execute permissions, run the following command:
chmod 755 filename
3.To Check Which Commands You Have Run Till Now:
The history
command is used to show a list of all the commands you have run in the current terminal session. For example:
history
4.To Remove a Directory/Folder:
The rmdir
command is used to remove an empty directory or folder. For example, to remove a directory named saurabh
, run the following command:
rmdir saurabh
5.To Create a Fruits.txt File and to View the Content:
The touch
command is used to create a new file. For example, to create a file named fruits.txt
, run the following command
touch fruits.txt
You can use the cat
command to view the contents of the newly created file:
cat fruits.txt
6.To Add Content in devops.txt (One in Each Line):
The echo
command is used to add content to a file. For example, to add the words "Apple", "Mango", "Banana", "Cherry", "Kiwi", "Orange", and "Guava" to the file named devops.txt
, one on each line, run the following commands:
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.To Show Only Top Three Fruits from the File:
The head
command is used to display the first few lines of a file. For example, to show only the top three fruits from the devops.txt
file, run the following command:
head -n 3 devops.txt
8.To Show Only the Bottom Three Fruits from the File:
The tail
command is used to display the last few lines of a file. For example, to show only the bottom three fruits from the devops.txt
file, run the following command:
tail -n 3 devops.txt
9.To Create Another File Colors.txt and to View the Content:
You can create another file named Colors.txt
using the touch
command:
touch Colors.txt
To view the contents of the newly created file, use the cat
command:
cat Colors.txt
To Add Content in Colors.txt (One in Each Line)
Use the echo
command to add the words "Red", "Pink", "White", "Black", "