Help on file starting with a '~'...

Jonathan I. Kamens jik at athena.mit.edu
Fri Feb 22 15:13:14 AEST 1991


In article <27513.667192135 at ics.uci.edu>, jman at 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 at 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.



More information about the Comp.unix.questions mailing list