You are not logged in.

#1 2008-06-23 19:59:54

RAH
Member
Registered: 2008-06-20
Posts: 205

[SOLVED] File Naming

Hello,

I am about to setup rSync to backup my files to my server (also running Linux) and considering using the following script which renames files to lowercase and replaces spaces with under scores.  Coming from a Windows environment this is obviously a potential issue which may need resolved.

#!/usr/bin/perl -w
use strict;
use File::Find;

find(\&rename, ".");                   # search the current directory and all under it

sub rename {
    if (/[\sA-Z]/) {                       # if there are spaces or capital letters
        my $newname = lc($_);     # lowercase the filename
        $newname =~ s/\s+/_/g;   # replace all spaces with underscores
        rename ($_, $newname)     # rename the file or issue a warning
        or warn "Couldn't rename $File::Find::name to $newname: $!\n";
    }
    return;
}

Would you reccomend doing this, for organisation purposes etc or will it cause problems?  Or is it un-necessary?

Thanks.

Last edited by RAH (2008-06-26 16:28:40)

Offline

#2 2008-06-23 22:26:16

Zepp
Member
From: Ontario, Canada
Registered: 2006-03-25
Posts: 334
Website

Re: [SOLVED] File Naming

umm what exactly are you backing up? Seems kind of odd though to have a backup that is different then the original file/directory structure.

Offline

#3 2008-06-23 22:41:40

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: [SOLVED] File Naming

Zepp wrote:

umm what exactly are you backing up? Seems kind of odd though to have a backup that is different then the original file/directory structure.

No, the structure will match.  What I'm saying is - before I start backing up 20GB+ of files should I adjust the file structure for ease of use in a Linux environment?

Offline

#4 2008-06-23 22:50:11

Zepp
Member
From: Ontario, Canada
Registered: 2006-03-25
Posts: 334
Website

Re: [SOLVED] File Naming

RAH wrote:
Zepp wrote:

umm what exactly are you backing up? Seems kind of odd though to have a backup that is different then the original file/directory structure.

No, the structure will match.  What I'm saying is - before I start backing up 20GB+ of files should I adjust the file structure for ease of use in a Linux environment?

What I meant was the file names and directory names are no longer equal to the originals. Not only do you replace spaces with underscores, but more specifically you replace sequences of spaces with one underscore. So like "  " becomes "_" not "__" so you can't even go back to the original file names.

As for replacing spaces with underscores for in linux, I find it's a personal thing. I personally tend to use spaces, uppercase, and other symbols where I see fit. Some people like everything to be lower case a-z and no spaces.

Last edited by Zepp (2008-06-23 22:51:02)

Offline

#5 2008-06-23 23:50:23

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: [SOLVED] File Naming

In linux, any character is allowed in a filename except for "/". A lot of shells have tab-completion that will automatically escape shell metacharacters for you. This will likely cause more trouble than it will avoid.

Offline

#6 2008-06-24 00:30:17

vogt
Member
From: Toronto, Canada
Registered: 2006-11-25
Posts: 389

Re: [SOLVED] File Naming

Yeah, modern filesystems store pretty well any filenames, though your backup script might choke on special characters or spaces.

Specifically a shell script might expand a variable with spaces, resulting in the command reading multiple arguments, instead of one with spaces. So use double quotes. And test it.

Offline

#7 2008-06-24 01:40:24

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] File Naming

A filesystem/home directory with small and "clean" filenames is one built from the ground up and carefully planned. If you want to suddenly change everything you better be sure nothing is pointing to the wrong things (symlinks/scripts) and making a rename script that not only deals with a lot more odd filename characters and renames satisfactorily* in all cases instead of returning an error, but also takes care of all files that you will have in the future. So any time you get a new file it will automatically be renamed instead of manually having to run the script again.

And the more restrictive you make your solution the more you will hate it.

*even nicer would be if everything is ready to be typed in bash, i.e. everything starts with a few [a-z] characters that are unique.

Offline

#8 2008-06-24 01:54:46

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,230
Website

Re: [SOLVED] File Naming

RAH wrote:

No, the structure will match.  What I'm saying is - before I start backing up 20GB+ of files should I adjust the file structure for ease of use in a Linux environment?

No. rsync and Linux will handle it just fine. It's up to you if you want to choose to do it smile

Offline

Board footer

Powered by FluxBB