Simple shell script example

I know this can be done but invariably when I come to do it – I forget what it is…
for example, lets say I have a bunch of tar files that I want to move to my home directory… I can do this…

ls *.tgz>myfilelist
for file in `cat myfilelist`; do
cp $file /home/username/;
done

I could also untar and process them too if I wanted – e.g.

ls *.tgz>myfilelist
for file in `cat myfilelist`; do
tar xzf /home/username/$file;
done

or something…
(corrected typo – in original I changed directory inside the script which would break finding the next file)

Leave a Reply

*