[comp.unix.questions] Help on file starting with a '~'...

jman@ICS.UCI.EDU (JIMMY MAN) (02/22/91)

    Hi netters!

Could some unix gurus out there help me in removing a file which the
name starts with a '~', such as ~filename?  Thanks a million!!!

jeenglis@alcor.usc.edu (A mutable language) (02/22/91)

jman@ICS.UCI.EDU writes:
>
>Could some unix gurus out there help me in removing a file which the
>name starts with a '~', such as ~filename?  Thanks a million!!!


Read The FAQ and Manual.



(But if you really must know, "rm \~filename" works from csh,
 "rm ~filename" works from the Bourne shell.)


--
   It would really be scary if we had a bunch of "Joe English"'s running 
         around insulting people and starting riots and the like.
                                     -- "Roger" "Rabbit"

             jeenglis@alcor.usc.edu // ignore this posting

jik@athena.mit.edu (Jonathan I. Kamens) (02/22/91)

In article <27513.667192135@ics.uci.edu>, jman@ICS.UCI.EDU (JIMMY MAN) writes:
|> Could some unix gurus out there help me in removing a file which the
|> name starts with a '~', such as ~filename?  Thanks a million!!!

  This is question number 2 on the Frequently Asked Questions posting which is
posted monthly to this newsgroup.  I've included the answer below.

  Before posting any more questions to this newsgroup, please read the FAQ
posting.  If it has expired at your site and you don't want to wait until it's
posted again (which should be in about two weeks), feel free to send me E-mail
and I'll send it to you.

  In any case, the answer below is a bit of overkill.  In the case of your
question, it's probably possible just to enclose the filename in single
quotes, or to put a backslash before the ~.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

2)  How do I remove a file with funny characters in the filename ?

    The  classic answers are

	rm -i some*pattern*that*matches*only*the*file*you*want

	which asks you whether you want to remove each file matching
	the indicated pattern;  depending on your shell, this may
	not work if the filename has a character with the 8th bit set
	(the shell may strip that off);
    
    and

	rm -ri .

	which asks you whether to remove each file in the directory.
	Answer "y" to the problem file and "n" to everything else.
	Unfortunately this doesn't work with many versions of rm.
	Also unfortunately, this will walk through every subdirectory
	of ".", so you might want to "chmod a-x" those directories
	temporarily to make them unsearchable.

	Always take a deep breath and think about what you're doing
	and double check what you typed when you use rm's "-r" flag
	or a wildcard on the command line;

    and

	find . -type f ... -ok rm '{}' \;

    where "..." is a group of predicates that uniquely identify the
    file.  One possibility is to figure out the inode number
    of the problem file (use "ls -i .") and then use

	find . -inum 12345 -ok rm '{}' \;
    
    or
	find . -inum 12345 -ok mv '{}' new-file-name \;
	
	
    "-ok" is a safety check - it will prompt you for confirmation of the
    command it's about to execute.  You can use "-exec" instead to avoid
    the prompting, if you want to live dangerously, or if you suspect
    that the filename may contain a funny character sequence that will mess
    up your screen when printed.

    If none of these work, find your system manager.