[CentOS] how to do repetetive command in shell
Paul Heinlein
heinlein at madboa.comThu Oct 21 20:26:37 UTC 2010
- Previous message: [CentOS] how to do repetetive command in shell
- Next message: [CentOS] how to do repetetive command in shell
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 at madboa.com <> http://www.madboa.com/
- Previous message: [CentOS] how to do repetetive command in shell
- Next message: [CentOS] how to do repetetive command in shell
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the CentOS mailing list