1

I have a folder /home/storage/aggregate_data with many sub-folders which in turn contain many files and sub-folders.

I want to copy all the files older than 90 days within the folder /home/storage/aggregate_data to a new one /home/storage_new/aggregate_data using find command since the argument list can be long.

I'm using the command

find /home/storage/aggregate_data/* -mtime +90 \
  -exec mv -v '{}' /home/storage_new/aggregate_data/ \;

The issue is for that some files the directory structure is maintained after moving while for some it is not.

For eg: the file originally in the path /home/storage/aggregate_data/rrc/rrc_daily/imsi_rrc/imsi_rrc_daily_2022_01_02.parquet gets moved to /home/storage_new/aggregate_data/imsi_rrc_daily_2022_01_02.parquet which is different from intended /home/storage_new/aggregate_data/rrc/rrc_daily/imsi_rrc/imsi_rrc_daily_2022_01_02.parquet.

I have also tried

find /home/storage/aggregate_data/ -mtime +90 \
  -exec mv -v '{}' /home/storage_new/ \;

Why is this issue happening to only some files and folders and not all?

How can I achieve my objective?

1
  • Please describe more clearly the result that you want.  Use example pathnames shorter than 17 characters. Commented May 24, 2022 at 17:07

1 Answer 1

1

When you move a directory, then all files and directories contained below it will be moved as a side affect of moving the directory.

When you move a file, then only that file is moved to the destination directory, no heirachy of directories are created, the file is just moved into the destination folder, just like the directory scenario above, however there is no side effect, as with a directory above.

You could write your own script - just to do the move correctly, creating the destination hierarchy if it doesn't already exists. Then use that instead of vanilla mv in the -exec of your find.

rsync has the sort of logic to do that automagically, it is really a backup tool.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .