LINUX COMMANDS PART 2
CAT COMMAND
Use of this command:
- cat displays the contents in the file
- cat used to create a file (not folder) also used to append the content of a file
1) To create the new file in current directory :
cat > prwa.txt
Then, add your contents in it,
Example:
This is the training institution
which is located in banglore and pune.
To return to the same directory
Ctrl+d
To check whether the content is created or not
ls
a.txt btm c.txt layout megha.txt poi prwa.txt
or to see in detail
ls –ltr
To display the same content
cat prwa.txt
This is the training institution
which is located in banglore and pune.
or
nl prwa.txt
1 This is the training institution.
2 which is located in banglore and pune.
3) In case If you want append the above content then,
cat >> prwa.txt
hen add your content
we mainly focused on Datascience , BigData , Google colud.
ctrl+d
To see the all content
cat prwa.txt
To check the number (n) of lines in the content:
cat -n prwa.txt
1 This is the training institution.
2 which is located in banglore and pune.
3 we mainly focused on Datascience , BigData and Google cloud.
5) To neglect the blank (b) spaces and numbering the remaining lines
cat -b prwa.txt
1 This is the training institution.
2 which is located in banglore and pune.
3 we mainly focused on Datascience , BigData and Google cloud.
4 thank you
6) To drop all the contents of a file
cat prwa.txt > prwa.txt
File will be empty
7) To create empty file
Data.txt
Where Data.txt is file name.
To check the size of the file, it will be zero
8) To end (e) the content line with $ symbol
cat -e prwa.txt
This is the training institution.$
which is located in banglore and pune.$
we mainly focused on Datascience , BigData and Google cloud.$
thank you$
9) To copy one file content to another file
prwa.txt > new.txt
where, new.txt is newly created file
user@ubuntu:~/Desktop$ cat prwa.txt
This is the training institution.
which is located in banglore and pune.
we mainly focused on Datascience , BigData and Google cloud.
thank you
user@ubuntu:~/Desktop$ cat new.txt
This is the training institution.
which is located in banglore and pune.
we mainly focused on Datascience , BigData and Google cloud.
thank you
10). To append the one file content with another file content
cat > start.txt
welcome to prwatech
ctrl+d
now I want attach start.txt file content with prwa.txt file
cat prwa.txt >> start.txt
cat start.txt
welcome to prwatech
This is the training institution.
which is located in banglore and pune.
we mainly focused on Datascience , BigData and Google cloud.
thank you
To add one or more file to new file
cat > p.txt 1 2 3 Clt+d cat > q.txt 4 5 6 Clt+d cat > r.txt 7 8 9 Clt+d
Check the size of the file after creation and after appending with 2 or more files
It will be p.txt + q.txt + r.txt =w.txt
Then
cat p.txt q.txt r.txt > w.txt cat w.txt 1 2 3 4 5 6 7 8 9
MKDIR COMMAND:
- mkdir is a command to create directory
- To create the directory
Mkdir prwatech
To check the created directory
ls
To create simultaneously directory
mkdir delhi hyderbad kerala
- To create the folder in directory without going inide it
mkdir prwatech/office
let’s see office directory in prwatech directory
cd prwatech
- same way lets create two or more folders in side office in single command
mkdir office/first floor office/ second floor
mkdir: cannot create directory ‘office/’: File exists
mkdir: cannot create directory ‘floor’: File exists
this because there should not be any space between directory name(first..floor)
mkdir office/firstfloor office/secondfloor
check the current root
pwd
/home/user/Desktop/prwatech
Currently we are in prwatech directory
let’s check directories in prwatech
ls
office
let’s go inside the office directory
cd office
and check directories in office
ls
firstfloor secondfloor
-
if we don’t need any msg after creating the directory then,
before this check the path
pwd
/home/user/Desktop/prwatech/office
let’s come back to prwatech directory
So, cd ..
Now check path
pwd
Ok we are in prwatech
/home/user/Desktop/prwatech
Now we will create good as directory in prwatech
mkdir -p good or mkdir -pv good
Here there will no message after creating good directory
To check current directories in prwatech
ls
good office
Now we will create one more bad as directory
mkdir -v bad or mkdir -vp bad
mkdir: created directory ‘bad’
This message will pop up
Now check the directories
ls
bad good office
- now you want to give permission before modifying
mkdir -m421 week
To check the directories
ls
bad good office week
let’s see in detail
ls -ltr
total 16
drwxr-xr-x 4 user user 4096 Dec 30 06:48 office
drwxr-xr-x 2 user user 4096 Dec 30 07:12 good
drwxr-xr-x 2 user user 4096 Dec 30 07:23 bad
dr—w—x 2 user user 4096 Dec 30 07:30 week
Here you can see the permission column with different code
Now try to go inside the directory week
cd week
bash: cd: week: Permission denied
user@ubuntu:~/Desktop/prwatech$ ls
office
REMOVE(RM) COMMAND
- It is used for remove file or directory.
- To remove the file from the current directory
Command:
rm
Before:
a.txt c.txt d.txt hyderbad lin poi p.txt r.txt
banglore Data.txt dumy kerala megha.txt prwatech q.txt start.txt
corona.txt delhi numbers.txt layout new.txt prwa.txt rajkumar
Operation :
rm start.txt
Output:
a.txt c.txt d.txt hyderbad lin poi p.txt r.txt
banglore Data.txt dumy kerala megha.txt prwatech q.txt
corona.txt delhi numbers.txt layout new.txt prwa.txt rajkumar
there is no start.txt file in the Desktop directory
- To ask YES or NO permission(i) before removing the file.
Command:
rm -i
Operation:
rm -i numbers.txt
message will be pop up
rm: remove regular file ‘numbers.txt’?
just type yes
To deny the remove permission
Operation:
rm -i megha.txt
Message will be pop up
rm: remove regular file ‘megha.txt’?
Say no
Output:
a.txt c.txt d.txt kerala megha.txt prwatech q.txt
banglore Data.txt dumy layout new.txt prwa.txt rajkumar
corona.txt delhi hyderbad lin poi p.txt r.txt
- NOTE: IF YOU WANT TO SEE WEATHER IT IS FILE OR DIRECTORY, WHITE COLOR OBJECTS ARE FILE AND BLUE COLOR OBJECTS ARE DIRCTORY
- To remove file completely
Command:
rm -rf
Operation:
rm -rf megha.txt or rm -f megha.txt
Before:
a.txt c.txt d.txt kerala megha.txt prwatech q.txt
banglore Data.txt dumy layout new.txt prwa.txt rajkumar
corona.txt delhi hyderbad lin poi p.txt r.txt
Output:
a.txt corona.txt Data.txt d.txt hyderbad layout new.txt prwatech p.txt rajkumar
banglore c.txt delhi dumy kerala lin poi prwa.txt q.txt r.txt
NOTE:
- we can’t open directory using cat command, to open command we have to use cd <name>
Operation:
cat rajkumar
output:
cat: rajkumar: Is a directory
- we can remove directory use rm command
Operation:
rm rajkumar
output:
rm: cannot remove ‘rajkumar’: Is a directory
- To remove directory completely
Command:
rm -r
Operation:
rm -r rajkumar
Before:
a.txt corona.txt Data.txt d.txt hyderbad layout new.txt prwatech p.txt rajkumar
banglore c.txt delhi dumy kerala lin poi prwa.txt q.txt r.txt
Output:
a.txt corona.txt Data.txt d.txt hyderbad layout new.txt prwatech p.txt r.txt
banglore c.txt delhi dumy kerala lin poi prwa.txt q.txt
- To remove directory forcefully(in some case the directory is not deleting use this)
careful while using this command it will delete forcefully
now we will remove kerala directory
Command:
rm -rf
rm -rf kerala
a.txt corona.txt Data.txt d.txt hyderbad layout new.txt prwatech p.txt r.txt
banglore c.txt delhi dumy kerala lin poi prwa.txt q.txt
Output:
a.txt corona.txt Data.txt d.txt layout new.txt prwatech p.txt r.txt
banglore c.txt delhi dumy lin poi prwa.txt q.txt
- To remove all any extension
Operation:
rm *.txt
Before:
x x.txt y y.txt z z.txt
Output:
x y z
- To remove the all the objects from the directory
Operation:
rm *
Before:
bye.txt hello.txt x y z
Output:
x y z
You may get error saying that
rm: cannot remove ‘x’: Is a directory
#rm: cannot remove ‘y’: Is a directory
rm: cannot remove ‘z’: Is a directory
Caution: if you type rm –r you may get error be careful with syntax or command, Linux is case sensitive.
rm: missing operand
Try ‘rm –help’ for more information.