Last active
October 6, 2015 11:53
-
-
Save biiont/ae71d7c93fc64fb59db6 to your computer and use it in GitHub Desktop.
Mass files rename in shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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