4

Please explain this command in detail.

I am using this command to find large files above 6 MB and split them into 5 MB chunks in the same folder. Then it removes the original files (larger than 6MB) in the same directory.

find . -size +6M -exec split -d -b 5M {\} {}-part \; | find . -size +6M -exec rm -rf {} \;

I have no idea about the purpose of the following portion of the command:

{\} {}

My aim is to develop a script for backing up Virtualmin domains to Amazon S3 buckets monthly.

Due to a 5 GB PUT limit on Amazon S3, I have to split the domain backups (tar.gz) in sizes less than 5 GB.

1 Answer 1

5

From the manpage of find:

The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command...

So, the first part of the find command searches for files greater than 6 MB and executes (-exec) split on every found file.

For Example, if the found file is ./path/to/file, the command executed would be:

split -d -b 5M ./path/to/file ./path/to/file-part 

{} is the placeholder replaced with the filepath. The {\} is unnecessary it could also be {}.

In the second find command - the one after the pipe (|) - the find command calls rm -rf for every file.

2
  • 4
    It's also wrong to use the pipe | to separate the commands; I'd recommend using the logical and && separator so that the second command only runs if the first was successful. Now the second find could be deleting files that haven't yet been split.
    – wurtel
    Commented Nov 14, 2014 at 8:42
  • 2
    As adviced by @wurtel the script can be find . -size +6M -exec sh -c 'split -d -b 5M {} {}-part && rm {}' \;
    – Costas
    Commented Nov 14, 2014 at 10:57

You must log in to answer this question.

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