Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-27-2007, 11:12 AM
|
#1
|
LQ Newbie
Registered: Jul 2004
Posts: 5
Rep:
|
Cannot replace spaces w/ underscores
Hello,
I'm desperately trying to replace some files w/ spaces in the names w/ underscores.
I ran this command in a directory: rename " " _ *\ * and it worked like a charm on every file except this one:
MissMarieBand_Oh_No!_Not Again.wmv
I then tried to take to remove the spaces w/ this: rename "s/ *//g" *.mov
and it still ignores this file.
Is there any way I can get around this?
Thanks,
Clem
|
|
|
09-27-2007, 11:30 AM
|
#2
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
The *.mov in the command you specified:
Code:
rename "s/ *//g" *.mov
Means the command will only apply to files which end in ".mov", so it should not work on one ending in ".wmv", like the one you named.
|
|
|
09-27-2007, 11:32 AM
|
#3
|
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Fedora40
Posts: 6,156
|
I think the problem is the "!" in the filename - it shouldn't be there.
|
|
|
09-27-2007, 11:33 AM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
I don't see what the syntax of this is.
This: operates on all files ending in ".mov", but yours ends in ".wmv" Also, it only replaces 2 or more occurences of " ". Try 's/ //g'
|
|
|
09-27-2007, 11:41 AM
|
#5
|
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Fedora40
Posts: 6,156
|
For example:
Code:
tg@vaio:~$ touch "MissMarieBand_Oh_No!_Not Again.wmv"
bash: !_Not: event not found
tg@vaio:~$ touch "MissMarieBand_Oh_No\!_Not Again.wmv"
tg@vaio:~$ ls Miss*
MissMarieBand_Oh_No\!_Not Again.wmv
So get rid of the "!"
Edit: Like this:
Code:
tg@vaio:~$ mv MissMarieBand_Oh_No\!_Not\ Again.wmv MissMarieBand_Oh_No_Not_Again.wmv
/Edit
Last edited by tredegar; 09-27-2007 at 11:55 AM.
|
|
|
09-27-2007, 11:54 AM
|
#6
|
Member
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202
Rep:
|
Try this, it worked on my pc:
mv MissMarieBand_Oh_No\!\ Again.wmv MissMarieBand_Oh_No\!_Again.wmw
I hope it is a good song.
|
|
|
09-27-2007, 11:56 AM
|
#7
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
I oopsed---"*" means ZERO or more instances of the previous expression. Here is the para from "man regex"
A piece is an atom possibly followed by a single(!) `*', `+', `?', or
bound. An atom followed by `*' matches a sequence of 0 or more matches
of the atom. An atom followed by `+' matches a sequence of 1 or more
matches of the atom. An atom followed by `?' matches a sequence of 0
or 1 matches of the atom.
And, yes, ANY special character in a filename is bad news....
|
|
|
09-27-2007, 01:17 PM
|
#8
|
LQ Newbie
Registered: Jul 2004
Posts: 5
Original Poster
Rep:
|
Great - thanks for all the feedback. I am a command line tard for sure.
This did the trick for me:
mv MissMarieBand_Oh_No\!_Not\ Again.wmv MissMarieBand_Oh_No_Not_Again.wmv
|
|
|
All times are GMT -5. The time now is 09:32 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|