0

I am trying to write a script where I can find files larger than a certain size and then move them to another dir but the find command also includes the current dir in the result which is not required to be moved the following is the command I wrote and the message I get

$ find -size +2000c -print0 | while IFS= read -r -d $'\0' file; do mv $file ~/wrkbnch; done

mv: cannot move '.' to '/home/jerry/wrkbnch/.': Device or resource busy
Jerry
  • 1

1 Answers1

2

If you're looking for files, be sure to tell find that with -type f:

find . -type f -size +2000c -exec mv {} "$HOME/wrkbnch" ';'

Your code:

find -size +2000c -print0 |
while IFS= read -r -d $'\0' file; do
    mv $file ~/wrkbnch
done

The two things missing here are

  1. -type f for find, and
  2. double quotes around $file to cope with excotic filenames (like *).

For information about IFS= read -r, see "Understand "IFS= read -r line"?" (you're dealing with most of these issues by specifying the delimiter specifically).

Kusalananda
  • 333,661