Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-25-2012, 08:23 PM   #1
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, 01:04 AM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
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
Old 06-26-2012, 05:05 AM   #3
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 ) .

Old 06-26-2012, 06:04 AM   #4
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)
for file in $(ls -l); do
     movefile = $(echo $file | grep '<date string>' | sed -n '[^ ]*$')
     mv $movefile <directory>
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........


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-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

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

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