Ruby would be easier, perl just looks wrong.Dungeon-Dave wrote:I could probably hack something together in perl; that'd be the easiest for me, I think.
(But that's a Programming forum thread).
The Official *nix Thread
- stealthbanana
- Baaaaaa!

- Posts: 2805
- Joined: Wed Nov 09, 2005 11:59 pm 0
- Location: Over Here.
Re: The Official *nix Thread
Not long now before lollipop men are called Darren
Re: The Official *nix Thread
That's pretty much what I got it down to as well. If you're happy to accept a load of error messages at each level, though, you can get away with this:koogy wrote:Code: Select all
find . -maxdepth 1 -name "* *" > acd while read line; do echo mv "$line" ${line// /_}; done < acd
Code: Select all
find | while read line; do mv "$line" ${line// /_}; doneThis works because "find" with no arguments will start in the current directory and print out a list of files. They are ordered so that parent directories come before the files within them. This means that when you run the command the topmost directories will get renamed, and all their children will generate errors (because the parent paths are now wrong). Run it again and you get errors about moving the top ones to themselves, their children get renamed, but their grandchildren generate errors. Repeat again and the top two levels generate errors, the third is renamed, and the rest generate errors.
It's doing the same as koogy's approach, but dirtier. By limiting each run using -maxdepth he avoids the problem of the parent directory name changing when trying to rename the child, and he's specifying a file mask, where I'm just getting everything and assuming that the rename won't do anything surprising.
It does the job quickly enough for most cases. A more correct way to do it would be to get the files in reverse order (pipe the output of "find" through "tac", for example), then split off the rightmost component for renaming. That gets more involved, though, so I gave up
Re: The Official *nix Thread
Sorry in advance for the long post. I have attached ren.pl, written by a friend of mine. Copy, save, make executable, enjoy. Dunno if he's made it better these days, but it works.
Spoiler: show
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
- RageMatrix
- Baaaaaaa!

- Posts: 5515
- Joined: Fri May 10, 2002 12:52 pm 0
- XBL Gamertag: Jon256
- Location: East Sussex
Re: The Official *nix Thread
Cheers guys - works a treat.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
Re: The Official *nix Thread
the -depth flag to find will list the children before the parent.xav wrote:A more correct way to do it would be to get the files in reverse order (pipe the output of "find" through "tac", for example)
- JQW
- Baaaaa!

- Posts: 1186
- Joined: Thu Feb 22, 2007 12:23 pm 0
- Location: Ripon, where nothing ever happens.
Re: The Official *nix Thread
Be very careful when handling file names with spaces in them. I once managed to empty a whole directory by mistake as it matched the pathname of the directory I was working on right up to the first space, because I hadn't bothered to use double quotes.
- dom
- Baaaaa!

- Posts: 1370
- Joined: Wed Feb 09, 2005 1:17 pm 0
- Location: Edinburgh, UK and level 691859
- Contact:
Re: The Official *nix Thread
I tend to check using tab-complete when I'm manipulating files and directories from the commandline, just to see it put the "/" on the end of the directory name.
OMG (or oligodendrocyte myelin glycoprotein) is a molecule found in your central nervous system.
- JQW
- Baaaaa!

- Posts: 1186
- Joined: Thu Feb 22, 2007 12:23 pm 0
- Location: Ripon, where nothing ever happens.
Re: The Official *nix Thread
In my case I had a script for cleaning up the mess made by an application that liked to scribble over every directory it touched, creating both files and directories to store scratch files and other data. The script searched for these files, and then deleted them. The script worked fine the first few times I used it. Let's call this directory "scratch", simply because I can't remember its actual name.dom wrote:I tend to check using tab-complete when I'm manipulating files and directories from the commandline, just to see it put the "/" on the end of the directory name.
However I had a couple of directories with similar names, lets call them "Audio" and "Audio (Old format)", both off a drive mounted as External.
So when the application had scribbled inside "Audio (Old format)" my command to remove one of the scratch run by the script was:
rm -rf /mnt/External/Audio (Old format)/scratch
You can see what it ended up deleting instead! Thankfully I had backups.
- Dungeon-Dave
- Baaaaaa!

- Posts: 3925
- Joined: Thu Aug 04, 2005 12:01 pm 0
- Location: UK
- Contact:
Re: The Official *nix Thread
Anyone use LFTP as a client here?
Been using lftp for a bit now, and like it as a client due to nice inbuilt features and shell-like behaviour.
However, with my recent server I've noticed some strange behaviour with this client, mainly with obtaining directory listings. I can ftp into another server and perform a "dir" or "ls", but when changing directory both commands still show the old listing. Peculiarly, I can use TAB to auto-complete in a "cd" command and it will see that a different directory exists, but then refuse to change to that directory since the name doesn't exist in the (old) dir listing.
I solved this once by turning off caching and flushing it to force a re-read of the directory, but once it had obtained a listing it then stubbornly refused to update remote server listings.
This happens on one box running F9 with lftp3.6.3 - two other boxes running F8+lftp3.5.14 and F4+lftp3.2.1 are fine.
Oddly it only seems to do it over ftp: and ftps: connection to remote servers - sftp: connections are fine, working as expected.
Any ideas?
Been using lftp for a bit now, and like it as a client due to nice inbuilt features and shell-like behaviour.
However, with my recent server I've noticed some strange behaviour with this client, mainly with obtaining directory listings. I can ftp into another server and perform a "dir" or "ls", but when changing directory both commands still show the old listing. Peculiarly, I can use TAB to auto-complete in a "cd" command and it will see that a different directory exists, but then refuse to change to that directory since the name doesn't exist in the (old) dir listing.
I solved this once by turning off caching and flushing it to force a re-read of the directory, but once it had obtained a listing it then stubbornly refused to update remote server listings.
This happens on one box running F9 with lftp3.6.3 - two other boxes running F8+lftp3.5.14 and F4+lftp3.2.1 are fine.
Oddly it only seems to do it over ftp: and ftps: connection to remote servers - sftp: connections are fine, working as expected.
Any ideas?
- JQW
- Baaaaa!

- Posts: 1186
- Joined: Thu Feb 22, 2007 12:23 pm 0
- Location: Ripon, where nothing ever happens.
Re: The Official *nix Thread
Dunno, really. I do recall having similar problems with FTP clients in the past doing odd things like this - i.e. allowing logging in but denying the ability to change directories. I never really got to the bottom of it, but suspected an issue with a firewall's handling of FTP proxying at the time.
- stealthbanana
- Baaaaaa!

- Posts: 2805
- Joined: Wed Nov 09, 2005 11:59 pm 0
- Location: Over Here.
Re: The Official *nix Thread
I have not used an ftp client for ages. If I use a terminal, midnight commander does enough for me, but usually I just use nautilus. Just bookmark your ftp sites and they are mounted and usable just like normal disks. I am even so lazy I just sftp with it into other my other machines rather than setting up full networking (except when I use a windows machine, which is rare).
Not long now before lollipop men are called Darren
Re: The Official *nix Thread
i also use nautilus. or try to. i find whenever you try to create a new directory it fails which i think is a function of it using the name 'New Folder' for the new directory and the server choking on the space.
(seriously, whoever thought spaces in filenames were a good idea needs a slap)
so i end up just using ftp from the command line. tab completion? kids today don't know they're born...
(seriously, whoever thought spaces in filenames were a good idea needs a slap)
so i end up just using ftp from the command line. tab completion? kids today don't know they're born...
- Dungeon-Dave
- Baaaaaa!

- Posts: 3925
- Joined: Thu Aug 04, 2005 12:01 pm 0
- Location: UK
- Contact:
Re: The Official *nix Thread
That's what "lftp" is - command-line!koogy wrote:so i end up just using ftp from the command line. tab completion? kids today don't know they're born...
I like it since it can have bookmarked sites for quick recall, copes with ftps and sftp, and has scripting ability (lftp -f download.cmds) so I can schedule out-of-hours downloads.
This is only an issue I've encountered on one particular server, and it only seems to affect ftp/ftps connections, not sftp.
Just wondered if anyone else had encountered it at all. And if there's any other scriptable command-line ftp client alternatives people would like to suggest.
Re: The Official *nix Thread
I automate all my ftp processes with expect.
- Dungeon-Dave
- Baaaaaa!

- Posts: 3925
- Joined: Thu Aug 04, 2005 12:01 pm 0
- Location: UK
- Contact:
Re: The Official *nix Thread
"What's this Foxfire thing?"
http://linuxlock.blogspot.com/2009/11/l ... using.html
http://linuxlock.blogspot.com/2009/11/l ... using.html


