Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the three document processing skills to improve work efficiency under Linux?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you what are the three document processing skills to improve work efficiency under Linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

When you work under Linux, you deal with files most often. After all, everything you work with under Linux is a file. Linux also provides you with a variety of commands for processing files, and the proper use of these commands can greatly save you time and make our workload less heavy.

Techniques for finding documents

When we look for files, the first thing that comes to mind is the find command. But if we search for a wide range of paths, it will take more time, in which case the find command is not the best way.

We can use ls to quickly find recently updated files. For example, do you want to know the script you called before you left the office and went home yesterday? Little case! Use the ls command with the-ltr option. The last one listed will be the most recently created or updated file.

$ls-ltr ~ / bin | tail-3-rwx- 1 shs shs 229 Sep 22 19:37 checkCPU-rwx- 1 shs shs 285 Sep 22 19:37 ff-rwxrw-r-- 1 shs shs 1629 Sep 22 19:37 test2 if we just want to list today's updated files, we can do this:

$ls-al-- time-style=+%D | grep `date +% D` drwxr-xr-x 60 shs shs 69632 09Universe 23 drwxr-xr-x 19. Drwxrwxr-x 2 shs shs 8052736 09 shs shs 23 stats 19 bin-rw-rw-r-- 1 shs shs 506 09 stats if the file we are looking for may not be in the current directory, then find will be more flexible and powerful than ls. However, the output of the find command may be more, and we can use some of its options to filter out results we don't want.

For example, in the following command, we do not search for directories that begin with a dot (that is, hidden directories), specify that we are looking for files rather than directories, and require that only files that have been updated on the most recent day be displayed.

The command is as follows:

$find. -not-path'* /\. *'- type f-mtime-1-ls 917517 0-rwxrw-r-- 1 shs shs 683 Sep 23 11:00. / newscript Note-the not option reverses the behavior of-path, so we will not search for subdirectories that begin with a dot.

If we only want to find the largest files and directories, we can use a command like du, which lists the contents of the current directory by size. The output is then piped to the tail command, viewing only the largest ones.

$du-kx | egrep-v "\. /. + /" | sort-n | tail-5 918984. / reports 1053980. / notes 1217932. / .cache 31470204. / photos 39771212.-k option lets du list file sizes in blocks, while x prevents it from traversing directories on other file systems (for example, through symbolic links). After the command runs, the du command lists the file sizes before calling sort-n to sort by size.

The skill of counting the number of documents

Using the find command, you can easily count files in any particular directory. Note, however, that find recurses to subdirectories and counts the files in these subdirectories together with the files in the current directory.

For example, if we want to count the files in the home directory of a specific user (alvin), we can first use the find command to find the files, and then use the wc command to count.

$find / home/alvin-type f 2 > / dev/null | wc-l 35624 Please note that we send the error output of the find command to / dev/null to avoid searching for folders like ~ / .cache that cannot be searched and are not interested in its contents.

If necessary, we can use the-maxdepth 1 option to limit the find search to a single directory, or we can set it to the depth we want to search:

$find / home/alvin-maxdepth 1-type f | wc-l 387 file renaming skills

You can easily rename a file with the mv command, but sometimes we want to rename a large number of files and don't want to spend a lot of time. At this point, the rename command will come in handy.

For example, if we want to change all files in the current directory with spaces in their names to underscores, you can use the following command:

$rename's / / _ / g' * you should expect that the g in this command line stands for "global". This means that the command changes all spaces in the file name to underscores, not just the first.

If we want to delete the .txt extension from the text file, we can use the following command:

The above is what the editor shares with you about the three document processing techniques to improve work efficiency under Linux. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report