- Code: Select all
ren foo* foo*.bar
In Unix you need to do:
- Code: Select all
for x in foo*; do mv $x $x.bar; done
The first part of this: 'for x', tells unix that we want to process a list of 'things' - essentially words or numbers - and that we will refer to each individual 'thing' as 'x'. In technical terms we are defining a variable which we have called x.
Next we use 'in foo*' to define our list. Unix 'just knows' that foo* means "all the files starting with 'foo'". The ';' tells unix we have finished defining our list.
do mv tells Unix what we want to do with each item (x).
$x refers to the variable contents. Once again, Unix 'just knows' that there is no variable called x.bar, and so correctly appends .bar to the file name held in the variable x.
Lastly, ; done indicates to Unix that we have finished entering our command.
So, if we had three files, foo1, foo2 and foo3, our command would be the same as typing:
- Code: Select all
mv foo1 foo1.bar
mv foo2 foo2.bar
mv foo3 foo3.bar
