New answers tagged

6

For mass-renaming (or mass-copying) files, zmv is your friend. autoload zmv zmv -W $'**/*\r' '**/*' Explanations: zmv renames files matching the given wildcard pattern (here $'**/*\r') to the given replacement expression (here **/*). The -W option allows wildcards in the replacement expression. The $'…' syntax supports backslash expressions such as \r for ...


1

As explained in the comment this works on Linux but not by default on MacOS. touch $'file_\r_name' ls -l --quoting-style=c file_* -rw-r--r-- 1 hl hauke 0 23. Nov 17:02 "file_\r_name" find . -name $'*\r*' -exec rename -nv $'\r' '' {} + 2>/dev/null | cat -v `./file_^M_name' -> `./file__name' -nv puts rename in verbose dry run mode. cat -v is ...


7

A variation on @Gilles' answer that removes all CR characters in (non-hidden) file names wherever they are. autoload -Uz zmv # best in ~/.zshrc zmv $'(**/)(*\r*)' $'$1${2//\r}' (from within the top-level directory where those files are). Here, we don't want to use $f as it's important we only change the name of the files and not other pathname components as ...


1

GNU patch supports file renaming feature of Git-style diffs, since it's last release in 2012. If you don't want to install Git, you can hand-craft the patch file yourself: diff --git a/myfile.txt b/mystory.txt similarity index 100% rename from myfile.txt rename to mystory.txt And it works well enough: $ ls myfile.txt rename.patch $ patch < rename.patch ...


0

Shell Provides the following expansion capability, which you can use with commands like mv or cp: $ echo myfile{.sh,.bak} myfile.sh myfile.bak $ echo myfile{.sh,.bak1,.bak2} myfile.sh myfile.bak1 myfile.bak2 $ echo myfile.sh{,.bak} myfile.sh myfile.sh.bak $ echo myfile.sh{.bak,} myfile.sh.bak myfile.sh Tested with the following: $ echo $SHELL /bin/bash $ /...


0

Beside all the suggested answers I also found the batch-rename functionality of Double Commander very usefull and suitable for my needs. Here is my setup: I add an counter to the filename [N][C] I use search and replace Search: (\d{1,4})(\d{2,4})(\..{3,4}$) Replace: $2$3 You need to check both checkboxes Regular Expression and Use substitution The ...


Top 50 recent answers are included