Hello,
I have 2 drives.
Drive X and drive Y.
Drive X has many many files and directories inside. And I wish to COPY things from drive X to Y.
However, I ONLY want to move the files between a certain date range.
Any files that satisfy the date range condition will be copied from X to Y.
For example, I want to only move files which are modified/created from Jan1st to Feb1st 2007, from X: to Y: drive. If only the following files satisfy the date range condition, then they will be copied in this fashion:
X:/abc/foo.c -%26gt; Y:/abc/foo.c
X:/teamX/excel.xls -%26gt; Y:/teamX/excel.xls
X:/teamA/picture.jpg -%26gt; Y:/teamA/picture.jpg
This would be simple if I were working in with a GUI, but I am STRICTLY restricted to text commands or Scripts (or programs).
I can write a program to perform this task, but I am pretty sure there's a much quicker existing way by using Shell commands and pipelines.
Any help would be greatly appreciated!
Unix/Linux help. Moving files using commands.?
cp - copies files
tar - can also copy files, more commonly it's used to make archives like zip does
dd - can also copy files, more commonly it's used to clone a drive or partition, particulary in data recovery.
mv - moves files
man cp - read the manpage for the cp command
man find - read the manpage for the find command
here's one way to do it:
touch -d "Jan 1 2007" file.start
touch -d "Feb 1 2007" file.end
find /somepath -daystart -newer file.start \! -daystart -newer file.end -exec cp {} /newlocation \;
That should do it. You might want to doublecheck my syntax as it's late and I could have mistyped something.
Reply:if you are copying files from one drive to another, make sure you know exactly where they are mounted. in linux all drives are mounted somewhere on the same filesystem, which could be confusing you. you can't just cd to x: like you can in windows. the upside to this is you can mount a drive anywhere you want! once you verify the proper paths, you can you cp and the find command to do what you want. here's an example of how to copy all the folders [command -type d] (only in the root of /mnt/drive1 [commands -mindepth 1 -maxdepth 1]) recursively [command cp -r] that were last modified in the past 24 hours [command -mtime 0] to a drive mounted at /mnt/drive2:
cp -r `find /mnt/drive1 -mindepth 1 -maxdepth 1 -mtime 0 -type d` /mnt/drive2
research the find command a bit more, it's pretty easy to do what you want.
also keep in mind you'll need to have the proper permissions to access and then cp the data!
*EDIT*
actually, that will only work if the folders do not have spaces or strange characters in them. for cp to handle the folder names correctly, you'll have to pipe to xargs like so:
find /mnt/drive1 -maxdepth -mindepth 1 -mtime 0 -type d -print0 | xargs -0 /bin/cp -r /mnt/drive 2
hope that helps! just trying to show you the INCREDIBLE power of the linux command line (assuming you use it right, lol!)
Reply:Doesn't UNIX have some kind of move command like Windows does?
Reply:Write script for that.
First get the last modified time of a file.
This you can do in many ways... One option is to scan the output of ls -l command and select those files whose date matches your requirement.
Once you have the list you can move thm to other drive using mv comand.
Start with root directory...
list all files..
if its a file(not a directry) then check the date
if it matches then
use mv to move to destn.
if all files are over.. open the first directory
do as above...
**************
I gave you just an idea.. I dont know its worth to you..
Anyhow goodluck
:-)
survey research
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment