I have A.js
, B.js
, C.js
in a certain directory and I want to write a SINGLE command line in bash shell to rename these files _A, _B, _C. How can I do this?
I tried find -name '*.sh' | xargs -I file mv file basename file .sh
but it doesn't work, basename file .sh isn't recognized as a nested command
How about
Check the syntax for rename on your system.
The above command will rename
A.js
to_A
& so on.If you want to retain the extension, below should help:
A simple native way to do it, with directory traversal:
Will rename every file in place adding extension .txt at the end.
And a more general cool way with parallelization:
Assuming you still want to keep the extension on the files, you could do this:
It will get the name of each file in the directory, and prepend an "_".