Skip to content

Instantly share code, notes, and snippets.

@biiont
Last active October 6, 2015 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biiont/ae71d7c93fc64fb59db6 to your computer and use it in GitHub Desktop.
Save biiont/ae71d7c93fc64fb59db6 to your computer and use it in GitHub Desktop.
Mass files rename in shell
#!/bin/false
## First: select file set.
/bin/ls -1 prefix_to_remove_*
## Second: test transformation.
/bin/ls -1 prefix_to_remove_* | sed 's/^prefix_to_remove_\(.*\)$/\1/'
## Third: execute
## NOTE: Added 'mv \0 ' to the sed command and '| sh' to the pipe.
/bin/ls -1 prefix_to_remove_*| sed 's/^prefix_to_remove_\(.*\)$/mv \0 \1/' | sh
## Multiline script example
## NOTE: Note option "-r" for sed command -- it enables use of brackets without escapes.
SEDS="$(mktemp -u -p \"${XDG_CACHE_HOME:-$HOME/.cache}\")"; cat <<EOF >"$SEDS"; ls -1 | sed -n -r -f "$SEDS" | sh; rm "$SEDS"
s/^(name)\.(ext)$/mv \0 \1\2/ p
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment