Batch rename files on Mac

I downloaded a whole episode of cartoons online, and the file names of the cartoons are all named
"Mouse Bobo and his friends 01.rmvb"
"Mouse Bobo and his friends 02.rmvb"
...

It seems that there is nothing wrong with opening it, but it is embarrassing when it is placed on a USB flash drive and played on TV. The file name is not displayed completely, and it is impossible to see which episode it is. So here we need to change the name in batches.

I know a command called rename, try it directly, unfortunately there is no such command under mac, download one with homebrew, and see how to use it

hao@haodeMacBook-Pro ~/D/tmp> rename
fish: Unknown command 'rename'
haodeMacBook-Pro:~ hao$ brew search rename
rename                                                                     renameutils
^C
haodeMacBook-Pro:~ hao$ brew install rename
^C==> Downloading https://homebrew.bintray.com/bottles/rename-1.600.el_capitan.bottle.tar.gz

######################################################################## 100.0%
==> Pouring rename-1.600.el_capitan.bottle.tar.gz
/usr/local/Cellar/rename/1.600: 3 files, 41.0K
haodeMacBook-Pro:~ hao$
haodeMacBook-Pro:~ hao$ which rename
/usr/local/bin/rename
hao@localhost ~/D/tmp> rename
Usage:
    rename [switches|transforms] [files]

    Switches:

    -0/--null (when reading from STDIN)
    -f/--force or -i/--interactive (proceed or prompt when overwriting)
Wide character in print at /System/Library/Perl/5.18/Pod/Text.pm line 286.
    -g/--glob (expand "*" etc. in filenames, useful in Windows™ CMD.EXE)
    -k/--backwards/--reverse-order
    -l/--symlink or -L/--hardlink
    -M/--use=*Module*
    -n/--just-print/--dry-run
    -N/--counter-format
    -p/--mkpath/--make-dirs
    --stdin/--no-stdin
    -t/--sort-time
    -T/--transcode=*encoding*
    -v/--verbose

    Transforms, applied sequentially:

    -a/--append=*str*
    -A/--prepend=*str*
    -c/--lower-case
    -C/--upper-case
    -d/--delete=*str*
    -D/--delete-all=*str*
    -e/--expr=*code*
    -P/--pipe=*cmd*
    -s/--subst *from* *to*
    -S/--subst-all *from* *to*
    -x/--remove-extension
    -X/--keep-extension
    -z/--sanitize
    --camelcase --urlesc --nows --rews --noctrl --nometa --trim (see manual)


Well, to be safe, let's experiment with samples first

hao@localhost ~/D/tmp> touch 我们1.txt
hao@localhost ~/D/tmp> touch 我们2.txt
hao@localhost ~/D/tmp> ll
total 0
-rw-r--r-- 1 hao staff 0B 11 8 10:04 us 1.txt
-rw-r--r-- 1 hao staff 0B 11 8 10:04 us 2.txt
hao@localhost ~/D/tmp> rename -s our superman *.txt
hao@localhost ~/D/tmp> ll
total 0
-rw-r--r-- 1 hao staff 0B 11 8 10:04 superman 1.txt
-rw-r--r-- 1 hao staff 0B 11 8 10:04 superman 2.txt


The experiment was successful, now it will take minutes to batch rename files

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326322060&siteId=291194637