![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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
|
|
#4
|
||||
|
||||
|
May be this will be beter:
Quote:
|
||||
| Google The UNIX and Linux Forums |