Deleting file named *

Hi, There is a file by name '*' in a hp-ux box. How can i delete the same?

-rw-r--r--   1 wleadm     dba           1531 Jul 24 08:49 *

need to delete this file named * without deleting any other file. Please help.

Escape the character to prevent shell interpolation

rm \*

Try the following.

-rw-r--r--    1 singh users             0 Jul 24 11:18 *
$
$ rm "*"

Thanks,
R. Singh

Another option is deleting using inode

Get the inode:

ls -il
 12048 -rw-rw-r--   1 yoda     xxxx             0 Jul 24 10:24 *
 12034 drwxrwxr-x   2 yoda     xxxx            96 Jul 24 10:24 ./
   435 drwxr-xr-x  21 yoda     xxxx          8192 Jul 24 10:24 ../

Remove using inode:

find . -inum 12048 -exec rm -f '{}' +

In bash, for example

set -f 

turns off globbing - the file-matching operation bash performs on metacharacters like * and ?

# remove a file named *
set -f
rm *
set +f

BTW - file names like * can screw up backup shell scripts and all sorts of other utilities. They are bad news.

1 Like

Thanks Jim for great command. It really helps.

For anyone bemoaning that their shell is not bash, set -f and set -o noglob (and their + counterparts) are part of POSIX sh, and are supported by at least ash, bash, busybox, dash, mksh, ksh, and pdksh.

Regards,
Alister

Hi Thanks to all. I'm working on HP-UX B.11.23. To be very precise i tried with inode based deletion and it worked
find . -inum 656 -exec rm -f {} \;
Also just to clarify, we can use this type of deletion even for files listed without any names i.e., blank file names. Right?

I didn't understand what exactly you mean by "blank file names". But I can assure you this approach will work for any file names.

Also, what works conveniently sometimes is to use filename name completion with the <TAB>-key in bash :

$ rm *<TAB>-key

changes the command line to:

$ rm \*

--
Or if it is the only single character file name in the directory:

rm ?