Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Deleting directory with leading hyphen in name Post 302981519 by edstevens on Wednesday 14th of September 2016 08:46:01 AM
Old 09-14-2016
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.

Code:
[root]# ls -li | grep p
2621441 drwxr-xr-x.   2 root root  4096 May  7  2015 cgroup
      3 drwxr-xr-x   19 root root  3700 Sep 14 07:11 dev
1572865 drwxr-xr-x. 101 root root 12288 Sep 14 07:11 etc
  11256 drwxr-xr-x    2 root root     0 Sep 14 07:11 misc
  11259 drwxr-xr-x    2 root root     0 Sep 14 07:11 net
2359297 drwxr-xr-x.   5 root root  4096 Aug 25 11:36 opt
1835010 drwxr-xr-x.   2 root root  4096 Aug 25 10:14 –p
      1 dr-xr-xr-x   96 root root     0 Sep 14 07:11 proc
1179649 dr-xr-x---.   2 root root  4096 Sep 14 07:23 root
      1 dr-xr-xr-x   13 root root     0 Sep 14 07:11 sys
 393217 drwxrwxrwt.   3 root root  4096 Sep 14 07:11 tmp
[root]# find . -inum 1835010
./–p
find: `./proc/3123/task/3123/fd/5': No such file or directory
find: `./proc/3123/task/3123/fdinfo/5': No such file or directory
find: `./proc/3123/fd/5': No such file or directory
find: `./proc/3123/fdinfo/5': No such file or directory
[root]# rmdir -- -p
rmdir: failed to remove `-p': No such file or directory
[root]# find . -type d -name '-p' -delete
[root]# ls -li | grep p
2621441 drwxr-xr-x.   2 root root  4096 May  7  2015 cgroup
      3 drwxr-xr-x   19 root root  3700 Sep 14 07:11 dev
1572865 drwxr-xr-x. 101 root root 12288 Sep 14 07:11 etc
  11256 drwxr-xr-x    2 root root     0 Sep 14 07:11 misc
  11259 drwxr-xr-x    2 root root     0 Sep 14 07:11 net
2359297 drwxr-xr-x.   5 root root  4096 Aug 25 11:36 opt
1835010 drwxr-xr-x.   2 root root  4096 Aug 25 10:14 –p
      1 dr-xr-xr-x   96 root root     0 Sep 14 07:11 proc
1179649 dr-xr-x---.   2 root root  4096 Sep 14 07:23 root
      1 dr-xr-xr-x   13 root root     0 Sep 14 07:11 sys
 393217 drwxrwxrwt.   3 root root  4096 Sep 14 07:11 tmp
[root]#
[root]# find . -inum 1835010 -exec rm -Rf {} \;
find: `./–p': No such file or directory
find: `./proc/3138/task/3138/fd/5': No such file or directory
find: `./proc/3138/task/3138/fdinfo/5': No such file or directory
find: `./proc/3138/fd/5': No such file or directory
find: `./proc/3138/fdinfo/5': No such file or directory
[root]#

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Deleting A Directory!

This must be simple! How do you delete a directory that contains other files and directories?:confused: (2 Replies)
Discussion started by: firefinger
2 Replies

2. Shell Programming and Scripting

Deleting the file only to all the directory and sub directory

I need the unix command or shell script to delete all the file in current directory and sub directory. (7 Replies)
Discussion started by: kingganesh04
7 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Excluding directory during deleting

Hi all, I'm trying to work on a script to delete files older then 31 day's in certain directories. Now, that works, but in one directory there are 3 other maps which contains files that can be deleted but one map which contains files that can't be deleted. My current command is: find... (6 Replies)
Discussion started by: JasperG
6 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Deleting a directory and zipping another directory

Hi Folks, I have a directory in unix that is /usr/local/pos contain the folowing directoreis ..that is dir1 dir2 dir3 now I want to delete only dir2 please advise how to remove the directory dir 2 ..that is rm command and how to use it , and second if I want to zip the dir3 please... (1 Reply)
Discussion started by: punpun66
1 Replies

8. Shell Programming and Scripting

Help deleting leading zeros in a file

I have a list of numbers extracted and need to delete the leading zeros from them, but when i do so, the command I am using also deletes numbers that end in Zero as well. eg 10, 20, 30, etc this is part of a larger script and the only way I can think of is to try and detect the 10,20 30 etc in... (19 Replies)
Discussion started by: kcpoole
19 Replies

9. UNIX for Dummies Questions & Answers

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". # ls -l / total 198 <snip> drwxr-xr-x 4 root root 4096 Dec 3 14:18 opt drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: edstevens
2 Replies

10. AIX

Deleting a Directory

I have a directory under my home directory called: my work. I cannot delete this directory and I want to. If anyone needs additional information. Please let me know. Any help you can provide is greatly appreciated. (8 Replies)
Discussion started by: Nerdgirl1313
8 Replies
SYSTEMD-VOLATILE-ROOT.SERVICE(8)			   systemd-volatile-root.service			  SYSTEMD-VOLATILE-ROOT.SERVICE(8)

NAME
systemd-volatile-root.service, systemd-volatile-root - Make the root file system volatile SYNOPSIS
systemd-volatile-root.service /lib/systemd/systemd-volatile-root DESCRIPTION
systemd-volatile-root.service is a service that replaces the root directory with a volatile memory file system ("tmpfs"), mounting the original (non-volatile) /usr inside it read-only. This way, vendor data from /usr is available as usual, but all configuration data in /etc, all state data in /var and all other resources stored directly under the root directory are reset on boot and lost at shutdown, enabling fully stateless systems. This service is only enabled if full volatile mode is selected, for example by specifying "systemd.volatile=yes" on the kernel command line. This service runs only in the initial RAM disk ("initrd"), before the system transitions to the host's root directory. Note that this service is not used if "systemd.volatile=state" is used, as in that mode the root directory is non-volatile. SEE ALSO
systemd(1), systemd-fstab-generator(8), kernel-command-line(7) systemd 237 SYSTEMD-VOLATILE-ROOT.SERVICE(8)
All times are GMT -4. The time now is 03:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy