LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 08:23 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
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, 01:04 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

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

Original Poster
Rep: Reputation: 31
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, 06:04 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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



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-07-2013 11:34 PM
[SOLVED] how to select date and some specific data from a log file shwhooda Linux - Newbie 2 06-25-2012 06:56 PM
Bash Script to Copy Modification Date from a file to his folder pjgm Programming 12 07-31-2011 08:33 AM
How To Copy all Files and Folders from specific date? moviecarpet Linux - Newbie 4 05-26-2011 07:01 PM
SCP copy file with dynamic date( or something like that) Shinigami101 Linux - Software 3 11-19-2008 07:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:35 PM.

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
Open Source Consulting | Domain Registration