Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 07 Dec 2019, 05:41
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
How to batch rename files from command line? (Solved)
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Author Message
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Mon 02 Jun 2014, 03:58    Post subject:  How to batch rename files from command line? (Solved)  

rename 's/%20/ /g' *.mp4

I'm trying to rename a bunch of files in one directory
opening a terminal in the directory and issuing the command gives no change and no errors

Anyone know whats going on here?
I don't think its handled by busybox
Back to top
View user's profile Send private message Yahoo Messenger 
Semme


Joined: 07 Aug 2011
Posts: 8021
Location: World_Hub

PostPosted: Mon 02 Jun 2014, 06:50    Post subject:  

April, a little food for thought till SFR Wink pops up..

http://rajaseelan.com/2009/07/12/how-to-mass-rename-files-in-linux/

http://andrewault.blogspot.com/2008/03/mass-file-renaming-in-unix-or-linux.html
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 12800
Location: Stratford, Ontario

PostPosted: Mon 02 Jun 2014, 07:10    Post subject:  

What are you trying to do? Take all the spaces out of the filenames? Please give an example.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1749

PostPosted: Mon 02 Jun 2014, 07:11    Post subject:  

Someone was calling me? Wink
Code:
for FILE in *.mp4; do mv "${FILE}" "${FILE//%20/ }"; done

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Mon 02 Jun 2014, 17:40    Post subject:  

Thanks
Code:
for FILE in *.mp4; do mv "${FILE}" "${FILE//%20/ }"; done

gives " are the same file " message in a terminal and nothing gets changed

The files look like this
"bob%20the%20builder%20does%20things.mp4"
and I want to get them to look like this
"bobthebuilderdoesthings.mp4"

There is something strange about the behaviour of "%20"


I also tried this from Semme's suggestion-thanks Semme
Code:
# $ for mp4 in *; do new_name=$(echo $mp4 | sed -e 's/%20/ /g' | sed -e 's/
/ /g'); echo file $mp4 will be renamed to $new_name;mv -v $mp4 "$new_name"; done
bash: syntax error near unexpected token `do'
#

The second sed was left in just because I didn't think it would affect anything

Edit - I finally got one to work albeit slowly , one at a time
Its from the second suggestion by Semme
Code:
#!/bin/sh for filename in *$1* do mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"` done

The above saved as "massren" and made executeable
then
Code:
massren %20 ""
changes one at a time in each filename so I just kept doing it until it gave an error and voila
Last edited by april on Mon 02 Jun 2014, 18:58; edited 1 time in total
Back to top
View user's profile Send private message Yahoo Messenger 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Mon 02 Jun 2014, 18:05    Post subject:  

Code:
#!/bin/sh
#------------------------------------------------------------------------------

# Submitted File
subfile="$1"
echo "`basename "$subfile"`" > /tmp/subfile_tmp

# Parts in File Name to be removed - if needed, add more here
FPARTS="%20 - _"

for FPART in $FPARTS;
do
   S_OUT="$FPART"
   S_IN=""
   for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20;
   do
      sed -i 's|'$S_OUT'|'$S_IN'|' /tmp/subfile_tmp
   done
done
# Remove real Spaces in File name
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20;
do
   sed -i 's| ||' /tmp/subfile_tmp
done

read newname < /tmp/subfile_tmp

mv "$subfile" "`dirname "$subfile"`/$newname"

rm -f /tmp/subfile_tmp

exit 0

This is a Script that I'm still using to remove parts like %20 from a filename.

_________________
LazY Puppy
RSH's DNA
SARA B.

Last edited by RSH on Mon 02 Jun 2014, 18:08; edited 1 time in total
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 894
Location: .ar

PostPosted: Mon 02 Jun 2014, 18:06    Post subject:  

Hi, "%20" is escape string for empty space as used by URLs.

Try this:
Code:
for i in *.mp4; do mv $i $(echo $i | sed 's|%20||g' ); done

Or even better, use detox.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1749

PostPosted: Mon 02 Jun 2014, 18:07    Post subject:  

april wrote:
gives " are the same file " message in a terminal and nothing gets changed
[snip]
There is something strange about the behaviour of "%20"

That's strange indeed, but let's see if we get the same results of this one:
Code:
# a="abc%20def%20ghi"; echo $a; echo ${a//%20/}
abc%20def%20ghi
abcdefghi
#

The only thing I can think of ATM is older version of Bash (3.something.something perhaps?).
If that's the case, just try the above line in 'ash' or 'busybox sh' shell instead.

EDIT: or use RSH's/GustavoYz's sed solutions, which should work regardless of used shell. Wink

EDIT2: I just found that if it's Bash-3.X.X, the % sign has to be escaped:
Code:
a="abc%20def%20ghi"; echo $a; echo ${a//\%20/}

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.

Last edited by SFR on Tue 03 Jun 2014, 06:28; edited 1 time in total
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 12800
Location: Stratford, Ontario

PostPosted: Mon 02 Jun 2014, 18:20    Post subject:  

SFR's version works for me, except that there is an extra space before the final }.
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Mon 02 Jun 2014, 19:03    Post subject:  

Thanks all it will take a little time to check these out
However changed above post with this
Quote:
Edit - I finally got one to work albeit slowly , one at a time
Its from the second suggestion by Semme
Code:
#!/bin/sh for filename in *$1* do mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"` done

The above saved as "massren" and made executeable
then
Code:
massren %20 ""
changes one at a time in each filename so I just kept doing it until it gave an error and voila


Code:
for i in *.mp4; do mv $i $(echo $i | sed 's|%20||g' ); done
Worked brilliantly thank you GustavoYz
Back to top
View user's profile Send private message Yahoo Messenger 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 13388
Location: Arizona USA

PostPosted: Tue 03 Jun 2014, 00:05    Post subject:  

Or you can open the directory with ROX, select all the files whose names you want to change, right-click on them and choose Rename from the menu. Enter %20 in the first box. leave the second box empty, and see what happens when you hit Enter. ROX won't actually change the file names until you click on Rename at the bottom, so if you don't like the way it looks, just Cancel out.
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Tue 03 Jun 2014, 05:56    Post subject:  

Well theres one I hav'nt seen before thanks Flash .Works well only one %20 at a time but you can see them change before commiting
Back to top
View user's profile Send private message Yahoo Messenger 
Puppus Dogfellow


Joined: 07 Jan 2013
Posts: 1633
Location: nyc

PostPosted: Tue 03 Jun 2014, 13:21    Post subject:  

could the built in gFnRename utility be of any use to you?
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Tue 03 Jun 2014, 17:06    Post subject:  

Thats another that works and I have never used that before .
Thanks Puppus Dogfellow
Back to top
View user's profile Send private message Yahoo Messenger 
Geoffrey


Joined: 30 May 2010
Posts: 2377
Location: Queensland

PostPosted: Wed 04 Jun 2014, 02:57    Post subject:  

Renaming in XFCE wm using Thunar Bulk Rename works
rename.jpg
 Description   
 Filesize   37.54 KB
 Viewed   246 Time(s)

rename.jpg


_________________
Carolina: Recent Repository Additions

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0617s ][ Queries: 13 (0.0101s) ][ GZIP on ]