Move files from one location to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move files from one location to another
# 1  
Old 04-01-2010
Move files from one location to another

Hi,

I wanted to check how to move files from one location to another based some particular date.

Example I want to move /data/NewJersey folder to /home/scripts/NJ ( including all the files and subfolders within it ), but only which are older than say 8th February 2010.

script , awk, sed ( doesn't matter)

Thanks
# 2  
Old 04-01-2010
Not quite what you are asking but nearly.
If the 28th Feb. was 33 days ago then:
Code:
find /data/NewJersey -type f -mtime +33 -exec mv {} /home/scripts/NJ ;/

You could give this a try?

The version of Unix determines what options you have available to the find(1) command, so what version of Unix are you using?
# 3  
Old 04-01-2010
I am using

Linux 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:56:28 EST 2006 x86_64 x86_64 x86_64 GNU/Linux

---------- Post updated at 05:33 PM ---------- Previous update was at 05:28 PM ----------

Get an error

find: missing argument to `-exec'
-bash: /: is a directory

---------- Post updated at 05:38 PM ---------- Previous update was at 05:33 PM ----------

Command works with a slight modification like below, but doesn't create the same directory structure as at the source

find /data/NewJersey -type f -mtime +33 -exec mv {} /home/scripts/NJ \;
# 4  
Old 04-01-2010
Agreed, sorry got the "\;" at the end from memory wrong!
# 5  
Old 04-01-2010
Hammer & Screwdriver

This turned out to be quite complex and interesting . Please test on expendable data.
My proposed solution appears grossly inefficient because it invokes cpio for every file. On a modern system it is hard to beat for speed.
The script copies the file and then deletes the file.
See both "man find" and "man cpio" for the interaction between "find" and "cpio" when copying files.

Code:
# This cd is important. We do not want absolute paths.
cd /data/NewJersey
find . -type f -mtime +33 -print|while read filename
do
        # Copy files preserving permissions and create any directory needed 
        echo "${filename}"|cpio -pdumv /home/scripts/NJ; ERROR=$?
        if [ $ERROR = 0 ]
        then
                  # Uncomment next line when tested thoroughly
                   echo rm "${filename}"
        else
                   echo "Copy failed for: ${filename}"
        fi
done


Last edited by methyl; 04-01-2010 at 08:42 PM.. Reason: spellin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with copying the list of files from one location to other location

A) I would like to achive following actions using shell script. can someone help me with writing the shell script 1) Go to some dir ( say /xyz/logs ) and then perform find operation in this dir and list of subdir using find . -name "*" -print | xargs grep -li 1367A49001CP0162 >... (1 Reply)
Discussion started by: GG2
1 Replies

2. Shell Programming and Scripting

How to move a file in ftp command to other location?

hi, when i do ftp from unix to laptop which is running a windows os, it lands in a root folder. can i move a file from this root ftp folder to any other location in my laptop say , c:\files\ folder? i used rename command inside ftp , but it says incorrect parameter. (5 Replies)
Discussion started by: Little
5 Replies

3. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be === (3 Replies)
Discussion started by: harpal singh
3 Replies

4. Shell Programming and Scripting

move files to a different location

Hi Guys, I need to write a script that will loop on all of my oracle databases on a server and move archivelogs from archive destination to a different location. I do have a function to loop on all databases on a server. I want help in writing a fuction to dynamically get the archive... (1 Reply)
Discussion started by: Phuti
1 Replies

5. Shell Programming and Scripting

After FTP unable to move file to other location

Hi Experts, I am using below script and facing some problems.. cd /home/user/test rm ftp://ftp.log Example: A_Bachfile_09292011.txt A=`ls -1 "A*.txt"` compress $A C=`ls -1 "A*` hostname="test.gmail.com" user="raju" Password="******" ftp -n $hostname <<EOF >>ftp.lpg... (4 Replies)
Discussion started by: rajubollas
4 Replies

6. UNIX for Dummies Questions & Answers

Schedule a move job, from one location to another

There are two similar directory structures existing, e.g. old/ and new/, where old/d1/d2/d4/, old/d1/d2/d5/, old/d1/d3/d6/ and old/d1/d3/d7 contains some files and now I want to move those files from each folder to new locations new/d1/d2/d4/, new/d1/d2/d5/, new/d1/d3/d6/ and new/d1/d3/d6/. The... (1 Reply)
Discussion started by: abkush
1 Replies

7. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

8. Shell Programming and Scripting

Transfer files from one location to another location

Hi, i have to transfer of files of User1 located in Location1 to user2 located in Location2 using shell script. Please suggest me. (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

9. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies

10. UNIX for Advanced & Expert Users

How to move an application from one location to another

Hi all, I have installed an application (RRDTool) in /usr/local directory, Can any one tell me how I can move this to some other location along with the libraries. Thanks in Advance. (3 Replies)
Discussion started by: KK Varma
3 Replies
Login or Register to Ask a Question