Basic Linux Commands (Part-2)

Task: What is the Linux command to
To view what's written in a file?
cat: The "cat" command in Linux is short for "concatenate," and it is used to display the contents of a file in the terminal window. It can also be used to create, copy, and concatenate files.

To create a file and add data in the file use: cat > pratibha.txt
After adding data press ctrl+d
To display the contents of a file: cat pratibha.txt
To change the access permissions of files.
chmod: The "chmod" command in Linux is used to change the permissions of files or directories. It stands for "change mode" and it is a command-line utility that allows you to specify who can read, write, or execute a file or directory.

In the above image we can see that after executing chmod o+w pratibha.txt
the permissions of the file got changed previously for other users only read permission was given but after executing chmod o+w pratibha.txt Read and Write both the permissions are given.
with chmod o-w pratibha.txt : we can take back the permission
To check which commands you have run till now?
Ans:- history command is used to display the history of the commands executed by the user.

To remove a directory/ Folder.
rmdir: The "rmdir" command in Linux is used to remove an empty directory. It stands for "remove directory" and it is a command-line utility that allows you to delete directories that do not contain any files or subdirectories

We can see in the above image that after executing rmdir pratii command the pratii directory was removed
To create a fruits.txt file and to view the content.
touch: The "touch" command in Linux is used to create a new file or update the access and modification timestamps of an existing file. It is a simple command-line utility that is often used to create empty files or update the timestamp of a file.
Cat : to view content in the file

Add content in devops.txt (One in each line) - Guava,Mango, Banana, Cherry, Kiwi, Orange,Guava,Apple)
echo: The "echo" command in Linux is used to display text on the terminal. It is a simple command-line utility that allows you to print messages or variables to the screen

To Show only the top three fruits from the file.
head: The "head" command in Linux is used to display the first few lines of a file. It is a command-line utility that allows you to quickly view the beginning of a file without opening it in a text editor.
Ans:-
head -n 3 devops.txt
Show only the bottom three fruits from the file.
tail: The "tail" command in Linux is used to display the last few lines of a file. It is a command-line utility that allows you to quickly view the end of a file without opening it in a text editor.
Ans:-
tail -n 3 devops.txt
To create another file Colors.txt and to view the content.
touch: The "touch" command in Linux is used to create a new file or update the access and modification timestamps of an existing file. It is a simple command-line utility that is often used to create empty files or update the timestamp of a file.
Ans:-
touch Colors.txt"cat colors.txt"
Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.
Ans:-
nano Colors.txtRedPinkWhiteBlackBlueOrangePurpleGreyOnce you have added all the lines, save the file by pressing
Ctrl+Oand then exit the editor by pressingCtrl+Xcat Colors.txtTo find the difference between fruits.txt and Colors.txt file.
diff: The "diff" command in Linux is used to compare the contents of two files and display the differences between them. It is a command-line utility that is commonly used by programmers and system administrators to identify changes made to files, such as configuration files, scripts, or source code.
diff fruits.txt Colors.txtThanks For Reading!
Pratibha Yedle


