In terminal I can rename a single file that starts with a dash, i.e.
mv ./-file file
I can also rename all files in a directory that start with a dash, i.e.
for f in ./-*; do rename 's/-//' "$f"; done
However, how can I do this recursively. I have tried using the find
command, the rename
command, and a recursive for
loop. By the way, a lot of the file names have more than one dash. I would only want to remove the first dash. Thanks!
-
(dash) because that is used as a prefix to signify parametesr for many commands. ie$ mv a -a mv: invalid option -- 'a' Try 'mv --help' for more information.
for f in ./-* ; do ....
(this has many advantages, such as giving you possibility to give "$f" to any program without fearing it takes the filename as options. but there are other advantages as well, which I won't go into details here (look for stephaneChazelas answers, one has a lot of relevant details))s/-//
instead ofs/^-//