bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to remove files named "!!!foo"? (Re: help)


From: Bob Proulx
Subject: How to remove files named "!!!foo"? (Re: help)
Date: Fri, 27 Jan 2006 09:33:10 -0700
User-agent: Mutt/1.5.9i

Hao Truong wrote:
> How can I remove file listed below ?:
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111111111111111111111111111111111111111111111111111111111111111111111111111111111111

With the name of this file it is probably a problem with your shell.
The '!' character in csh expands to a history argument.  Other shells
such as bash also provide csh like functionality.

  touch '!!!foo'
  rm !!!foo
  bash: !foo: event not found

Probably you need to quote the filename.  It depends upon your shell
and without knowing that it is only possible to guess.

Here is an example.  I create a fliename with '!' characters in it and
then remove it.  Yours is probably similar.

  touch '!!!foo'
  ls -l '!!!foo'
  -rw-r--r--  1 bob bob 0 2006-01-27 09:14 !!!foo
  rm '!!!foo'
  ls -l '!!!foo'
  ls: !!!foo: No such file or directory

Several tricks exist for dealing with filenames with unusual
characters.  One is to use 'rm -i *'.  This will prompt before
removing files.  Select yes for the file you want to remove and no for
all other files.  Here is an example:

  mkdir /tmp/a
  cd /tmp/a
  touch '!!!foo' abc xyz
  ls -l
  total 0
  -rw-r--r--  1 bob bob 0 2006-01-27 09:17 !!!foo
  -rw-r--r--  1 bob bob 0 2006-01-27 09:16 abc
  -rw-r--r--  1 bob bob 0 2006-01-27 09:16 xyz
  rm -i *
  rm: remove regular empty file `!!!foo'? y
  rm: remove regular empty file `abc'? n
  rm: remove regular empty file `xyz'? n
  ls -l
  total 0
  -rw-r--r--  1 bob bob 0 2006-01-27 09:16 abc
  -rw-r--r--  1 bob bob 0 2006-01-27 09:16 xyz

Another trick is to use a modern shell such as bash that does filename
completion upon TAB.  Allow the shell to expand the filename.  Here is
an example where "TAB" means I enterred a tab character.  Then shell
then acted upon that and completed the filename.

  touch '!!!foo'
  rm !TAB
  rm \!\!\!foo

Upon TAB the bash shell will replace the "!" with the filename
expansion with individual characters quoted as needed.  This reveals
that there are several different ways to quote shell metacharacters.

Emacs users will often use the Emacs directory editing features for
this process.  In emacs edit the directory.  Then use the dired
commands to delete files and directories.  'D' to mark the file for
deletion and then 'x' to execute the operation.  The emacs code will
quote the filenames properly for th shell and so the user can remove
files with unusual names in the Emacs dired mode without needing to
know the shell file quoting conventions.

> Subject: Re: help

A subject such as "help" is really a terrible subject.  It is too
generic.  Many people would never even read the message!  Can you
imagine a mailbox where many messages are all "help" or "bug"?  It
does not help the person trying to help you.  In the future you will
have much better results if you select a good subject for your
message.  In this case something like "How to remove files named
!!!!FOO?" or "rm !!!FOO fails" or something like that would be much
better.  Pick something representative of the topic but as concise as
possible.

Hope this helps,
Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]