In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use mkdir, tar and kill commands in Linux. It is very detailed and has a certain reference value. Friends who are interested must finish it!
1. Suppose you want to create a long / complex directory tree similar to the one below. What is the most effective way to achieve this?
Similar to the directory tree structure to be implemented below.
$cd / home/$USER/Desktop$ mkdir tecmint$ mkdir tecmint/etc$ mkdir tecmint/lib$ mkdir tecmint/usr$ mkdir tecmint/bin$ mkdir tecmint/tmp$ mkdir tecmint/opt$ mkdir tecmint/var$ mkdir tecmint/etc/x1 $mkdir tecmint/usr/x2 $mkdir tecmint/usr/x3 $mkdir tecmint/tmp/Y1 $mkdir tecmint/tmp/Y2 $mkdir tecmint/tmp/Y3 $mkdir tecmint/tmp/Y3/z
This can be done simply by running the following command.
$mkdir-p / home/$USER/Desktop/tecmint/ {etc/x1,lib,usr/ {x2jue x3}, bin,tmp/ {Y1recoveryY2meme Y3compz}, opt,var}
You can verify it with the tree command. If it is not installed, you can use apt or yum to install the 'tree' package.
$tree tecmint
Check the directory structure
We can create any complex directory tree structure in the above way. Note that this is just a normal command, but use'{}'to create a hierarchical directory. It is very useful if you use it in shell scripts when needed.
two。 Create a file (for example, test) on the desktop (/ home/$USER/Desktop) and fill in the following. ABCDEFGHIJKLMNOPQRSTUVWXYZ
What would an ordinary user do in such a situation?
a. He will first create the file, preferably using the touch command, for example:
$touch / home/$USER/Desktop/test
b. He opens the file with a text editor, which could be nano, vim, or some other editor.
$nano / home/$USER/Desktop/test
c. Then he will input the above into the file, save and exit.
Ignoring the time he / she uses, he needs at least 3 steps to implement the above situation.
What would an experienced Linux user do? He will type the following text into the terminal and then complete all the tasks. He doesn't have to perform every step alone.
Cat / home/$USER/Desktop/testABCDEFGHIJKLMNOPQRSTUVWXYZEOF
You can use the 'cat' command to check whether the file and content have been created successfully.
$cat / home/avi/Desktop/test
Check the contents of the file
3. We often work with archived files (especially TAR packages) in Linux. In many cases, we use the TAR package in some location rather than in the Downloads directory. What do we do in this situation?
In this case, we usually do two things.
a. Copy / move the tar package to the target location and extract it, for example:
$cp firefox-37.0.2.tar.bz2 / opt/ or $mv firefox-37.0.2.tar.bz2 / opt/
B. cd to the / opt/ directory.
$cd / opt/
c. Extract the tar package.
# tar-jxvf firefox-37.0.2.tar.bz2
We can also use another way.
We can also extract and copy / move the extracted files to the desired target location at the location of the Tar package, for example:
$tar-jxvf firefox-37.0.2.tar.bz2 $cp-R firefox/ / opt/ or $mv firefox/ / opt/
Either way, it takes two steps to complete the task. Professionals can accomplish this task in one step:
$tar-jxvf firefox-37.0.2.tar.bz2-C / opt/
The-C option extracts the file to the specified directory (in this case / opt/).
It's not about the option (- C), it's about habit. Get into the habit of using the tar command with the-C option. This will make your job easier. Instead of moving archived files or copying / moving unzipped files from now on, save the tar package in the Downloads folder and unzip it wherever you want.
4. How do we kill a process in the conventional way?
In the most common way, we first list all processes with the ps-A command, and then pipe into grep to find the processes / services (if apache2), as follows:
$ps-A | grep-I apache2
Output sample
1006? 00:00:00 apache2 2702? 00:00:00 apache2 2703? 00:00:00 apache2 2704? 00:00:00 apache2 2705? 00:00:00 apache2 2706? 00:00:00 apache2 2707? 00:00:00 apache2
The above output shows all the processes running apache2 and their PID, and then you can use these PID to kill apache2 with the help of the following command.
# kill 1006 2702 2703 2704 2705 2706 2707
Then cross-check to see if there are any processes / services with the name 'apache2'' running, as follows:
$ps-A | grep-I apache2
We can actually do this in a way that is easier to understand using tools like pgrep and pkill. You can use pgrep to find information about a process. If you are looking for process information related to apache2, you just need to run:
$pgrep apache2
Output sample
15396154001540115402154031540415405
You can also list the process name and pid by running the following command.
$pgrep-l apache2
Output sample
15396 apache215400 apache215401 apache215402 apache215403 apache215404 apache215405 apache2
Killing the process with pkill is very simple. You just need to enter the name of the resource you want to kill. I wrote a blog post about pkill, you can refer to: http://www.tecmint.com/how-to-kill-a-process-in-linux/.
To kill a process (such as apache2) with pkill, you only need to enter the following command:
# pkill apache2
You can verify that you killed apache2 by running the following command.
$pgrep-l apache2
It doesn't output anything and returns to the window means that no process with an apache2 in its name is running.
The above is all the contents of the article "how to use mkdir, tar and kill commands in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.