How to use mkdir, tar and kill commands efficiently in Linux
To use mkdir, tar and kill commands efficiently in Linux
In this tutorial how to use mkdir, tar and kill commands efficiently in Linux command efficiently is illustrated with examples.
Using mkdir create directory tree
[root@linuxhelp Desktop]# mkdir folder
[root@linuxhelp Desktop]# cd folder
[root@linuxhelp folder]# mkdir image
[root@linuxhelp folder]# cd image/
[root@linuxhelp image]# mkdir video
[root@linuxhelp image]# cd video
[root@linuxhelp Desktop]# tree folder
folder
??? image
??? video
2 directories, 0 files
The above method is very long process to create the directory tree.
Create the directory tree efficiently
mkdir with option -p will create the long directory tree in single command.
[root@linuxhelp Desktop]# mkdir -p mydir/dir/a1/b2/c3
[root@linuxhelp Desktop]# tree mydir
mydir
??? dir
??? a1
??? b2
??? c3
4 directories, 0 files
To create and view the files
To create the file use touch command.
[root@linuxhelp Desktop]# touch my.txt
Once the text file is created, add the contents by using editor like vim ,vi ,nano&hellip etc.
[root@linuxhelp Desktop]# vim my.txt
Centos
Redhat
Ubuntu
Now the next step if you want to view your created file by using same editors use the following command.
[root@linuxhelp Desktop]# vim my.txt
So this method also takes some time to create the file and add the contents to that file.
To create the file using cat command
Using cat command it will simple to create the file and also easy view the created file.
[root@linuxhelp Desktop]# cat < < EOF > file.txt
linux
window
To view the content of created files
[root@linuxhelp Desktop]# cat file.txt
linux
window
We often deal with archives on Linux and in several cases we use TAR ball on some location other than the downloads folder.
In such a situation we normally do the following method
First we start copy or move the tar ball and extract it at the destination.
[root@linuxhelp Desktop]# cp folder.tar /root/Documents/ [root@linuxhelp Desktop]# cd ../Documents [root@linuxhelp Documents]# ls folder.tar [root@linuxhelp Documents]# tar -xvf folder.tar folder/ folder/image/ folder/image/video/
So these method will take little longer steps. The below command will overcome this issue.
[root@linuxhelp Desktop]# tar -xvf mydir.tar.gz -C /root/Downloads
mydir/
mydir/music/
mydir/music/s2/
mydir/music/s1/
mydir/dir/
.
.
.
mydir/{number/
mydir/{number/a1/
mydir/{number/a1/b1}/
Option C is used to mention the destination path
[root@linuxhelp Desktop]# cd ../Downloads/
[root@linuxhelp Downloads]# ls
mydir
To kill the process and view the status
Usually we first list all the process using ps -A and pipeline it with grep to find a process or a service:
[root@linuxhelp Desktop]# ps -A | grep -i python
3059 ? 00:00:01 python
Now let us kill the above process id.
[root@linuxhelp Desktop]#kill 3059
[root@linuxhelp Desktop]# ps -A | grep -i python
To view the process details and delete the process
To view the process details and delete the process by using pgrep and pkill commands.
You may find relevant information about a process just by using pgrep. To kill a process, just type pkill followed by the process to kill.
[root@linuxhelp Desktop]# ps -A | grep -i gnote 3032 ? 00:00:01 gnote [root@linuxhelp Desktop]# pgrep gnote 3032 [root@linuxhelp Desktop]# pgrep -l gnote 3032 gnote [root@linuxhelp Desktop]# pkill gnote [root@linuxhelp Desktop]# pgrep -l gnote