In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to deal with Linux files, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Linux provides a variety of commands for working with files, which can save you time and make your work less tedious.
Find a file
Find may be the first command that comes to mind when you look up files, but sometimes a well-designed ls command is better. Want to know the script you called before you left the office and went home yesterday? simple! 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
A command like this lists only the files that are updated today:
$ls-al-- time-style=+%D | grep `date +% D`drwxr-xr-x 60 shs shs 69632 09 stats. Drwxrwxr-x 2 shs shs 8052736 09 stats 23 bin-rw-rw-r-- 1 shs shs 506 09 stats
If the file you are looking for may not be in the current directory, find will provide better options than ls, but it may output more results than you want. In the following command, we do not search for directories that start with a dot (many of which are constantly updated), specify that we are looking for files (that is, not directories), and require that only files that have been updated on the most recent day (- mtime-1) be displayed.
$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 you only want to find the largest files and directories, you can use a command like du, which lists the contents of the current directory by size. Pipe the output to tail and view only the largest ones.
$du-kx | egrep-v "\. /. + /" | sort-n | tail-5918984. / reports1053980. / notes1217932. / .cache31470204. / photos39771212.
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). In fact, du lists the file sizes first so that they can be sorted by size (sort-n).
File count
Using the find command, you can easily count files in any particular directory. You just need to remember that find recurses to subdirectories and counts the files in these subdirectories together with the files in the current directory. In this command, we count the files in a specific user's home directory (username). Depending on the permissions of the home directory, this may require the use of sudo. Remember that the first parameter is the starting point of the search. What is specified here is the user's home directory.
$find ~ username-type f 2 > / dev/null | wc-l35624
Note that we are sending the error output of the above find command to / dev/null to avoid searching for folders like ~ username/.cache that cannot be searched and are not interested in its contents.
If necessary, you can use the maxdepth 1 option to limit find to a single directory:
$find / home/shs-maxdepth 1-type f | wc-l387 rename file
You can easily rename files with the mv command, but sometimes you want to rename a large number of files and don't want to spend a lot of time. For example, to change all spaces you find in the file name of the current directory to underscore, you can use the following command:
$rename's / / _ / g' *
As you suspect, the g in this command means "global". This means that the command changes all spaces in the file name to underscores, not just the first.
To remove the .txt extension from the text file, use the following command:
The above is all the contents of the article "how to deal with Linux Files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.
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.