Command-oriented commands for Unix systems in one go

Source: Internet
Author: User
Article Title: Command-oriented Unix system commands in one go. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In Unix, there is a very practical function, namely the command-oriented function. Simply put, command-oriented means connecting several separate commands with the guiding symbols. In this case, System Engineers can combine these independent commands to achieve each specific purpose without executing certain commands in the distribution.

The ls,>, and wc commands are used to count the number of specific files in a folder. In this case, you can use the command-oriented function to combine the three commands into one ls | wc command. For example, there are more than 80 folders under the user folder/mnt/share. But now the system engineer needs to know the exact number of folders and files in the share folder. What should I do? If you want to deploy data one by one, you can also. However, this method is a waste of time and is easy to count incorrectly. To achieve this goal, we can use several related commands.

 First Command: file LIST Command ls.

In the Window system, you can use the dir command to display the folder and file information under a specific directory. In fact, there are similar commands in Unix systems, such as ls file list commands. However, this command is more powerful than the dir command. For example, if the-l parameter is added after the ls command, the permission information of each folder and file can be displayed. The dir command does not have this function. The ls command can be used to list objects in a specific directory. If the system engineer wants to view the file and Folder Information under file Jia share, he can first locate the folder and then use the ls command to view all the folders and file information. In general, folders or files are displayed in the order of ascll codes. That is to say, sort by letters, and upper-case letters are placed before lower-case letters. If there is not much file (folder) data in this folder, you can get the correct results quickly. However, if there are many files (folders), such as a page that cannot be displayed, the correct results cannot be obtained quickly if the number is used. In this case, you need to use other commands to help System Engineers complete this task.

  The second command outputs the redirection function.

In actual work, in addition to entering the ls command execution result on the terminal, the system engineer can also use a special command ">" to output the redirection command) save the execution result to a folder. For example, you can use the ls> total command to save the results displayed by the ls command in the total file. After the system engineer executes this command, the system will not display any content except a prompt on the screen. This is the shell redirection function in unix systems. This redirection function redirects the content that should have been displayed on the screen to a user-specified file. The Shell will first explain the commands before the redirection symbol. Note that the command is interpreted but not executed. The shell program then opens the file after the redirection symbol. The third step is to execute this command and save the search results to the file specified by the user. If the system engineer wants to view the content in this file, he can use the cat command to query it. For example, cat total can be used to view the content in this file.

  The third command is the number of lines in the statistics file.

Although the output redirection function has been used to save all the files (folders) in the share folder to a specific file. However, at this time, the system engineer still cannot clearly know the total number of files and folders in the folder. Although data can be predicted by number, it is too troublesome. Although the ls command can save the trouble of scrolling the screen, the accuracy is still not very high. At this point, the system engineer needs to use the command wc for counting the number of file lines.

After the ls result is output to a file through the output redirection function, each folder file will be an independent row during storage. That is to say, if you can use relevant commands to calculate the number of lines in the file, then the number of lines is the total number of files or folders. To achieve this goal, the system engineer can use the wc total command to count the number of rows in this file. After executing this command, the system displays the following line of content.

$ Wc total

85 85 356 total

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.