How get rid of funny characters in filenames?
I am rescuing files from a Linux partition onto an USB drive using an Ubuntu live CD. Some of the files have funny characters in them (due to the fact that they reside on a Swedish machine). Ubuntu gets upset and tells me it cannot create those files on the target drive due to those characters. I can only access the partition where the files are as root. My knowledge of Linux is limited (in particular on the command line), so I would need and appreciate some assistance. I have tried using cp, rename and mv, but all of them complain about the characters. What to do?
Bengt |
Here is my feable attempt at a solution. My perl is not very good, so this may not work and I can't test it till I get home. Save the following script as replace_funnies
Code:
#/usr/bin/perl Code:
chmod +x replace_funnies You run the script like this Code:
perl replace_funnies infile outfile Right now it is replacing anything that is not A-Z, a-z, 0-9, ., ?, or !. You can add other characters that you don't want to replace by changeing the s/// line. For example to add ( and ) change it to Code:
$line =~ s/[^\w\s\n\.\?\!\(\)]//; |
Fixed it up a bit here you go:
Code:
#/usr/bin/perl |
Thank you. I just had a look around. The Ububtu system does not include Perl. Sorry.
|
Sorry, I was wrong. I typed your program into a file and made it executable. When I ran it, it gave me the complaints:
" line 3: =: command not found line 4: =: command not found " Could it be the "shift" statement it doesn't like. What does it do? I checked the contents of my file against your original and couldn't find any diffs. |
Probably means you don't have perl installed. Surely ubuntu has perl, its a very common scripting language in linux. Have you looked for it with the synaptic package manager? Do you have your package repositories set up correctly? Post the output of
Code:
cat /etc/apt/sources.list |
It looks like there is some kind of Perl installed after all - if I run the script without arguments, it runs the "die" statement so I get the error message correctly. Here is the output from the sources.list:
" deb http://archive.ubuntu.com/ubuntu hoary main restricted deb-src http://archive.ubuntu.com/ubuntu hoary main restricted " then there is a commented message regarding support and things. It says that if I want to add software from the "universe" depository, I should uncomment the two commented lines following. Then comes this: " # deb http://archive.ubuntu.com/ubuntu hoary universe # deb-src http://archive.ubuntu.com/ubuntu hoary universe deb http://security.ubuntu.com/ubuntu hoary-security main restricted deb-src http://security.ubuntu.com/ubuntu hoary-security main restricted " That's it. It doesn't make much sense to me. I took a look at the URLs listed, but found nothing much. Now, there might be a problem. I'll try to make the story short. I was running Mandriva 2006 and tried to upgrade KDE to 3.5, and, apparently, deleted too much of the 3.4 I was running. I couldn't because the root partition was full. Threfore I ended up without the graphical interface. I think the only way I can get it up and running again is to re-install the entire system with a different set of partitions, but before that I'd like to salvage the work I have done. Now, some of the files have Swedish characters in their names, and will therefore not be copied onto the USB drive (as you know). This is the reason I run the Ubuntu system - not to disturbe the /home partition, which I might have if I had re-sized the root partition. There is also an empty partition that I would like to include or simply use as the root. It is big enough. That is a different problem, though. |
Something just occurred to me - would there be another live CD distro around which could copy files with funny characters? I have a Knoppix CD and a College CD. Would they be live distros?
|
Lets try to configure your locales so that you can see those funny characters. First we need to enable root login cause ubuntu doesn't allow it by default.
Code:
sudo passwd root Code:
dpkg-reconfigure locales I couldn't tell from your previous post if your x window system is broken or not. You also mentioned something about KDE, but ubuntu uses gnome. |
Yeah, I was using KDE in the original Mandriva installation.
I read the Knoppix homepage and found that they appear to specialise in live CDs only, so I took mine and ran it. It works fine, and has got a KDE desktop. I managed to copy the "funny" files too without problem. Then I tried your dpkg command with no success. Both Ubuntu and Knoppix have a "root terminal" which does not require a password (funny, though not really safe). The USB drive is automatically mounted and display an icon on the desktop. In Knoppix it is mounted as a read-only device. To enable me to copy the files, I had to open the root terminal, unmount the drive and then mount it again to make it writable. Since neither system allow a non-root user to enter the subdirectories of /home, I had to stay as a root. Then "cp -r *" did the trick. The only problem it had is a directory called "Why?", and I can understand that. It i okay, though, because I have it on a CD and I know it has not been touched since. Thanks a lot for your assistance. Much appreciated. |
Ubuntu does not allow direct root login. You have to use sudo, which in my opinion is a silly. That is probably why you could not reconfigure the locales. Not sure what your "root terminal" is, but I doubt if it actually gives you root priveleges. That would be a serious security risk, and would completely defeat the purpose of making you use sudo. Anyway, glad you got it worked out. You should still be able to use the commands above (at least in ubuntu) to get your locales set up once you get to be root.
|
Well, with the Ubuntu system I was able to copy the files with only the 25 English characters in their names from the "root terminal". I used Knoppix for the rest of the files. I now have all files I wanted on the USB disk. At desktop level I had no access to /home OR the USB-drive, which I had in the "root terminal". Wello, the main thing is that I managed to rescue the files.
|
All times are GMT -5. The time now is 06:40 AM. |