Removing directory with leading hyphen from root directory


 
Thread Tools Search this Thread
# 1  
Removing directory with leading hyphen from root directory

I know that this basic question has been asked many times and solutions all over the internet, but none of the are working for me. I have a directory in the root directory, named "-p".

Code:
[root@vbpsdev /]# ls -l /
total 198
<snip>
drwxr-xr-x   4 root   root      4096 Dec  3 14:18 opt
drwxr-xr-x   2 root   root      4096 Dec  2 14:09 p
dr-xr-xr-x 129 root   root         0 Feb  4 08:33 proc
<snip>

Several different variations on trying to delete it.

Code:
[root@vbpsdev /]# pwd
/
[root@vbpsdev /]# rm /-p
rm: cannot lstat `/-p': No such file or directory
[root@vbpsdev /]# rmdir /-p
rmdir: /-p: No such file or directory
[root@vbpsdev /]# rm -fR -- -p
[root@vbpsdev /]# ll
<snip>
drwxr-xr-x   4 root   root      4096 Dec  3 14:18 opt
drwxr-xr-x   2 root   root      4096 Dec  2 14:09 p
dr-xr-xr-x 129 root   root         0 Feb  4 08:33 proc

Try to remove by inode. First, find the inode
Code:
[root@vbpsdev /]# ls -li
<snip>
1702273 drwxr-xr-x   4 root   root      4096 Dec  3 14:18 opt
1767745 drwxr-xr-x   2 root   root      4096 Dec  2 14:09 p
      1 dr-xr-xr-x 129 root   root         0 Feb  4 08:33 proc

Then use 'find' for a 'rm', first, use an 'ls' instead of 'rm', to confirm what the 'find' finds

Code:
[root@vbpsdev /]# find . -inum 1767745 -exec ls -li {} \;
find: ./proc/5734/task/5734/fd/4: No such file or directory
find: ./proc/5734/task/5734/fdinfo/4: No such file or directory
find: ./proc/5734/fd/4: No such file or directory
find: ./proc/5734/fdinfo/4: No such file or directory
total 0

# 2  
I suspect it's named -p\n or some other such garbage or else you'd have been able to remove it with rmdir /-p.

If it's an empty folder, ls -li won't show anything. -d tells it to show the folder itself instead of its contents.

Use -xdev to prevent it from leaving the root partition (and avoid those errors).

Many commands will accept -- to mean 'treat everything after this as an argument, not a flag' in case ls decides to consider it as the 'indicator style' option instead of an argument.

Code:
find . -xdev -inum 1767745 -exec ls -lid -- {} \;

This User Gave Thanks to Corona688 For This Post:
# 3  
Took a couple of tries to get the perfect combo, but that was it.

Code:
[root@vbpsdev /]# find . -xdev -inum 1767745 -exec ls -lid -- {} \;
1767745 drwxr-xr-x 2 root root 4096 Dec  2 14:09 ./p
[root@vbpsdev /]# find . -xdev -inum 1767745 -exec rm -- {} \;
rm: cannot remove `./p': Is a directory
[root@vbpsdev /]# find . -xdev -inum 1767745 -exec rmdir -- {} \;
find: ./p: No such file or directory
[root@vbpsdev /]# find . -xdev -inum 1767745 -exec rm -fR -- {} \;
[root@vbpsdev /]# ll
<snip>
drwxr-xr-x   4 root   root      4096 Dec  3 14:18 opt
dr-xr-xr-x 123 root   root         0 Feb  4 08:33 proc

Thanks for the assistance.
This User Gave Thanks to edstevens For This Post:
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #288
Difficulty: Easy
In Linux, Logical Volume Manager (LVM) is a device mapper target that provides sound card I/O management for the Linux kernel.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Beginners Questions & Answers

Deleting directory with leading hyphen in name

I asked this question last month in Stack Exchange (linux - delete directory with leading hyphen - Server Fault) and none of the answers supplied worked. I have somehow created a directory with a leading hyphen and cannot get rid of it. # ls -li | grep p 2621441 drwxr-xr-x. 2 root root... (4 Replies)
Discussion started by: edstevens
4 Replies

3. Shell Programming and Scripting

Removing hyphen from beginning and end of a word only.

It is very simple to remove a hyphen from a word anywhere in that word using a simple sed command (sed -i 's/-//g' filename), but I am not able to figure out how to do this: For example, apple -orange tree pipe- banana-shake dupe- What my output should look like: apple orange tree... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

how to remove leading directory from line in filename?

i have a process that receives files similar to below. these are files obviously generated on a windows machine that are submitted to a linux cluster. the one thing they have in common is the leading c:\any-number-of-leading-dirs\filename.xxx. is there a way to re-create/modify the file to remove... (3 Replies)
Discussion started by: crimso
3 Replies

5. Shell Programming and Scripting

Untar specific directory and strip leading directories

Ok so I know the title was probably confusing so here goes: I have a tarball (gzipped) that has a nested directory structure . For example: my.tar.gz (contents) --- ------ --------- ------------ --------------- ... (2 Replies)
Discussion started by: DC Slick
2 Replies

6. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

7. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

8. UNIX for Dummies Questions & Answers

removing the files but not the directory

How would i rmeove all the files in the directory but still keep the directory? (5 Replies)
Discussion started by: JamieMurry
5 Replies

9. Filesystems, Disks and Memory

Removing a file from a directory

How do you remove a file named '-'? ('rm' does not work) (5 Replies)
Discussion started by: npatel
5 Replies

10. UNIX for Dummies Questions & Answers

removing a directory

all - I'm trying to delete this directory with no success. This was placed in my folder by a test script I wrote for beginners... drwxr-xr-x 2 myaddress ssusr 512 Dec 22 16:10 $x+1 Here is the message I receive - I've tried every command possible to remove it: rmdir:... (7 Replies)
Discussion started by: da_curtain
7 Replies

Featured Tech Videos