I have tried to rename several files on my Linux system. I usedrename 's/foo/bar/g' *
All the files that I wish to change are in the current directory.
It does not change the name of the files but I think it should. Any help would be appreciated.
You have mentioned that you want to rename multiple files at once using rename
expression. Technically you can't use only *
sign for change file names. *
means all files with same name. We know same file types doesn't exist with same name but you can rename some selected part from file. For an example
admin@home:~/works$
ls test*.c
test_car.c test_van.c test_dog.c
- you can rename some part of these files not full name. because there cannot be exist same file name with same extention
admin@home:~/works$
rename 's/test/practice/' *.c
- After executing this command every
test
replace withpractice
.
admin@home:~/works$
ls practice*.c
practice_car.c practice_van.c practice_dog.c
Rename a file mv
mv old_name new_name
The use of the mv command changes the name of the file from old_name
to new_name
.
Another way to rename file extentions in the current directory, for instance renaming all .txt
files in .csv
:
for file in $(ls .); do
mv $file ${file/.txt/.csv}
done
This will not affect files that don't have the .txt
extention and it will prompt an error (should be developed further depending on your needs).
rename foo bar *
or just read the manpage. – hasufell Aug 16 '15 at 18:50