We have been doing a task in the usual way until we know there is a better way to handle it. As a follow-up to the Linux tips and tricks series, I'm here to introduce four tips that can help you in every aspect. let's start!
4 useful Linux tips
1. Suppose you want to create a directory tree that looks like the long/complex 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/zThe above can be achieved simply by running the following line of commands.
$ mkdir -p /home/$USER/Desktop/tecmint/{etc/x1,lib,usr/{x2,x3},bin,tmp/{Y1,Y2,Y3/z},opt ,var}You can verify with the tree command. If it is not installed you can use apt or yum to install the ‘tree’ package.
$ tree tecmint
Check directory structure
We can create arbitrarily complex directory tree structures in the above way. Note that this is just a normal command, but use ‘{}& rsquo; to create a hierarchical directory. It is very useful if you use it in a shell script when needed.
2. Create a file (eg test) on the desktop (/home/$USER/Desktop) and fill in the following.
ABCDEFGHIJKLMNOPQRSTUVWXYZWhat would an ordinary user do in this situation?
a. He will first create the file, preferably using the touch command, for example:
$ touch /home/$USER/Desktop/testb. He will edit with a text Open the file, this may be nano, vim or other editor.
$ nano /home/$USER/Desktop/testc. Then he will type the above into the file, save and exit.
Ignore the time he/she uses, he needs at least 3 steps to perform the above situation.
What does an experienced Linux user do? He will type the following text in the terminal and complete all tasks. He does not need to perform each step alone.
cat << EOF > /home/$USER/Desktop/testABCDEFGHIJKLMNOPQRSTUVWXYZEOFYou can use the ‘cat’ command to check if the file and content were successfully created.
$ cat /home/avi/Desktop/test
Checking the contents of the file
3. We often process archives in Linux (especially TAR packages) . In many cases we will use the TAR package in some locations instead of in the Downloads directory. What do we do in this situation?
In this case we usually do two things.
a. Copy/move the tarball 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. Unzip the tar package.
# tar -jxvf firefox-37.0.2.tar.bz2We can also use another method.
We can also extract and copy/move the decompressed files to the desired destination in 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. Professional people can do this in one step:
$ tar -jxvf firefox-37.0.2.tar.bz2 -C /opt/-C option to extract files to the specified directory (here /opt/).
This is not a question about options (-C), but a matter of habit. Develop the habit of using the -C option tar command. This will make your work easier. From now on, don't move the archive or copy/move the unzipped files. Save the tarball in the Downloads folder and unzip it wherever you want.
4. Regular way How do we kill a process?
The most common method, we first list all processes with the ps -A command, and then pipe into grep to find the process /service (if apache2), as follows:
$ ps - A | Grep -i apache2Output 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 apache2The above output shows all the processes running apache2 and their PIDs, then you can use these PIDs in the following command With the help of kill apache2.
# kill 1006 2702 2703 2704 2705 2706 2707Then cross check to see if there are processes/services with ‘apache2’ in the name running, as follows:
$ ps -A | Grep -i apache2In fact, we can use tools like pgrep and pkill to implement in a more understandable way. You can use pgrep to find information about a process. If you are looking for process information related to apache2, you only need to run:
$ pgrep apache2Output sample
15396154001540115402154031540415405You can also list by running the following command Process name and pid.
$ pgrep -l apache2Output sample
15396 apache215400 apache215401 apache215402 apache215403 apache215404 apache215405 apache2It is very simple to kill the process with pkill. You only need to enter the name of the resource you want to kill. I wrote a blog post about pkill, which you can refer to: http://www.tecmint.com/how-to-kill-a-process-in-linux/.
To kill a process with pkill (for example, apache2), you only need to enter the following command:
# pkill apache2You can verify that apache2 is killed by running the following command.
$ pgrep -l apache2It doesn't output anything and returns to the window means that no process with apache2 in its name is running.
Basic Concepts Virtualization allows multiple virtual machines with different operating systems to
Mono is a cross-platform, open source .NET development framework. Support for Linux systems, which
At present, many schools have built campus networks and connected to the Internet, but there are so
Nginx starts with version 0.7.48 and supports Squid-like caching. This cache uses the URL and relate
Linux is a very useful command to find the software installation directory
Linux vps how to modify the time zone linux vps time zone setting
Linux under the dual network card configuration basic tutorial
Linux cluster load balancing introduction
Detailed analysis of kernel module development under Linux operating system
Linux regularly performs tasks. Implementation Tutorial
Setting up the Linux system time server in the LAN
Installing two Linux operating systems on one hard disk
Win7 system locks the computer screen graphic tutorial
Win10 preview version upgrade 9879 detailed steps
Windows 7 Comic Album: Desktop Widget
Microsoft Blog - Learn about the libraries in Windows 7
Windows 7 memory footprint is the reason
Win10 watching video always pops up realtek high definition audio manager how to do?
Win7 system computer how to hide QQ data age and gender
How to install Win8.1? Install the win8.1 tutorial from the hard disk /CD /u disk diagram