6

We need a command that copy files from current directory to another with given date.

-rw-r----- 1 schmidt schmidt 276423 set 03 10:31 'event01.csv'
-rw-r----- 1 schmidt schmidt 283861 set 03 10:34 'event02.csv'
-rw-r----- 1 schmidt schmidt 280644 set 03 10:40 'event03.csv'
-rw-r----- 1 schmidt schmidt 270234 set 03 03:26 'event04.csv'
-rw-r----- 1 schmidt schmidt 293488 set 12 06:43 'event05.csv'
-rw-r----- 1 schmidt schmidt 287417 set 12 07:48 'event06.csv'
-rw-r----- 1 schmidt schmidt 280519 set 12 10:19 'event07.csv'
-rw-r----- 1 schmidt schmidt 279631 set 12 19:43 'event08.csv'
-rw-r----- 1 schmidt schmidt 286578 set 12 15:15 'event09.csv'
-rw-r----- 1 schmidt schmidt 289830 set 12 18:41 'event10.csv'
-rw-r----- 1 schmidt schmidt 305209 set 19 05:58 'event11.csv'
-rw-r----- 1 schmidt schmidt 308275 set 19 06:20 'event12.csv'
-rw-r----- 1 schmidt schmidt 275015 set 19 14:40 'event13.csv'
-rw-r----- 1 schmidt schmidt 310610 set 19 15:40 'event14.csv'
-rw-r----- 1 schmidt schmidt 311466 set 19 15:41 'event15.csv'
-rw-r----- 1 schmidt schmidt 305241 set 19 15:51 'event16.csv'
-rw-r----- 1 schmidt schmidt 291699 set 19 15:56 'event17.csv'

For example, command should copy all files with "set 12" timestamp to directory /home/12thsep/.

Any ideas?

8

You could be selecting by the date option in find

find . -maxdepth 1 -type f -newerat '2019-09-19' ! -newerat '2019-09-20' -exec mv '{}' /home/12thsep \;
6

You may use find with correct mtime arguments. For example:

mkdir <dest_path> && find <source path> -mtime -X -a -mtime +Y -exec mv {} <dest_path>/ \;

Where X represent the "day after" and Y the "day before". Note the use of -a to makes find use a AND between the two conditions specified. Refer to find manpage for more details regarding syntax to use.

  • @Fixman answer looks better than mine. I didn't knew about -newerat... – binarym Oct 21 '19 at 15:54
  • 1
    FYI -a for AND is the default with find, so isn't needed. you only need to specify a logical operator when you want to use OR (-o). in other words, all predicates are AND-ed together unless you specify otherwise with -o. You'll need parentheses (quoted or escaped on the shell command line, e.g. \( and \)) for nested or more complicated logic operators. – cas Oct 22 '19 at 3:51
  • Thx for precisions @cas – binarym Oct 22 '19 at 8:17
5

It may be done in following way:

ls -alF|grep "set 12" >> logxa00.txt

cat logxa00.txt| awk '{print $9}' > logxa01.txt

xargs -a logxa01.txt cp -p -t /home/12thsep/
  • Be careful with spaces and tabs in filenames. awk might print half a name only. – Fiximan Oct 23 '19 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.