The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Splitting input files into multiple files through AWK command arund_01 Shell Programming and Scripting 3 05-13-2008 06:17 AM
Find duplicates from multuple files with 2 diff types of files ricky007 Shell Programming and Scripting 2 03-04-2008 10:46 AM
unzip particular gzip files among the normal data files thepurple Shell Programming and Scripting 4 11-30-2007 08:17 AM
when I try to run rm on multiple files I have problem to delete files with space umen UNIX for Dummies Questions & Answers 1 09-20-2005 12:20 AM
text files, ASCII files, binary files and ftp transfers Perderabo Answers to Frequently Asked Questions 0 04-08-2004 01:25 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-21-2006
Registered User
 

Join Date: Jul 2006
Posts: 1
moveing files after they get to old

I can find the files that are to old in the directory

find /dir -mtime +45 -type f -print

but but I need to move them to a archive directory while retaining there subdirectory.

Example

mv /dir1/dir2/dir3/file1 /archive/dir1/dir2/dir3/file1
but /archive does not have any directory in it.

any idea how to do that. Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 07-22-2006
crabbie_upk's Avatar
Registered User
 

Join Date: Jul 2005
Posts: 18
Moving files to archive dir

Just write a perl/shell script with the below steps.

1. Have the result set retuned by find command into array
2. For each file determine the path and create complete dir structure (use command mkdir -p dir1/dir2/dir3) under "archive" directory.
3. Nove move the file from current location into newly created directory.

Please let us know if this fails.
Reply With Quote
  #3  
Old 07-22-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Here is one way:
Code:
#!/bin/ksh
find /dir1 -mtime +45 -type f  | \
while read filename
do
    dir=$( basename "$file" )
    isthere=$( find /archive -name "$dir" -type d )
    if [[ ${#isthere} -eq 0 ]] ; then
        mkdir /archive"$dir"
    fi
    mv "$file"  /archive"$file"
done
Reply With Quote
  #4  
Old 07-22-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 360
May be this will be beter:

Quote:
Originally Posted by jim mcnamara
Here is one way:
Code:
#!/bin/ksh
find /dir1 -mtime +45 -type f  | \
while read filename
do
    dir=$( basename "$file" )
    isthere=$( find /archive -name "$dir" -type d )
    if [[ ${#isthere} -eq 0 ]] ; then
        mkdir -p /archive"$dir"
    fi
    mv "$file"  /archive"$file"
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0