Operating System - HP-UX
1833175 Members
2899 Online
110051 Solutions
New Discussion

Re: 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.

Bill Hassell
Honored Contributor

Re: Delete Folder without name

I did test the recommendation.

Here's the screen captures:

 

# stty
speed 38400 baud; -parity hupcl
intr = ^C; erase = ^H; kill = ^U;
swtch <undef>;
susp = ^Z; dsusp = ^Y;
brkint -inpck icrnl ixoff onlcr tab3
-iexten echo -echoe echok
-echoctl -echoke

# mkdir ^H
  (this was: mkdir \<bs>, the shell shows ^H)

# ll -db ?
drwxr-xr-x 2 root sys 96 Jun 12 13:24 \010

# rmdir ?
# ll -db ?
? not found

This was repeated on 10.20, 11.00, 11.11, 11.23 and 11.31, PARISC and IA systems.

One could also just rmdir -i ? in case there are several one-character directories.



Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: Delete Folder without name

> 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. [...]

 

   I must have been thinking of VMS, where the terminal driver deals
with this stuff, not the command-line interpreter (shell analogue).  On
a UNIX(-like) OS, the shell apparently does all the work.  Which is the
crucial fact.

 

> # mkdir ^H
>   (this was: mkdir \<bs>, the shell shows ^H)

 

   Exactly.  The _shell_ shows "^H".  You're just using the wrong shell.
Around here, for example, "\<bs>" can look like yours or mine,
depending:

 

dyi# /sbin/sh
dyi# ^H

 

   But:


dyi# /usr/local/bin/bash
dyi#

 

> This was repeated on [...]

 

   Yeah.   I tried it here on AIX, GNU/Linux (Debian), HP-UX, Solaris,
and Tru64, and I got the (my) expected result everywhere, too, but I use
"bash" everywhere.  (On HP-UX, the root user uses it only when it's
available, of course.)  So, perhaps neither of us is a complete moron,
after all.  (Or perhaps both?)

 

> > Everything's complicated.

 

   That remains true, I claim.

 

   For the record:

 

dyi# uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

Mat_Name
Occasional Contributor

Re: Delete Folder without name

Thank you very much for your information.

 

I tried but I failed ;-(

 

 

# rm -i *

Didn’t work, backslash-folder didn’t appear.

 

 

# rm -ir *

directory: ? (y/n) y

: ? (y/n) y

rm: directory not removed.  Directory not empty

 

 

# rmdir -i ?

?: ? (y/n) y

rmdir: ?: No such file or directory

 

 

# rmdir -i \^H

: ? (y/n) y

rmdir:: Directory not empty

 

(^H is my real backslash and not ^ and H)

 

 

 

PS:

# ll -ld ?
Is working. Sorry, I forgot question mark.

Bill Hassell
Honored Contributor

Re: Delete Folder without name

>> # rmdir -i \^H

>> : ? (y/n) y

>> rmdir:: Directory not empty

 

OK, there is something in the directory. rmdir just removes empty directories.

 

So this should work OK:

 

# rm -ir \<bs>

 

where <bs> is the backspace character. It will appear as ^H which is the shell's way of displaying the backspace.

 

If this still says directory not empty, let's see what is in that directory:

 

# ll -b \<bs>

 

There may other directories or files with bad characters.



Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: Delete Folder without name

>> The _shell_ shows "^H".  You're just using the wrong shell.

 

Actually, the vast majority of HP-UX systems run /sbin/sh as the root shell since this is the only functional shell in single user mode (archived libraries). If the root shell is changed to ksh, csh or BASH, the system will not have a usable shell in single user mode (a critical problem as single user mode usually means there is already a problem to solve). The rest of the users start with /usr/bin/sh (the POSIX shell, not Bourne), or may use chsh to change to /usr/bin/ksh. BASH is not part of the HP-UX distribution so it must be downloaded and installed -- assuming that data center policies allow open source tools like BASH. Where BASH is allowed, sysadmins will login as ordinary users with the BASH shell, then use sudo for root commands. Or they may simply run BASH after logging either with exec or as a child process. Supporting thousands of HP-UX servers in dozens of data centers, the standard tools (ie, POSIX shell, vi, etc) are always there. BASH has a number of useful features but availability to other data centers is not guarantied.



Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: Delete directory with backspace in name

>So this should work OK:  rm -ir \<bs>

 

Since this works, you could simply rename the directory:

# mv \<bs> better-name

 

And in ksh and sh and vi, you can use control-V before the backspace.