1
vote
3answers
58 views

How do I delete a folder but not the contents?

My directory (in Linux) looks like com/com/{various,files} where com and com are folders of the same name and the second com holds the various files. I want the first com removed, but the second and ...
7
votes
1answer
109 views

Why are rmdir and unlink two separate system calls?

Here's something that kept me wondering for a while: [15:40:50][/tmp]$ mkdir a [15:40:52][/tmp]$ strace rmdir a execve("/usr/bin/rmdir", ["rmdir", "a"], [/* 78 vars */]) = 0 brk(0) ...
-2
votes
2answers
62 views

Getting a propmt when deleteing a non-directory

I want to get a prompt when attempting to delete a non-empty directory with rmdir. Is this possible?
0
votes
1answer
61 views

Delete ghost files with special characters

I have read several ways to delete files with special characters, but none of them works for me in one special folder in my cache system. I have no idea how the files got there, and why they turned ...
3
votes
5answers
76 views

How to find and empty some directories

I'd like to find and delete the contents while leaving the directories themselves intact. The following find /data1 -name MyTargetDir -type d -exec rm -rv {} \; and find /data1 -name ...
28
votes
8answers
2k views

How to delete this undeletable directory?

I untarred a corrupt tar file, and managed to end up with some directory that I can not delete, If I try to delete it, it seems like it can not be found, but ls shows it's present, both with bash and ...
1
vote
3answers
155 views

Removing a directory that has no files in it

I recently created a username and a group called gamesForAdmin. Since then I deleted it and the folder I made for it is still there: drwxr-xr-x 5 root root 4096 Jul 4 11:28 . drwxr-xr-x ...
2
votes
1answer
664 views

Delete files/ folders with .nfs files

A lot of time when I delete a folder, it says cannot be deleted because of .nfs files Error - Device or resource busy How can I delete a folder ignoring these errors ( is there any flag in rm ...
8
votes
1answer
1k views

Can rm recursively remove empty directories?

In an old version of Unix, the rm command would delete directories if they were empty. From the Research Unix Eighth Edition man page for rm: "If an entry is a directory it is removed only if empty." ...
3
votes
1answer
156 views

How can there be a directory named `~`?

I was trying to test out this buggy/new tool to see how it works, and it prompted me to choose a directory to use for stuff I am doing. From the directory ~/Code/indep, I typed in ...
1
vote
1answer
787 views

mount.cifs not respecting file permissions in Ubuntu 12.04.2 LTS

I am attempting to mount a cifs drive in standard Ubuntu 12.04.2 LTS using the following line in /etc/fstab: //server-name/share-name /mnt/archive cifs ...
3
votes
2answers
153 views

Preventing accidental directory deletion. Making an alias that contains options?

I use an alias to prevent me from accidentally deleting files, and I would like to do something similar for directories. For files, I have the following added to my .bashrc: alias rm="rm -i" I ...
0
votes
1answer
429 views

Find and remove sub-directories without error?

I need to find a way to remove sub-directories from within a particular directory without receiving an error if no sub-directories exist. This command will successfully remove sub-directories if they ...
6
votes
5answers
708 views

Making a directory protected from 'rm -rf'

I just lost some data in folder A which was inside folder B after doing rm -rf B. Before I could realize what have I done, it was all over. Now a lesson is learnt, I wish to make some of my folder ...
1
vote
8answers
136 views

remove content of directory in elegant way

I would like to remove all content of the current working directory. How to do it in efficient and elegant way? I have several files, directories and some of them starts with dot, like: touch .abc; ...
6
votes
3answers
4k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a ...
0
votes
2answers
2k views

Remove soft link but not the target

I have a directory that contains a link to another directory that I just created. I would like to remove the link but preserve the directory my link was pointing to. How do I do this? > mkdir rgac ...
3
votes
2answers
2k views

find flags: -exec rm -rf vs -delete

I thought the flags I mentioned in the question are the same, but I get the following message with the former, but nothing with the latter: $ find . -mindepth 1 -type d -exec rm -rf {} \; find: ...
3
votes
2answers
780 views

rm -fr not working

I have a directory that was generated by mistake by an application and this directory has a structure that involves more than 2000 directories, one inside a another, something like: Directory aaaa ...
5
votes
5answers
2k views

Delete all folders containing files which match pattern

I'm trying to delete all subdirectories of my current working directory which contain a rar file. My first attempt: find -name *.rar -exec rm -r {}/.. ';' failed because that is not a valid ...
3
votes
3answers
16k views

How can I delete all files with a particular extension in a particular folder?

If I set the current/working directory (navigating to it using cd) to some particular directory and then type: rm *.xvg What will this command do? Is it true that the above command will only delete ...
0
votes
1answer
576 views

OSX : rmdir “permission denied” but directory removed

This is a question from a newbie trying to learn UNIX commands. I was trying to test the rmdir command by removing a test directory located in my Downloads directory. I have read and write rights on ...
4
votes
3answers
388 views

Need to delete a directory with name '~' created accidentally

I don't remember exactly how this directory got created. It's name is ~, the alternative we all use for home diretory. I also see a sticky bit attached with this directory. How shall I delete it? I ...
2
votes
5answers
2k views

Unable to delete directory

On my OS X host, I am having trouble deleting the directory "foo". mymac:.Trashes joe$ ls foo mymac:.Trashes joe$ ls foo/ Ảnh011.jpg Ảnh012.jpg Ảnh013.jpg mymac:.Trashes joe$ ls -l foo/ ls: ...
5
votes
1answer
3k views

mv file without write permission to the source file

I just realised that I can move a file that I do not own and don't have write permissions on. I have write permissions to the directory, so I am guessing that is why I could move it, but in this ...
3
votes
4answers
1k views

Accidental deletion of /lib directory in Fedora 15

I accidentally deleted the /lib directory on my Fedora 15 machine and I'm not sure how to go about fixing this. Any help in figuring out how to restore the directory along with symbolic links would be ...
1
vote
3answers
2k views

Removing a directory hangs

I'm a non-root user on a shared compile server that mounts /home via NFS from some other host. I have a directory ~/a/b with lots of subdirectories c1,c2,.... I wanted to delete ~/a/b completely, and ...
1
vote
3answers
2k views

shell commands to check & create dir

I am writing a Ruby script inside which I would like to invoke/execute some shell commands. The shell commands I would like to run should check if a directory named 'tmp' under /var/lib/mysql/ exists ...
6
votes
6answers
1k views

Remove empty directory trees (removing as many directories as possible but no files)

Suppose I have a dir tree like this: ROOTDIR └--SUBDIR1 └----SUBDIR2 └----SUBDIR3 I am looking for a command such that when I input: $ [unknown command] ROOTDIR The whole ...
3
votes
1answer
917 views

Prevent a subdirectory from getting deleted / enforce a directory structure

imagine the following folder structure ../documents ../documents/templates I have two user groups: editors managers Users of both groups should be able to create new files modify any ...
16
votes
3answers
6k views

Is there any way to prevent deletion of certain files from user owned directory?

Let's say user has Directory1 and it contains File1 File2 CantBeDeletedFile How to make so the user would never be allowed to delete the CantBeDeletedFile? If I change the ownership of Directory1 and ...
8
votes
6answers
29k views

How to remove all the files in a directory?

I am trying to remove all files and subdirectories in a directory. I used rm -r to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself. For ...
19
votes
3answers
4k views

How to remove all empty directories in a subtree?

How can I remove all empty directories in a subtree? I used something like find . -type d -exec rmdir {} 2>/dev/null \; but I needs to be run multiple times in order to remove directories ...