As we all know, Shell is the main management tool under Linux operating system. In addition to mastering the commands under the shell, the system administrator also needs to master some special characters. These special characters can help your system administrator combine multiple commands into a single command, or you can make it easier for your system administrator to operate. I will give you a brief introduction to these special characters and related applications.
First, quickly switch between the directories.
In the Linux operating system text mode, switching between directories needs to be done by command. Obviously there is no graphical interface to use the mouse dot so convenient. However, some special characters are still available in the shell. With the help of these characters, the system administrator can easily switch between different directories.
If the system administrator wants to go back to the user's home directory from any directory, is there any quicker way than to go back in the original way? In fact, to return to the user's home directory, there is a very convenient way, is through a special character ~ to complete. Typically, when an administrator creates a user, a folder is created in the system's/home directory with the user's name. The directory in which this folder resides is the user's home directory. When users do not know where they are and need to quickly return to their home directory, you can use this command to implement: CD ~. In other words, the special symbol ~ Represents the user's home directory in the operating system. Because of the different user's home directory, this home directory can be used to quickly return to their home directory.
In the directory switching process, there are two more important special characters, respectively. Symbol. where "." Represents the current directory. This symbol is important and needs to be used in many places. If you define the PATH environment variable, you need to add this. Number at the end of the path, which means the current directory. Also, if the system administrator wants to run a script file in the current directory, such as setup.sh. You can use the./setup.sh instead of an absolute path. One of these. Symbols represent the current directory. You can also use the. number, such as CD./setup, in the CD command to enter the next subdirectory setpup under the current directory. So this special symbol. (The point number in the English state) is useful when switching directories. Another special character is ".." The two-point number in the state of the system represents the previous level of the directory. When an administrator uses the CD command to define a directory and wants to go back to the previous directory, you can use the CD. commands to implement. Note that there is a space between the CD command and the dot number.
If the system administrator can skillfully apply these special characters, especially the symbol of the directory of the head of household, can help the administrator to quickly switch to the directory they want. For example, in a Linux client, the folder for the user's mailbox is kept under the user's home directory. If the user may be using a Thunderbird mail client. The disadvantage of adopting this client is that when the Linux system shuts down illegally, the meeting produces a lock file in the Mail directory. The client will not be able to open it. Only the system administrator needs to switch to the Mail folder in the user's home directory and delete the lock file. At this point the simpler way is to use the ~ symbol to locate the user's home directory, and then into the Mail directory, find the file and delete. This level of access is much faster.
Second, save the results of the execution to a file.
Users may need to save the execution results of some commands to a file in their day-to-day operations. If you need to save some of the running results of some programs to the day to the file and so on. The author now takes a simple example as an example. The PS command is the command used to display the current system's running programs. As on the command line, entering the PS command shows all the programs that are running on the current system (note that the program and process are two different experiences). It displays the application's process number, terminal information, elapsed time, and program name, and so on. Now, how do administrators implement this information if they want to save it to a specific file?
At this point, the system administrator can use a special character, such as PS > Ps.txt, to save the execution results of the command PS to the text file ps.txt after the command. If the destination file does not exist, the system creates the file and saves the information. If the target file exists, the system overwrites the original file. Therefore, you need special attention when you use the > special symbol to create a file. Because the target file exists, the system will not give the user any hint, delete the target file and create a new file with the same name. Inadvertently, this may result in the loss of files. But it also has a twin brother, the >> symbol. This special symbol is similar to the > symbol and also saves the execution results to a file. But there is a big difference between this symbol and the > symbol. If the target file already exists, the two-symbol execution effect is different. If you are using the > symbol, the system will automatically overwrite it. If you use the >> symbol, the system will not overwrite the existing target file, but only in the target file appended to the relevant records. If the destination file does not exist, the destination file is still created automatically.
Because the >> symbol does not automatically overwrite the target file, it simply appends the record to the target file. There are some other special uses for this symbol, such as the use of different files to be merged. As now there are even a file listjpg.txt and listgif.txt. The image names of JPG and GIF are mainly preserved in this two file. Now the user wants to merge the two files, or they want to append the records in Listjpg.txt to the Listgif.txt file. What to do now? Use the command cat Listjpg.txt >> listgif.txt to achieve this function. The meaning of this command is to use the Cat command to read the contents of the file Listjpg.txt and append it to the Listgif.txt file. When this command is executed, two files are merged. But the original document still exists. If you do not need to, you need to manually delete it.
Because the two special symbols function Similarly, there are differences in implementation details. To this end, the system administrator needs to master the differences and choose the appropriate approach in the actual work. As in some setup programs, you need to keep the information in the installation process in a log file. However, during the next reinstallation process, the system administrator may prefer to delete the original log first. Because it will increase the amount of reading. At this point it is reasonable to use the special symbol of >, because it will automatically delete the log file.