Wednesday, May 1, 2019

Add Prefix to File Names

Here's how to add a prefix, e.g., "uhu-" to all file names in the current directory:

Original List of Files


$ ll
total 20
drwxr-xr-x  2 lex lex 4096 May  1 09:46 ./
drwxr-xr-x 22 lex lex 4096 May  1 09:45 ../
-rwxr-xr-x  1 lex lex  284 May  1 09:46 drop-tables*
-rwxr-xr-x  1 lex lex   45 May  1 09:44 drop-tables-gen-and-seed*
-rwxr-xr-x  1 lex lex  943 May  1 09:46 gen-tables-and-seed*


Run Bash Commands to Rename Files


$ find . -type f | while read line; do   mv "$line" "uhu-${line:2:999}"; done

$ ll
total 20
drwxr-xr-x  2 lex lex 4096 May  1 09:51 ./
drwxr-xr-x 22 lex lex 4096 May  1 09:45 ../
-rwxr-xr-x  1 lex lex  284 May  1 09:46 uhu-drop-tables*
-rwxr-xr-x  1 lex lex   45 May  1 09:44 uhu-drop-tables-gen-and-seed*
-rwxr-xr-x  1 lex lex  943 May  1 09:46 uhu-gen-tables-and-seed*


Note


alias ll='ls -alF'


This work is licensed under the Creative Commons Attribution 3.0 Unported License.