[Linux-disciples] delete a whole lot of files

Stephen R Laniel steve at laniels.org
Wed Feb 7 16:28:53 EST 2007


On Wed, Feb 07, 2007 at 03:13:30PM -0600, Karl Sokol wrote:
> church at ubuntu:~$ find /home/church -iname '*.jpg' -print0 |xargs -i0 echo rm "
> {}"
> find: /home/church/.aptitude: Permission denied

For one thing, I presume all your JPEGs are either in ~, or
in some specific subfolder of ~ -- 'find' won't be finding
any under ~church/.aptitude . So you should probably do one
of two things:

1) Have 'find' look only under ~, and not under any of ~'s
   subdirectories:

   find ~ -maxdepth 1 [rest of arguments]

or

2) Have it look only under the specific subfolder:

   find [subfolder] [rest of arguments]

> xargs: argument line too long

I just tested this out in a directory with more files than
ls/bash can list. I got the same error as you. I think the
echo might be the problem. xargs may also be tricky. This
works for me:

find ~/dir_with_lots_of_files -exec echo rm '{}' \;

I.e., drop the xargs and use -exec. Most of the time you'll
notice no difference. If you do, come back to us.

> church at ubuntu:~$ find /home/church/ -iname '*.jpg' \ -exec cp '{}' /home/church
> /jpg ';'
> find: paths must precede expression

Normally one gets 'paths must precede expression' errors
when one does something like

find -maxdepth 1 ~/some_dir_to_search_in

because 'find' wants you to do

find ~/some_dir_to_search_in -maxdepth 1

So I suspect what's causing you trouble above is the errant
' \ ' after the '*.jpg'.

I think you need to get comfortable with 'find'. Why not
make a test directory like so?

mkdir ~/test_dir
cd ~/test_dir
for i in `seq 1 1000`; do touch ~/test_dir/$i; done
for i in `seq 200 300`; do mv $i{,.jpg}; done

Now you'll have 900 files or so called 1, 2, 3, etc., and
you'll have 100 or so files called 200.jpg, 201.jpg, etc.
Now play with that directory as you like. Try

find ~/test_dir -maxdepth 1 -exec echo rm '{}' \;

for instance. Just play around and see if you get
comfortable with it.

-- 
Stephen R. Laniel
steve at laniels.org
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20070207/3d7e28c3/attachment.pgp


More information about the Linux-disciples mailing list