LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2012, 09:23 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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
 
Old 06-26-2012, 02:04 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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
 
Old 06-26-2012, 06:05 AM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
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
 
Old 06-26-2012, 07:04 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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........
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-08-2013 12:34 AM
[SOLVED] how to select date and some specific data from a log file shwhooda Linux - Newbie 2 06-25-2012 07:56 PM
Bash Script to Copy Modification Date from a file to his folder pjgm Programming 12 07-31-2011 09:33 AM
How To Copy all Files and Folders from specific date? moviecarpet Linux - Newbie 4 05-26-2011 08:01 PM
SCP copy file with dynamic date( or something like that) Shinigami101 Linux - Software 3 11-19-2008 08:56 AM


All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration