In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
The purpose of this article is to share with you what are the document processing skills to improve work efficiency under Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
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 the files that are updated today, 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 stats 23 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 that the-not option reverses the behavior of-path, so we don't search for subdirectories that start with a dot.
If we only want to find larger 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 to view only the larger ones.
$du-kx | egrep-v "\. /. + /" | sort-n | tail-5 918984. / reports 1053980. / notes 1217932. / .cache 31470204. / photos 39771212.
The-k option lets du list file sizes in blocks, while x prevents it from traversing directories on other file systems (for example, referencing 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
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
Techniques for renaming files
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' *
As you can imagine, the g on this command line stands for "overall". 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:
Thank you for reading $rename's _ This is the end of this article on "what are the document processing skills to improve work efficiency under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.