How can I rename all these folders at once to remove "-v4"?
My directories look like this:
drawable-hdpi-v4/
drawable-ldrtl-v4/
mipmap-mdpi-v4/
How can I rename all these folders at once to remove "-v4"?
My directories look like this:
drawable-hdpi-v4/
drawable-ldrtl-v4/
mipmap-mdpi-v4/
In bash, dash, zsh and maybe other shells with parameter expansion and assuming that only directories end with suffix -v4, you could do :
for i in *-v4; do mv "$i" "${i%-v4}"; done
Install DoubleCommander (doublecmd). It has a group rename feature (Ctrl+M). https://doublecmd.github.io/doc/en/help.html
If you have installed Thunar - http://freesoftwaremagazine.com/articles/bulk_renaming_thunar/
Try this, we can remove the suffixing 3 characters using below code
find . -maxdepth 1 -mindepth 1 -name '*-v4' -type d -execdir bash -c 'mv "$1" "${1%???}"' mover {} \;
-v4 (whether the question says this is debatable), prudence dictates the use of -name '*-v4'.
– G-Man Says 'Reinstate Monica'
Jul 08 '19 at 05:19
Use find with xargs commands:
find -maxdepth 1 -type d -name '*-v4' -print0 | \
xargs -0 -I % bash -c 'mv -v "%" "$(echo % | sed "s/-v4$//")"'
find - search for files in a directory hierarchy
xarg - executes a command (bash here) with argument from find
echo % | sed "s/-v4//" - removes -v4 from file name
foo-v4bar-v4? (2) It’s ironic that you know about find … -print0 and xargs -0, but you build a shell command that fails for filenames with spaces and other special characters.
– G-Man Says 'Reinstate Monica'
Jul 08 '19 at 05:59
-v4 suffixes and can put it only in the end, and you can't put whitespaces or special characters in names. So my command will remove -v4 for any valid android resource directory.
– g4s8
Jul 08 '19 at 06:27
find … -print0 and xargs -0 in the first place?
– G-Man Says 'Reinstate Monica'
Jul 08 '19 at 08:22