How to batch rename files from command line? (Solved)
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
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
April, a little food for thought till SFR pops up..
http://rajaseelan.com/2009/07/12/how-to ... -in-linux/
http://andrewault.blogspot.com/2008/03/ ... linux.html
http://rajaseelan.com/2009/07/12/how-to ... -in-linux/
http://andrewault.blogspot.com/2008/03/ ... linux.html
Someone was calling me?
Greetings!
Code: Select all
for FILE in *.mp4; do mv "${FILE}" "${FILE//%20/ }"; done
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
Thanks
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
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
The above saved as "massren" and made executeable
then changes one at a time in each filename so I just kept doing it until it gave an error and voila
Code: Select all
for FILE in *.mp4; do mv "${FILE}" "${FILE//%20/ }"; done
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: Select all
# $ 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'
#
Edit - I finally got one to work albeit slowly , one at a time
Its from the second suggestion by Semme
Code: Select all
#!/bin/sh for filename in *$1* do mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"` done
then
Code: Select all
massren %20 ""
Last edited by april on Mon 02 Jun 2014, 22:58, edited 1 time in total.
Code: Select all
#!/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
Last edited by RSH on Mon 02 Jun 2014, 22:08, edited 1 time in total.
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
Hi, "%20" is escape string for empty space as used by URLs.
Try this:
Or even better, use detox.
Try this:
Code: Select all
for i in *.mp4; do mv $i $(echo $i | sed 's|%20||g' ); done
That's strange indeed, but let's see if we get the same results of this one: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"
Code: Select all
# a="abc%20def%20ghi"; echo $a; echo ${a//%20/}
abc%20def%20ghi
abcdefghi
#
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.
EDIT2: I just found that if it's Bash-3.X.X, the % sign has to be escaped:
Code: Select all
a="abc%20def%20ghi"; echo $a; echo ${a//\%20/}
Last edited by SFR on Tue 03 Jun 2014, 10:28, edited 1 time in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
Thanks all it will take a little time to check these out
However changed above post with this Worked brilliantly thank you GustavoYz
However changed above post with this
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: Select all
for i in *.mp4; do mv $i $(echo $i | sed 's|%20||g' ); done
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.
- Puppus Dogfellow
- Posts: 1667
- Joined: Tue 08 Jan 2013, 01:39
- Location: nyc
Renaming in XFCE wm using Thunar Bulk Rename works
- Attachments
-
- rename.jpg
- (37.54 KiB) Downloaded 249 times
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]
@Flash shows a way to use ROX. I would like to do so,but need help.
I have a folder with files in it that end with a date ; such as " - 20120407.txt". There are 27 such files in the folder. In ROX, I
for all of the files. Question #1 - How would I use ROX Rename to do this?
When I type - 20120407 in the left box and leave the right empty, I getQuestion #2 - And, if I wanted to change the datestamp to, say, "tested and confirmed", how would I do that, too?
Guidance anyone?
I have a folder with files in it that end with a date ; such as " - 20120407.txt". There are 27 such files in the folder. In ROX, I
- highlight the files
- right-click to Rename
for all of the files. Question #1 - How would I use ROX Rename to do this?
When I type - 20120407 in the left box and leave the right empty, I get
Code: Select all
None of the names changed, Nothing to do.
Guidance anyone?
- Attachments
-
- Screenshot.jpg
- What must I put in the left and right boxes to remove datestamp
- (26.46 KiB) Downloaded 297 times
Same result.
- Attachments
-
- Cannot Batch Rename.jpg
- Filled in "Replace" and "With". Then clicked "Rename" button. ... Error
- (37.07 KiB) Downloaded 264 times
Hark! The problem is discovered.
ROX's bulk rename does what it is designed to do, but, for a "new to app" user it is all-too-easy to NOT notice that each clickable field has mouse popups associated.
But, there is NO mouse popups to provide the steps via an example on how to use the app. I can see how it did confuse.
To use this ROX app, one needs to know that it is a 3 step process. The process, I think, is a good one but, this screen is NOT helpful if you don't have someone to keep nudging you into the right direction. Way too many minutes and support personnel to use something which should be so obvious.
OK, the 3 steps are (for anyone else)
BTW @Flash, thanks, again.
ROX's bulk rename does what it is designed to do, but, for a "new to app" user it is all-too-easy to NOT notice that each clickable field has mouse popups associated.
But, there is NO mouse popups to provide the steps via an example on how to use the app. I can see how it did confuse.
To use this ROX app, one needs to know that it is a 3 step process. The process, I think, is a good one but, this screen is NOT helpful if you don't have someone to keep nudging you into the right direction. Way too many minutes and support personnel to use something which should be so obvious.
OK, the 3 steps are (for anyone else)
- Fill-in the "Replace" and the "With" fields
- Click the "Apply" button, on the very right-side of the fields, to visually verify the action that the tool will take
- Click "Rename" button, at bottom of window, to carry out the actions you verified
BTW @Flash, thanks, again.
- Attachments
-
- Apply button's use is obscured.jpg
- After filling Replace-With fields, click Apply button to verify the intended action.
If satisfied with the intended action,Click the Rename button to complete the action.
This is a first, second, then last step type of screen with little help for first-ti - (43.48 KiB) Downloaded 249 times
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Really?gcmartin wrote:Hark! The problem is discovered.
Try this:
- Attachments
-
- rename.png
- (25.44 KiB) Downloaded 246 times