In this blog, we will discuss further basic commands that can be utilized to play around in Linux. Along with this, we will discuss a few tasks assigned as part of the #90daysofdevops challenge by Shubham Londhe.
Continuing where we left off, we discussed Listing commands and Directory commands in the previous blog. You can view it here: Linux | Part 1 by Sneha K S.
Some more basic commands
echo
echo <text>
This command helps in providing the standard output.
clear
clear
This command helps in clearing the terminal screen. It just scrolls down and does not delete any history.
File Commands
cp
cp <flag> {filename} /pathname/
This command helps in copying the files and directories. Some of the cp commands with flags are:
cp -i #This command is used to get into interactive mode. CLI asks permission before overwriting.
cp -n #This command does not overwrite
cp -u #This command updates only when destination file is different from source file.
cp -r #This command helps in creating recursive copy for copying dir, also copies hidden files.
cp -v #This command behaves as a verbose. It prints informative messages.
mv
mv <flag> {filename} /pathname/
This command helps in moving files/directories. Once the files are moved, they are deleted from working directory.
rm
rm <flag> {filename}
This removes files from a directory.
rm -r #This command removes non-empty directories.
rm -rp #This command removes non-empty firectories including parent and subdirectories.
grep
grep <flag> {filename}
grep command is used to search a particular string/word in a text file.
grep -i #This command returns the results for case insensitive strings.
grep -n #This command returns matching strings along with their line number.
grep -v #This command returns the results of lines not matching the search string.
grep -c #This command returns number of lines in which results have matched the search string.
cat
cat <flag> {filename}
The cat command is used to read, modify or concatenate text files. This command helps in displaying file contents.
Tasks for today
What is the Linux command to view what's written in a file?
The command used for viewing what's written in a file is the cat command. Syntax: cat <filename>
What is the Linux command to change the access permissions of files?
The chmod command is used to change the access of files and permissions. To change all the read, write and execute permissions 777 is used. Syntax: chmod 777 <foldername>
What is the Linux command to check which commands you have run till now?
The history command is used to display the history of the commands executed by the user. Syntax: history
What is the Linux command to remove a directory/file?
The rm command is used to remove a directory/file. Syntax: rm <filename> #For file, rmdir <foldername> #For Directory
What is the Linux command to create a fruits.txt file and view the content?
To create a fruits.txt file: touch fruits.txt To view the content: cat fruits.txt
Which Linux command to add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.
Using a text editor open the file: vi devops.txt Later add the items one item per line in the editor: Apple Mango Cherry Kiwi Orange Guava Then save and exit the editor using the below command: :wq
Which Linux command is used to show only the top three fruits from the file?
The head command is used to show only the top three fruits from the file: Syntax: head -n 3 devops.txt -n is the flag used to print first those specified number of lines. The output of the command will be: Apple Mango Cherry
Which Linux command is used to show only the bottom three fruits from the file?
The tail command is used to show only the top three fruits from the file: Syntax: tail -n 3 devops.txt -n is the flag used to print first those specified number of lines. The output of the command will be: Kiwi Orange Guava
Which Linux command is used to create another file colors.txt and to view the content?
To create a new file: touch colors.txt To view the content: cat colors.txt
Which Linux command is used to add content in colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey?
Using a text editor open the file: vi colors.txt Later add the items one item per line in the editor: Red Pink White Black Blue Orange Purple Grey Then save and exit the editor using the below command: :wq