-2

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/
Siva
  • 9,077
  • (1) What do you mean by “at once”?  Generally, only one disk operation can happen at a time.  (We could split hairs and talk about concurrent operations on a RAID, but that’s beyond the scope of this question.)  (2) If you mean that you want to type a command to rename all your folders (one at a time), that’s fairly easy.  What research have you done?  What have you learned?  What have you tried?  Where are you stuck?  (3) Please don’t post pictures of text. – Scott - Слава Україні Jul 08 '19 at 03:28
  • Sorry, i m new to forum, what i mean is that i want to edit the name of the folders, there is -v4 at the end of the name of many folders, so i m looking for something like renaming loop that can remove -v4 from their names – Creepy World Jul 08 '19 at 03:38

4 Answers4

2

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
Freddy
  • 25,565
1

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/

Alex_Krug
  • 322
  • 1
    Seconded on the group renaming feature of Thunar, it's excellent and even has regex support. Another great standalone (graphical) option I use is pyrenamer. – Egon Jul 08 '19 at 05:24
0

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 {} \;
Siva
  • 9,077
  • 5
    Even if the OP assures us that every directory in their directory has a name ending with -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
  • I wonder why this answer was downvoted.   OK, yes (arguably), Freddy’s answer is a bit more streamlined (shorter and more efficient).   But, as far as I can see, msp9011’s answer works correctly, and it was posted earlier.   And yes, this answer is basically just a command with very little explanation — but so is Freddy’s. – G-Man Says 'Reinstate Monica' Jul 08 '19 at 15:23
-1

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

g4s8
  • 478
  • (1) And what if there is a directory with the 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
  • @G-Man it's really strange that I know about these commands, it was hard to find;) if you look closer to question, you may find that it's about Android resource directory layout, where all directories are following special convention, in a few words you can't put multiple -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
  • (1) Hard to find?  Users of Unix&Linux Stack Exchange write about the commands frequently, and there’s lots of documentation for them.  (2) I’ve looked at the question, and I don’t see any reference to Android.  It’s a Unix&Linux question on the Unix&Linux site, so it should be treated as a Unix&Linux question.  (3) And if you’re so sure that filenames won’t contain whitespace or special characters, why did you use find … -print0 and xargs -0 in the first place? – G-Man Says 'Reinstate Monica' Jul 08 '19 at 08:22