How can I copy files that are not bigger than 200MB using the terminal?
The question says it all. I want to copy files in the terminal, but there are a few big files I don't want to copy (because they are backups). Is there a command to do that?
Something like cp --max-size=200MB
?
I know rsync
has such an option. Is that the way to go?
Solution 1:
Try using the find
command to build a list of files under 200MB and copy them to a dir
.
find . -size -200M -exec cp -r {} dir/ \;
Solution 2:
Here is how I do it with rsync
:
rsync --max-size=200MB --progress --verbose --recursive --links --perms --ignore-existing --executability --owner --group --times SOURCE TARGET
I would still like to accept an cp
solution, though.
Solution 3:
This
find . -size -200M -exec cp -r {} dir/ \;
didn´t work for me, because it copies all files when it finds a folder, because of the "r" flag on cp. I had to do the following:
-
Get the list of the files when their size is -200MB
find /yourdirectory -type f -size -200M > list.txt
-
Then, copy the files from the list.txt.
cp --parents $(cat list.txt) /newFolder
The "cp" and the "--parents" flag will copy the files and create the necessary folder tree.
-
After that, you have to move the folder to the right place, but it´s simple.
Hope it helps.