bash one-liner loop over directories throws errors

Posted by cori on Server Fault See other posts from Server Fault or by cori
Published on 2010-01-28T04:45:13Z Indexed on 2011/01/04 21:56 UTC
Read the original article Hit count: 443

Filed under:
|
|
|

I'm trying to build a bash one-liner to loop over the directories within the current directory and tar the content into unique tars, using the directory name as the tar file name. I've got the basics working (finding the directory names, and tarring them up with those names) but my loop tosses some error messages and I can't understand where it's getting the commands its trying to run.

Here's the mostly-working one-liner:

for f in `ls -d */`; do `tar -czvvf ${f%/}.tar.gz $f`;done

The "strange" output is:

-bash: drwxrwxr-x: command not found
-bash: drwxr-xr-x: command not found
-bash: drwxr-xr-x: command not found
-bash: drwxrwxr-x: command not found

What portion of the command that I'm running do I not understand and that's generating that output?

© Server Fault or respective owner

Related posts about bash

Related posts about tar