1833758 Members
2367 Online
110063 Solutions
New Discussion

Re: deleting directories

 
Donald Thaler
Super Advisor

deleting directories

System is hp ux 11i, in the /tmp directory there was a subdirectory u04 (/tmp/u04), and there is also a seperate directory /u04. When we attempted to delete /tmp/u04 the system removed the directory /u04. How could this have happened?
12 REPLIES 12
Bill Hassell
Honored Contributor

Re: deleting directories

It's really immportant to identify a directory before you remove it with bdf and the ll -d option. -d will not list the contents, but will show only the directory characteristics and most probably, /tmp/u04 was either mountpoint or a symbolic link. Look in /etc/fstab to see if /u04 is a mountpoint. If so, then /tmp/u04 was very likely a symbolic link and removing files by: rm -rf /tmp/u04/* would have actually been translated to: rm -rf /u04/...filenames...


Bill Hassell, sysadmin
RAC_1
Honored Contributor

Re: deleting directories

Is /tmp/u04 linked to /u04??
There is no substitute to HARDWORK
TwoProc
Honored Contributor

Re: deleting directories

It's bad practice I think, but you could have also (besides what Bill mentioned) had a directory from one file system actually mounted on an another. In other words /tmp could have been mounted with /tmp/u04 merely a subdirectory of /tmp. This could have been mounted as /u04 - leaving you with two paths to the same data. This would have been the result of something like "mount /tmp/u04 /u04 " - which, ugly as it - actually works, and can lead admins to accidently delete stuff they didn't want to...
We are the people our parents warned us about --Jimmy Buffett
Donald Thaler
Super Advisor

Re: deleting directories

Evidently /tmp/u04 was a symbolic link to /u04...How do we get rid of /tmp/u04 without eliminating /u04? How can we tell a subdirectory is a link? When i did the
bdf || -d it returned the same info as doing just bdf?
Geoff Wild
Honored Contributor

Re: deleting directories

rm /tmp/u04

that will remove link

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Kent Ostby
Honored Contributor

Re: deleting directories

You can test it backwards as well by doing.

mkdir /tmp/mytest
cp /tmp/mytest
mkdir /mytest
mount /tmp/mytest /mytest
ll /mytest
rm -r /tmp/mytest/*
ll /mystest

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Donald Thaler
Super Advisor

Re: deleting directories

What do the double pipe (||) symobls mean? And is there anyway of identifying the subdirectories as a symbolic link?
Greg OBarr
Regular Advisor

Re: deleting directories


I don't think that's a "double pipe". It's two lower-case Ls, as the abreviated version of "ls -l", or "ll". "ll" or "ls -l" will show you if it's a file, directory or link. As in:

# cd /testdir
# ll

lrwxrwxrwx 1 root sys 7 Apr 9 2004 backup_disk -> /backup
drwxr-xr-x 2 root root 96 Sep 22 1999 lost+found


In the above listing, "ll" shows that "backup_disk" is a link to /backup, as indicated by the "l" in "lrwxrwxrwx" and the "->" pointing to the link destination. "lost+found" on the other hand is a directory, as indicated by the "drwx..". If I run:

# rm -r backup_disk

It will delete the contents of /backup and remove the "backup_disk" link in /tmp. The /backup directory will still exist, but will be empty. This is likely what happened in your case.

-greg
Bill Hassell
Honored Contributor

Re: deleting directories

Two vertical bars: || in conjunction with a test means: take this branch if the result is false. For example:

[ ABC = xyz ] && echo true || echo false

A symbolic link is not in itself a directory or file but simply an alias to something. It could be pointing to a filename or to a directory or to nothing. That makes symlinks a bit tricky and they should be used with caution. To see a symlink, use ll -d . The reason to use -d is to prevent following the symlink and showing the contents of the link.

To find all the symlinks in a particular directory such as /tmp:

find /tmp -type l -exec ll {} \;


Bill Hassell, sysadmin
TwoProc
Honored Contributor

Re: deleting directories

Cool tip Bill - I'm adding that to my shell programming repertoire. Thanks.
We are the people our parents warned us about --Jimmy Buffett
Donald Thaler
Super Advisor

Re: deleting directories

I tried the ll and ll -d and the /tmp/u04 directory doesn't show up a linked directory?
The 'find /tmp -type l -exec ll {} \;' gives me an error 'find -type requires an argument'?
Bill Hassell
Honored Contributor

Re: deleting directories

The vertical bar | is very different than a lowercase l. Unfortunately, with the font used in the forums, the two characters are very, very similar. Rather than retype the find command, just copy-and-paste this line:

find /tmp -type l -exec ll {} \;

-type l means: locate links (l or the letter ell), and -exec means: run the folllowing command (ll or ell ell) where the name for ll is provided by the {} \; incantation.


Bill Hassell, sysadmin