![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto copy for files from folder to folder upon instant writing | Bashar | UNIX for Advanced & Expert Users | 2 | 08-21-2008 02:44 PM |
| moving a file to a new folder and automated ftp | dineshr85 | Shell Programming and Scripting | 1 | 10-05-2007 10:24 AM |
| Parse the .txt file for folder name and FTP to the corrsponding folder. | MeganP | Shell Programming and Scripting | 3 | 07-03-2007 01:54 PM |
| Take a folder name and find it in another folder (Complicated) | hkhan12 | Shell Programming and Scripting | 5 | 09-06-2006 12:25 PM |
| Suppres error message when moving files from empty source folder | Steven | Shell Programming and Scripting | 2 | 11-19-2001 01:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Moving Files from one folder to another folder
Hi,
I have a folder which contain the log files. The folder may contain sub folders as well. I want to move the contents of the log folder to tmp folder periodically. I have used the command. LOG_DIR=/logs DESTINATION_DIR=/tmp/logs find ${LOG_DIR} -mtime +1 -exec mv {} ${DESTINATION_DIR} \; but, the problem is that this command moves all the files in the same folder and source folder structure (sub-folders) is not maintained in the destination directory. Any ideas? or some other way to do this Regards, Muhammad Farooq |
|
||||
|
No success, as it gives 'bad Option -maxdepth' error.
Actually, my scenerio is that I have a folder name 'Messages' and contains subfolders 'message1', 'message2', 'message3', 'message4' and so on. I want to move the folder Messages to the destination directory say 'Logs' and want that directory structure in the destination remains the same. But, when i use the above find command, all the files in the subfolder are placed in the same folder. Is there any other way through which i can move files older than, say 5 days, to another location, while maintaining the directory structure of the source |
|
||||
|
Actually, I made a mistake. :-) I edited my post to correct it, but obviously wasn't fast enough. Anyway, my update was also incorrect...
Code:
dest=$(dirname "$file" | sed 's/Messages/Logs/')
[ -d "$dest" ] || mkdir -p "$dest"
The second line tests whether this directory exists, and if not, creates it. |
|
||||
|
thanks for reply,
what is this s for in 'sed s/Messages/Logs/' Also, i have a source folder and destination folder in a variable, so how would i replace that in a above command $SRC_DIR=/var/opt/Messages probably shomething like below? dest=$(dirname "$file" | sed 's/${SRC_DIR}/Logs/') Last edited by farooqpervaiz; 08-06-2008 at 11:48 PM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| clear logs, find -maxdepth, logs, moving files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|