Operating System - HP-UX
1748123 Members
3369 Online
108758 Solutions
New Discussion

Delete Folder without name

 
Mat_Name
Occasional Contributor

Delete Folder without name

Hi there,

 

a couple of month ago I created one folder without name (or renamed it?).

 

Big question: How could I rename or delete this folder?

 

Name of “folder without name” seems to be a backslash (BS).

 

Best wishes

15 REPLIES 15
Steven Schweda
Honored Contributor

Re: Delete Folder without name

> [...] folder without name [...]

 

> Name of "folder without name" seems to be a backslash (BS).

 

   Make up your mind?  If you can't decide whether it has a name or not,
then you might show an actual "ls" command with its actual output, so
that a reader could decide for himself.  Some other basic information
might also be helpful. For example:

 

      uname -a

 

   If the name really is "\", then consider the following:

 

pro3$ ls -l
pro3$ mkdir \\
pro3$ ls -l
total 0
drwxr-xr-x  2 sms  staff  68 Jun 11 13:05 \
pro3$ rmdir \\
pro3$ ls -l
pro3$

Bill Hassell
Honored Contributor

Re: Delete Folder without name

The folder (ie, directory) probably has one or more control characters in the name. You can use the -b option for ls to reveal the invisible characters in the name, or use xd to display the hex codes for each character:

 

# mkdir "\^G ab"

# ll -d *ab
drwxr-xr-x 2 root sys 96 Jun 11 18:51 \ ab

# ll -bd *ab
drwxr-xr-x 2 root sys 96 Jun 11 18:51 \\007 ab

# ll -d *ab | xd -xc
0000000 6472 7778 722d 7872 2d78 2020 2032 2072
         d r  w x  r -  x r  - x         2    r
0000010 6f6f 7420 2020 2020 2020 7379 7320 2020
         o o  t s  y s
0000020 2020 2020 2020 2020 2020 3936 204a 756e
                                  9 6    J  u n
0000030 2031 3120 3138 3a35 3120 5c07 2061 620a
           1  1    1 8  : 5  1   \ 07  a b \n
0000040

I made a directory with a backslash, then CTRL-G (the bell character), a space and then ab.

The CTRL-G is hex 07 and invisible when displayed normally. ll -db shows the non-printing character.

xd shows the invisible spaces as hex 20.

 

 You can now remove the directory by putting the filename in quotes and using the CTRL key to match the special character(s).

 

 



Bill Hassell, sysadmin
Mat_Name
Occasional Contributor

Re: Delete Folder without name

Thanks for your help!

 

I tried this commands (ll -db is not working on my HP UX)

 

 

 

# ll -b

drwxrwxr-x 3 root sys 96 Apr 30 19:38 \010



# ll | xd -xc

0000000  746f  7461  6c20  3538  320a  6472  7778  7277
         t  o  t  a  l     5  8  2 \n  d  r  w  x  r  w
0000010  7872  2d78  2020  2033  2072  6f6f  7420  2020
         x  r  -  x           3     r  o  o  t
0000020  2020  2020  7379  7320  2020  2020  2020  2020
                     s  y  s
0000030  2020  2020  3936  2041  7072  2033  3020  3139
                     9  6     A  p  r     3  0     1  9
0000040  3a33  3820  080a  2d72  2d2d  722d  2d72  2d2d
         :  3  8    \b \n  -  r  -  -  r  -  -  r  -  -

 

 

 

So my folder without name is "\010" (ll -b) or "\b" (ll | xd -xc).

 

How could I switch to this folder and remove it?

 

 

Best wishes

Steven Schweda
Honored Contributor

Re: Delete Folder without name

> How could I switch to this folder and remove it?

 

   Which do you want to do, "switch to" it or "remove" it?  To remove
it, the easy way is probably to use a command like:
      rm -i *
and say "yes" when the invisible name comes up.

 

> I made a directory with a backslash, then CTRL-G (the bell character), [...]

 

   In this case, \010 would be Ctrl/H, but that's a backspace, and with
typical stty settings, this may be interpreted as the "erase" character,
making it harder to use this trick. One could use something like:
      stty erase ^G
to make Ctrl/H less special, then:
      rmdir ^H         [really: rmdir Ctrl/H]

 

   Everything's complicated.

Bill Hassell
Honored Contributor

Re: Delete Folder without name

>> ll -db is not working on my HP UX

 

This isn't very helpful. Stating that something is not working is missing a very important part:

What is the exact command you used and what was displayed as a result? The -b option is working based on your later posting, so I assume that the -d option is causing some problem. Did your machine crash or did the shell abort, or did you get a usage message like this:

 

# ll -z
/usr/bin/ll: illegal option -- z
usage: ls -1ARadeCxmnlogrtucpFLbqisf [files]

As you can see in this usage message (and more importantly, the man page for ll), both -d and -b are valid.

I ran the ll -db filename command on a 10.20 version of HP-UX and it worked correctly. Based on the man page as well as empirically testing every version of HP-UX from 10.20 through 11.31, ll -d, ll -d -b, and ll -bd will always work correctly.

 

There is one other possibility: you are not running the ll command, but instead are using an alias. Use this command to see what ll actually does: type ll

 

=====

 

As far as your directory, you can't change (cd) into a directory and then remove it. The directory must not be open (busy) when you remove it. So from the xd listing, you have nothing but the backspace character (\010 in octal, 08 in hex) so you can remove the directory like this:

 

# rmdir "\010"



Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: Delete Folder without name

> [...] you have nothing but the backspace character (\010 in octal, 08
> in hex) so you can remove the directory like this:
>
> # rmdir "\010"

 

   Think again?

Steven Schweda
Honored Contributor

Re: Delete Folder without name

>       rm -i *

 

   Oops.  You need "-r" for a directory:

 

      rm -ir *

Bill Hassell
Honored Contributor

Re: Delete Folder without name

Oops, rmdir "\010" does not work. I was expecting the shell to expand the backspace character.

Since we know that the directory is exactly 1 backspace character, just use:

 

# rmdir \<bs>

 

where <bs> is the backspace character. The \ escapes the special meaning of the next character (backspace).

 

>> rm -ir *

 

Don't ever use rm -r unless you know exactly what will be removed. The -i option will start asking you about each file and directory and if you are currently in a big directory like /var or the most dangerous place to be, the / directory, the results could be catastrophic if you answer y at the wrong time.



Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: Delete Folder without name

> # rmdir \<bs>
>
> where <bs> is the backspace character. The \ escapes the special meaning
> of the next character (backspace).

 

   Think again?  If "stty -a" says "erase = ^H", then a backspace will
erase the previous character, which can easily be a backslash.  So long
as the terminal interface treats certain a character as special, the
shell won't see it.  Of course, if your erase character is something
else (like, say, "^?" = Delete), and "^H" = backspace is not used for
some other purpose, then you could be ok.

 

   In many cases, actually trying this stuff before posting it can be
valuable.

 

> Everything's complicated.

 

   Still true.