[Novalug] Two files with the same name: Hunh?!

jecottrell3 at comcast.net jecottrell3 at comcast.net
Thu Jan 15 18:33:23 EST 2009


Cool! However, tcsh still seems to rely on external commands...another knock against it.

While pedantry may be of use in real programming languages, scripts are supposed to be quick, if not dirty, so a little implicit boolean conversion doesn't bother me in this context.

JIM

----- Original Message -----
From: "Jon LaBadie" <novalugml at jgcomp.com>
To: novalug at calypso.tux.org
Sent: Wednesday, January 14, 2009 5:50:00 PM GMT -05:00 US/Canada Eastern
Subject: Re: [Novalug] Two files with the same name: Hunh?!

If you execute /bin/{true|false} you are correct that a separate
program will be executed.  However, bash, ksh93, and zsh all
have true and false as builtin commands just like :.

> Using arithmetic, "if ((n)); then cmd; fi" and "while ((n)); do cmd; done" commands actually look better.
> 

Some would say the C-style of if ((n)) is too cryptic.
They would prefer something like if ((n != 0)).

jl
> JIM
> 
> ----- Original Message -----
> From: "Jon LaBadie" <novalugml at jgcomp.com>
> To: novalug at calypso.tux.org
> Sent: Wednesday, January 14, 2009 1:29:28 PM GMT -05:00 US/Canada Eastern
> Subject: Re: [Novalug] Two files with the same name: Hunh?!
> 
> On Wed, Jan 14, 2009 at 04:17:40PM +0000, jecottrell3 at comcast.net wrote:
> > Dear Friends,
> > 
> > What do you do if you have files with characters you can't type and you don't want to write a program or script? if there is only one name that matches the pattern, simply use '?' for the unprintable character: mv a?b newname
> > 
> > 
> >  Suppose you have two filenames that match the pattern 'a?b'. Link them into different directories and selectively remove them with rm -i.
> > 
> > $ mkdir 1 2
> > $ ln a?b 1
> > $ ln a?b 2
> > 
> > $ cd 1
> > $ rm -i a?b
> > rm: remove regular file 'a?b'? n
> > rm: remove regular file 'a?b'? y
> > $ mv a?b file1
> > 
> > $ cd ../2
> > $ rm -i a?b
> > rm: remove regular file 'a?b'? y
> > rm: remove regular file 'a?b'? n
> > $ mv a?b file2
> > 
> > $ cd ..
> > $ ls -il a?b 1 2
> > 
> > $ rm a?b
> > $ mv 1/* 2/* .
> > $ rmdir 1 2
> > 
> > The -i option displays the inode numbers, so you can verify which file is which. With 3 or more files, there is more work to do, but the same principle applies.
> 
> 
> Your solution got me thinking about renaming the files.
> If you have a pattern that matches all the alternative
> "duplicate" file names you could rename them with a
> for loop from the command line.  The code below would
> rename them file1, file2, ...
> 
>   $ n=1
> 
>   $ for f in <your_pattern, e.g. a?b>
>   > do
>   >   mv "$f" file$n
>   >   n=$((n+1))
>   > done
>   $
> 
> Jon

-- 
Jon H. LaBadie                  jon at jgcomp.com
 JG Computing
 12027 Creekbend Drive		(703) 787-0884
 Reston, VA  20194		(703) 787-0922 (fax)
_______________________________________________
Novalug mailing list
Novalug at calypso.tux.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug



More information about the Novalug mailing list