Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving file before a certain time 4

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I need to move a number of files from the current dir to another directory before a certain date & time..

thnx,
 
I tried using find and piping it to mv command but not yet getting there..

Want to do something like this:

xxxxxxxxx 12-03-2004 10:29:54 abcd.job
xxxxxxxxx 12-03-2004 10:39:54 abde.job
xxxxxxxxx 12-03-2004 10:42:54 ab23cdf.job

Now move all the files before 12-03-2004 10:42:10 to another directory..

thnx
 
Actually, on second thought, [tt]xargs[/tt] won't work too well for [tt]mv[/tt] unless you have GNU [tt]mv[/tt]. If you do, look at the man page for [tt]mv[/tt] and pay attention to the [tt]--target-directory[/tt] option.

Otherwise, you might try something like
Code:
mv `find -whatever` target-dir
but that runs the risk of overrunning the command line length on some systems.

If that's the case, try
Code:
find -whatever |
while read file
do
    mv "$file" target-dir
done
That'll be slower, and you might have to fiddle with the IFS variable if your filenames contain spaces or other weird characters.
 
hi,

But how I find the files older than say 2 hours ago ?? the Find -mtime option only provides for days option.. I have Xargs available but not sure how to use it..

thnx
 
Look at -newer option of find command;
you may have to create a suitable file using touch command.
 
I need to supply a file name with the -newer command..

Isnt there any simpler way to going around this ?

thnx
 
I need to supply a file name with the -newer command"

Yes. I don't really see the problem, isn't this simple enough?
 
not sure if i am posing the question right..

I need to find all files based on a certain date-time and not on name of the files..

The -newer commmand asks for a file name but I dont hv one to give...

hope I made my point..

tia
 
The -newer commmand asks for a file name but I dont hv one to give...
But it's so easy to have one ...
Did you read the man pages for touch?
 
hi again,

sorry, missed seeing the post on the related Thread..

Ok I created a touch file like the fwg:

touch 2004031411 /home/etbc01/temp/tempdate.txt

Executed the find command:

find . ! -newer /home/etbc01/temp/tempdate.txt -type f
The command executed fine but the tempdate.txt remains empty ! why is this ?

Also, can I do the fwg:

mv `find . ! -newer /home/etbc01/temp/tempdate.txt -type f` /home/etbc01/temp/

Thnx,
 
Maybe Ken is also answering just now, but here is my text:

The command executed fine but the tempdate.txt remains empty ! why is this ?
That's the normal behaviour. What else did you expect?
Your file tempdate.txt has no other meaning then supplying a time stamp.

mv `find . ! -newer /home/etbc01/temp/tempdate.txt -type f` /home/etbc01/temp/
should work, provided that
1) /home/etbc01/temp is a directory
2) the list of files is not too long.
The usual way however is -exec option of find command.
And if you get errors like 'argument list too long',
you will have to use something like
find ... | xargs mv ...,
there should be threads here explaining this problem.

regards
 
Hi, I am getting fwg output when I execute the command:

/NETSTAT>mv `find . ! -newer /home/etbc01/temp/tempdate.txt
-type f` /home/etbc01/temp/

Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

any idea, whats wrong here ?
 
Where (ie which directory) are you issuing the command from? Have you created tempdate.txt? Are you using 'backticks' (` above the tab key on my keyboard), not regular apostrophes?
 
another idea:
Perhaps find command doesn't find any file at all? Are there such files?
 
1. PWD is : /home/etbc01/NETSTAT
2. ls in this dir gives me:
-rw-r----- 1 etbc01 etbc 167031 Mar 14 10:52 duinfo.txt
-rw-r----- 1 etbc01 etbc 113472 Mar 14 10:53 npu.xls
-rw-r----- 1 etbc01 etbc 1333 Mar 14 10:52 sel.sql
-rw-r----- 1 etbc01 etbc 167031 Mar 14 13:52 sortDU.txt
-rw-r----- 1 etbc01 etbc 2783 Mar 14 11:52 test.txt

3.command touch 200403141130 /home/etbc01/temp/filedate.txt
created a file filedate.txt with the date above.

4. As I said, i now executed the find cmd in the NETSTAT dir with the previously posted message as output..

argh, never thought this wud get so tough ! thnx..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top