Questions about batch file name modification in linux
Source: Internet
Author: User
Problem: in a mysql backup directory, the "modification time" attribute is the file of the current day, renamed as original name + date stamp; put it in the folder named by date, www.2cto.com, the first impression is the xargs command + ls command. 1. date first comes with the command date + % Y % m % d20120... problem: in a mysql backup directory, the "modification time" attribute is the file of the current day, renamed = original name + date stamp; put www.2cto.com in the folder named after the date. The first impression is the xargs command + ls command. 1. date first comes with the command date + % Y % m % d 20120611 2. change the time to the file of the current day, the first thought is to use the ls command to grep the file ll -- full-time-rw-r -- 1 root 0 16:01:03. 455732984 + 0800 1.txt-rw-r -- 1 root 0 16:06:54. 385383568 + 0800 2.txt: filter out the files on the current day. [we didn't know how to execute the date command in grep at the beginning. later, with the reminder of Fat Man, if you know the backquotes, you can execute the command in this situation.] ll -- full-time | grep 'date + % Y-% m-% d' 3. you only need to obtain the file name. cut command, easy to use; ll-full-time | grep 'date + % Y-% m-% d' | cut- D ""-f10 1.txt www.2cto.com 2.txt 4. use the xargs command. Ll -- full-time | grep 'date + % Y-% m-% d' | cut-d ""-f10 | xargs-n 10-I {} mv {}{ }. 'date + % Y % m % d'-rw-r -- 1 root 0 June 11 16:01 1.txt. 20120611-rw-r -- 1 root 0 June 11 16:06 2.txt. 20120611 [here is also the anti-single quotation mark ', which gave me a headache for a long time and finally figured out that the anti-single quotation mark ''is the priority to execute the content in it.] 5. later I found that the original find command, it is much simpler than I implement; find. -maxdepth 1-type f-mtime 0-exec mv {}{}. 'date + % Y % m % d' \; 6. We also found that awk text operations can also be used later. I lamented that linux is a beginner to me ,...... Author james_moriarty
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.