0
votes
2answers
68 views

Is it better to check if file exists before deleting it

Sometimes when I want to delete a file (from within a script), I will just delete it rather than checking if it exists first. So I do this: $ rm "temp.txt" 2>/dev/null Instead of this: [ -f ...
3
votes
1answer
112 views

Is there a scenario where rm -rf -no-preserve-root is needed?

I've seen some questions on here where people accidentally do rm -rf --no-preserve-root or rm -rf *, wiping out most or all of their file system before they can react. Is there ever a reason to use ...
2
votes
2answers
147 views

UNIX command for deleting / removing files on today's date

I want to remove all the files in the directory I am in currently in that were created today. So if today is April 3rd then the UNIX commond I am asking for would remove someFile2, someFile3, ...
16
votes
3answers
1k views

How can I remove a file or directory called “\”?

I'm using terminal on a Ubuntu machine and there is a file that I would like to delete. The file's name is \ (just a backslash). Now usually I would just do rm filename However if I do rm \ then ...
1
vote
1answer
71 views

Removing all directories in a given path with unix

I have a directory containing lots of files and lots of empty directories. I want to keep the files but remove the directories. How can I achieve this using rm and other standard unix tools?
2
votes
1answer
664 views

Is it possible to remove the root directory?

I noticed in the documentation for rm as obtained by rm --help the following flag: --no-preserve-root do not treat `/' specially What does this mean? Is it actually possible to delete the root ...
0
votes
2answers
175 views

How can I recover from mistaken 'rm *'?

I just typed rm * in the wrong directory by mistake. I had the wrong terminal window highlighted. What are my options?
8
votes
3answers
10k views

Can files deleted with rm -rf be recovered?

When I delete folders or files in through osx terminal using the rm -rf, where do they go? I heard that some say they are deleted directly, but some also say it only "remove the link to the file ...
2
votes
2answers
157 views

What is the point of UNIX's rmdir?

I'm new to UNIX (MAC OS X bourne shell POSIX), I understand rmdir will only remove an empty directory but under what circumstances would you actually want to use rmdir <directory name> and not ...
1
vote
2answers
843 views

How can delete all files except one from a directory?

I need to delete all files, except one (its name is defined), from a given directory. How can I do this from the terminal in OS X? Can I do this with one single command?
3
votes
3answers
5k views

Delete files with regular expression

I Tried to delete files that starts with A and ends with 2 numbers but It doesn't do a thing. What I tried: rm ^A*[0..9]2$ Where am I wrong?
7
votes
6answers
2k views

Best practices to alias the rm command and make it safer

Some time ago I erroneously deleted my home folder because I ran a rm -rf * on the wrong terminal, whose working directory was the home folder! I wish I had an alias for the rm command, but it was ...
20
votes
3answers
8k views

Does rm -f follow symbolic links?

I have a directory like this: $ ls -l total 899166 drwxr-xr-x 12 me scicomp 324 Jan 24 13:47 data -rw-r--r-- 1 me scicomp 84188 Jan 24 13:47 lod-thin-1.000000-0.010000-0.030000.rda ...
5
votes
3answers
969 views

Why is the dreadful 'rm -rf /' even allowed? [closed]

We all know the destructive power of the following command executed as root: rm -rf / Related questions: How far will you get with a 'rm -rf /' deleting everything: # rm -rf / I fail to ...
18
votes
4answers
656 views

Getting rid of a file called “-d” [duplicate]

Possible Duplicates: How do I delete a file named "-p" from bash? How to delete file with this name on linux: -]???????q Removing "-rf" file in Unix I've ...
2
votes
3answers
300 views

(Probably) trivial question about rmdir

I hope this isn't too trivial, but for some reason I can't get a simple command to execute. I'm writing a file manipulation script and I have several directories called test, test2, etc each ...
170
votes
8answers
8k views

How far will you get with an 'rm -rf /' command?

I've often wondered how far the system will actually get if you run rm -rf /. I doubt the OS would be able to erase itself (?) Bonus Question: After the command has been executed, will rm have ...
3
votes
1answer
512 views

When does rm remove open files?

Particularly, I want to know what happens when I rm an open file and don't explicitly kill the process holding the file descriptor to that file. Will the file be removed when the system is shut down?
9
votes
6answers
10k views

How to delete all but one file in Unix? [duplicate]

Possible Duplicate: How to delete all files in a directory except some? How to delete all but one(or some) file in Unix ? Something like rm -rf -ignore myfile.txt *
0
votes
4answers
5k views

How to remove file (which has white space in name) from Unix?

How to remove file (which has white space in name) from Unix?
2
votes
4answers
8k views

Remove all files except for a few, from a folder in Unix [duplicate]

Possible Duplicate: How to delete all files in a directory except some? I often face this problem. I have a set of files in a folder and would like to delete all of them except a few. For ...
1
vote
1answer
151 views

Removing files with strange names [duplicate]

Possible Duplicate: Unix: Files starting with a dash, - Somehow I ended up with a file named "-r". How do I remove it? rm -r doesn't work. I tried 'rm -i `ls -a`' to step through the ...
11
votes
5answers
13k views

use rm to remove files and directories recursively

is it possible to use rm to remove files and directories matching a pattern recursively without using other commands?