LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   copy a file with a specific date (https://www.linuxquestions.org/questions/linux-newbie-8/copy-a-file-with-a-specific-date-4175413358/)

ust 06-25-2012 08:23 PM

copy a file with a specific date
 
I have some files which are different timestamp , can advise if I would like to copy a specific date ( eg. May 1 2012) to another directory , what can i do ? thx

chrism01 06-26-2012 01:04 AM

We need to see examples of the filenames (is date in the filename or do you mean mtime?) and where you want them to go.
What have you written so far?

These may help
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://linux.die.net/man/1/date

ust 06-26-2012 05:05 AM

hi ,

may be I explain more detail , what I would like to do is just copy the files which the date is May 1 2012 to another directory ( eg. /tmp ) .


thx

pixellany 06-26-2012 06:04 AM

I assume you mean the date shown in the ls command (this defaults to modification time--I think). The "find" command allows you to filter based on three kinds of time( accessed, changed status, and modified ) but the logic is based on the elapsed time and not an absolute date. (Look at "man find" to see if I've missed something)

The brute force way to do it is to simply use grep to find the date and then pass the filename to the mv command.

Something like this maybe (NOT TESTED)
Code:

for file in $(ls -l); do
    movefile = $(echo $file | grep '<date string>' | sed -n '[^ ]*$')
    mv $movefile <directory>
done

The sed command here strips off the actual filename, and assumes there are no spaces in the filename.

there must be an easier way to do this........


All times are GMT -5. The time now is 11:42 AM.