Reputation: 113
I'm trying to rename all the files in a directory in csh (I'm using FreeNAS).
I thought I had the hang of it until I accidentally prepended to the whole file name so now I have files of the format
Veronica Mars - 1x22 Leave It to Beaver.mkv - HDTV 720p
and would like them in the format of
Veronica Mars - 1x22 Leave It to Beaver - HDTV 720p.mkv
I would like to do this purely with a script so that I can ssh in to my box and run it without having to install anything extra.
Upvotes: 0
Views: 622
Reputation: 625
Check if rename is available on your system:
rename 's/\.mkv/ - HDTV 720p.mkv/' *.mkv
EDIT: Then you have to do some shell script programming (bash)
for i in *.mkv; do j=echo $i | cut -d . -f 1
; r=$j" - HDTV 720p.mkv"; mv "$i" "$r"; done
Upvotes: 0
Reputation: 7237
The most expedient way to do this is probably vidir, which allows you to edit the filenames in a directory in a text editor. You can then use Vim's or Emacs' column editing/search and replace.
You can download vidir, and here's a brief introduction.
The only caveat is that it's written in perl, not sure if FreeNAS has that available.
Upvotes: 1