Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| 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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
04-17-2008, 01:03 PM
|
#16
|
|
Member
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 323
Rep: 
|
If rename creates the name of a file which already exists then the file will be overwritten, so you can end up with fewer files than you started with.
The detox command line utility supplied with some linux distributions can recursively replace spaces with '_' and also remove other characters which might cause problems in file and folder names; it won't overwrite a file that already exists.
More details, and detox, can be obtained from http://detox.sourceforge.net/
|
|
|
|
04-17-2008, 05:35 PM
|
#17
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,967
Rep: 
|
Quote:
Originally Posted by ghostdog74
is rename a perl script? does it have the ability to do the sed portion, so that sed can be removed. all done using rename.
|
Code:
/usr/bin/rename: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
Not true about not needing sed. rename will only replace the first instance of space, not all of them.
ta0kira
Last edited by ta0kira; 04-17-2008 at 05:36 PM.
|
|
|
|
04-17-2008, 05:39 PM
|
#18
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,967
Rep: 
|
Quote:
Originally Posted by ararus
This is completely redundant, rename translates patterns itself.
|
Code:
> touch "1 2 3"
> rename " " "_" "1 2 3"
> ls 1_*
1_2\ 3
ta0kira
|
|
|
|
04-18-2008, 08:16 AM
|
#19
|
|
Member
Registered: Mar 2008
Location: UK
Distribution: Slackware
Posts: 56
Rep:
|
Quote:
Originally Posted by ta0kira
Not true about not needing sed. rename will only replace the first instance of space, not all of them.
ta0kira
|
Bugger, I never noticed that before, my bad.
There is also the mmv command, though it's not standard.
A more efficient way might to be use a perl wrapper with xargs, e.g.:
find -type f -print0 | xargs -0 rmspace.pl
rmspace.pl:
Code:
#!/usr/bin/perl -w
for $ARGV (@ARGV) {
$new = $ARGV;
$new =~ s/ /_/g;
rename $ARGV,$new;
}
(My Perl is pretty limited so this might no be the best way to do this...)
|
|
|
|
04-19-2008, 11:18 AM
|
#20
|
|
Member
Registered: Mar 2008
Location: UK
Distribution: Slackware
Posts: 56
Rep:
|
You can also use the shell of course:
Code:
# foo="a b c"
# echo ${foo// /_}
a_b_c
|
|
|
|
04-19-2008, 11:34 AM
|
#21
|
|
Member
Registered: Nov 2004
Location: UK
Distribution: Fedora 12
Posts: 129
Rep:
|
you don't have to rename all your folders subfolders etc.. just do
Code:
cp "folder name with spaces"
|
|
|
|
04-19-2008, 12:48 PM
|
#22
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
Quote:
Originally Posted by ta0kira
Code:
> touch "1 2 3"
> rename " " "_" "1 2 3"
> ls 1_*
1_2\ 3
ta0kira
|
Nope, still redundant:
Code:
telemachus ~/files $ touch "1 2 3" "4 5 6"
telemachus ~/files $ ls
1 2 3 4 5 6
telemachus ~/files $ rename 's/ /_/g' *
telemachus ~/files $ ls
1_2_3 4_5_6
Just use the 'g' option in the rename command. Edit - unless your rename and mine are different. (Mine is the Debian version, ie a Perl script.)
Last edited by Telemachos; 04-19-2008 at 12:51 PM.
Reason: Clarification
|
|
|
|
04-19-2008, 02:48 PM
|
#23
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,967
Rep: 
|
Yeah, that doesn't work at all for me. Mine is a binary.
ta0kira
|
|
|
|
04-19-2008, 06:23 PM
|
#24
|
|
Member
Registered: May 2007
Distribution: Debian
Posts: 754
Rep:
|
Quote:
Originally Posted by ta0kira
Yeah, that doesn't work at all for me. Mine is a binary.
ta0kira
|
Another reason to choose Debian then. 
|
|
|
|
04-20-2008, 12:17 AM
|
#25
|
|
Member
Registered: Aug 2003
Posts: 365
Original Poster
Rep:
|
thankyou to all who've responded here. this will take me
some time to sort through. been out of town the past few
days. frankly, i'm astonished at the amount of response
this question has produced.
thanks again,
BabaG
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:06 PM.
|
|
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
|
|