Command to copy files older than <n> days keeping dir structure.
Hey Guys,
I'm trying to truncate a postfix Maildata directory for one of our users. I want to be able to move any files older than <n> days to a new location, but also copying the relevant directory structure. This should be doable in the one comman. I've used find to locate the files, and mv to move them, but I can't figure out how to build the directoryt structure on the fly in the new location. This is what I have so far: Code:
find /Maildata/editor -mtime +42 -type f -exec mv -v {} /EditorEmailOld/ \; > ~/editor.txt Thanks. |
Hi, welcome to LQ!
You could create a script ... something like [untested!!]: mv_w_dir.sh Code:
#!/bin/bash Use the script in your exec-statement. Cheers, Tink |
Hmm,
I've got special characters in the files, and maybe spaces. I've seen someone use CPIO but I've never used that command and don't really understand it. I may just have to add support for spaces/special chars into that script above. Thanks! |
To manage spaces and special characters, double quotes around $dir and $file might be enough. An alternative could be rsync, which is suited to recreate the directory structure and manage weird file names as well. For example:
Code:
$ cd /Maildata/editor |
Quote:
|
All times are GMT -5. The time now is 06:56 AM. |