Day3: Basic Linux Commands
#90daysofdevops challenge
What is the linux command to:
1)To view what's written in a file:
i)cat
Cat simply prints the content of the file to standard display i.e. your screen.
ii)less
Less command views the file one page at a time.
2)To change the access permissions of files:
The chmod command enables you to change the permissions on a file. You must be superuser or the owner of a file or directory to change its permissions.
In Linux, there are three types of owners: user, group, and others. File permissions fall in three categories: Read, Write, and Execute.
Below is the symbolic representation of permissions to user, group, and others.
we can find permissions of files and folders using long listing "ls -l" on a Linux terminal.
In the output above, d represents a directory and - represents a regular file.
Syntax of chmod:
chmod permissions filename
Permissions can be changed using two modes:
i)Symbolic mode
ii)Absolute mode
examples:
i) chmod u+x file.txt
3)Linux command to check which commands you have run till now.
'history' command is used to check the commands you have run till now.
Ex: history
4)Linux command to remove a directory/ Folder.
To remove an empty directory, use the rmdir command
To remove a directory and all its contents, including any subdirectories and files use: rm
5)Linux command to create a nums.txt file and to view the content.
We are going to use the touch command to create the file and cat command to view the content of the file
touch nums.txt
cat nums.txt
6)Linux command to add content in nums.txt (One in each line) — one, two, three, four, five, six
we are going to add content in num.txt file by using vim editor
vim nums.txt
press i (insert)
one
two
three
four
Esc(escape)
:wq(write and quit that file)
7)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
e.g head -3 nums.txt
8)Linux command to show only the bottom three nums from the file.
To show only the bottom three fruits we will use tail command with -n option
e.g tail -3 nums.txt
9)To create another file colors.txt and to view the content.
We are going to use the touch command to create the file and cat command to view the content of the file
touch colors.txt
10)Add content in colors.txt (One in each line) — Red, Pink, White, Black, Blue, Orange, Purple, Grey.
vim colors.txt
Press i(insert)
Red
Pink
White
Black
Blue
Esc(escape)
:wq(write and quit that file)
11)To find the difference between the nums.txt and colors.txt files.
To find the difference between the content of two files we can use the diff command.
eg:- diff nums.txt colors.txt
Thanks for reading!! Hope you find this article helpful!
Sanjana :)