bash - Filter before copy in shell -


I have a directory with files from January 2014 to November 2014. Regrettably, there are no dates in the name of the files, so only by the way I can know what file is from the file, using the ls -lrt and checking the month there. Used to be.

The file was created so I have to copy these files to the second place by month.

  ls -lr | Grep oct  

will give me all October files.

Now, I tried

  ls -lrt | Grapes October CP * /../../oct2014  

This clearly did not work. Can anybody do this anyway?

EDIT: Thank you very much for responding with such great responses, complete with explanations. I'm really humble. I'll try them on tomorrow morning.

In addition to this, I am working with all the files which do not have any particular characters in its name. Thanks again.

This is a method

  ls -ltr | Awk '/ Oct / {print $ NF}' | Xargs -i {} cp {} Newdir  

or you can use the search

  find type- f-newermt "Oct 01"! -November "October 31st" | Xargs -i {} cp {} Newdir  

Find more robust search (credit to BroSlow)

  find- f-newermt "Oct 01"! -Neworm "Oct 31 23:59:59" -Print 0 | Xargs -0 -i {} cp {} Newdir  

If you need it the most accurate thing in the world then type

  find- f-newermt "Oct 01"! -Newarm "October 31 23: 59: 59.999 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99" 99-99 99 " Xargs -0 -i {} cp {} Newdir  

note

I just thought that in some circumstances, the LSS parsing is insecure (it does not cause special characters Great on display, and that eliminates most programs by spaces and arguments by Newline), if you know that all the filenames in the target folder are not regular characters, then there are no special characters or spaces, then it Ls will work perfectly .
.
Clearly the names of the files are at the discretion of the user, so in most cases where the name can change, it would be better to use to find the solution


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -