Re: how to do repetetive command in shell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Thu, 21 Oct 2010, John Kennedy wrote:

> Damn...I will get this right...Need more sleep...

> for i in `ls -d /opt/* | cut -d/ -f3` do
> cp /opt/${i}/test/ /backup/${i}
> done

Using ls in a for loop is rarely necessary.

   for i in /opt/*; do
     cp -a ${i}/test /backup/$(basename $i)
   done

More simply, just cd to /opt before globbing filenames:

   cd /opt
   for d in *; do
     cp -a ${i}/test /backup/${i}
   done

-- 
Paul Heinlein <> heinlein@xxxxxxxxxx <> http://www.madboa.com/
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux