Hi guys,
First of all thanks for reading this and the already provided information! I was reading about a post that was created a couple of years back:
86686-ls-l-all-files-created-between-two-times.html (i am not allowed to copy urls )
My question is somehow similar.
I have a directory with +/- 68.000 photos (JPEG images) that where created from 15-01-2012 until 04-06-2012. The photos where created every 2 minutes. There are some gaps in between but that is not important.
From these 68.000 file I am only interested in the once that where created between: 09:00 and 17:30
In other words: I need a specific filter within the data filter, correct?
How does the syntax look like for the cp command, if I want to copy the selected query to another directory?
Many, many thanks,
Paul
Is the time of making the photo part of the filename?
Nope. File name is sequential 1,2,3,4....68151.jpg
Only time is the time stamp.
Thanks.
Check if this gives you files that should be copied:
stat -c "%y %n" * | awk -F"[ :]" '$2>=9&&$2<17||$2==17&&$3<=30{print $6}'
aah
Can you explain what is happening here?
stat
is used to read file's modification date and awk
is used to filter files that were modified between 9:00 and 17:30. If this code gives you proper results, then you can copy those files using:
stat -c "%y %n" * | awk -F"[ :]" '$2>=9&&$2<17||$2==17&&$3<=30{print $6}' | xargs -i cp {} /somewhere/else
1 Like
I forget to mention:
I am running a Mac os X machine with Debian Linux. Don't think the -c command is working?
bartus11:
stat
is used to read file's modification date and awk
is used to filter files that were modified between 9:00 and 17:30. If this code gives you proper results, then you can copy those files using:
stat -c "%y %n" * | awk -F"[ :]" '$2>=9&&$2<17||$2==17&&$3<=30{print $6}' | xargs -i cp {} /somewhere/else
Okay That makes sense yes
But shouldn't I define a time for AWK:confused:
This: $2>=9&&$2<17||$2==17&&$3<=30
defines the time in awk...
...
Pauls-Mac-mini:NEED TO DOWNLOAD mmtimelapse$ stat -c "%y %n" * | head
-bash: /usr/bin/stat: Argument list too long
aaaaah
---------- Post updated at 09:40 AM ---------- Previous update was at 09:36 AM ----------
stat -c "%y %n" * | awk -F"[ :]" '$2>=9&&$2<17||$2==17&&$3<=30{print $6}'
Give the same problem.
Try
find . -type f -exec stat -c "%y %n" {} \; | awk -F"[ :]" '$2>=9&&$2<17||$2==17&&$3<=30{print $6}'
hehe... terminal when to an infinite loop of stat awk
But you see filenames appearing?
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
Nope.
OK... so you are running OSX or Debian? I'm confused now.
Would this work?
find . -type f -print0 | xargs -0 stat -c "%y %n" | awk -F"[ :]" $2>=9&&$2<17||$2==17&&$3<=30{print $6}
---------- Post updated at 09:53 AM ---------- Previous update was at 09:51 AM ----------
O crap... Not debian but darwin.. (sorry its late here)
Darwin Kernel Version 11.4.0
What does this show:
stat -f "%m %N" /usr/bin/stat
How about this:
find . -type f -print0 | xargs -0 stat -f "%Sm %N" -t "%H:%M" | awk '/^(09:|1[0123456]:|17:[012]|17:30)/ { print $2 }'
---------- Post updated at 11:30 AM ---------- Previous update was at 10:38 AM ----------
This is driving me nuts!!!
find . -maxdepth 1 -type f -print0 | xargs -0 stat -f "%Sm %N" -t "%H:%M" | awk '/^(09:|1[0123456]:|17:[012]|17:30)/ { print $2 }' | xargs -I cp /Volumes/Timelapse\ 1/Temp/
returns permission denied...
Help!
---------- Post updated at 01:23 PM ---------- Previous update was at 11:30 AM ----------
Ok...
So the following code
find . -maxdepth 1 -type f -print0 | xargs -0 stat -f "%Sm %N" -t "%H:%M" | awk '/^(09:|1[0123456]:|17:[012]|17:30)/ { print $2 }'
works as a selection on screen.
I can also parse it to a txt file but I have absolutely no luck in getting the selection into the copy command...
If this gives you the list of files:
find . -maxdepth 1 -type f -print0 | xargs -0 stat -f "%Sm %N" -t "%H:%M" | awk '/^(09:|1[0123456]:|17:[012]|17:30)/ { print $2 }'
Then this will copy them to "/somewhere/else"
find . -maxdepth 1 -type f -print0 | xargs -0 stat -f "%Sm %N" -t "%H:%M" | awk '/^(09:|1[0123456]:|17:[012]|17:30)/ { print $2 }' | xargs -I'{}' cp {} /somewhere/else
1 Like