LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-01-2017, 03:05 AM   #1
chickenjoy
Member
 
Registered: Apr 2007
Distribution: centos,rhel, solaris
Posts: 239

Rep: Reputation: 30
normal rm vs rm -rf


Hello,

A colleague of mine insist on running rm -rf when he deletes at least a file (does not even have any directories). He said a redhat tech support told him that the -rf will permanently delete the file from the system. I don't see it in any manpage.

I know -r is recursive and -f is force and include directories to be deleted. are inodes affected?
 
Old 08-01-2017, 05:06 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,222

Rep: Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539Reputation: 2539
Your details on the options are correct. Rm takes what is given, rm -rf takes out the directory tree specified (i.e. the files, dirs, links & everything under them)matching the file spec.
What's available after an 'rm' command depends on the filesystem; vfat is recoverable, but ext4 filesystems have pretty poor recovery tools, and it's best to see deletion as permanent.
 
1 members found this post helpful.
Old 08-01-2017, 05:21 AM   #3
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 567

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
rm alone will not remove directories and rmdir alone will not remove non-empty directories. These commands on their own are the safe ones to use in your everyday life. The "-r" argument is used with rm when removing directories recursively. Some people use "rm -rf" so that no error messages are reported and everything is effectively removed.

But, generally it is considered dangerous to use "rm -rf" all the time. You might be using the command without thinking, and if ever this command is run as root on an inappropriate file/directory, it will be a catastrophe. As business kid said, it is extremely rare to be able to recover from "rm -rf" if it was used incorrectly.

So, stick to rm and rmdir. Only add arguments when you need them.
 
1 members found this post helpful.
Old 08-01-2017, 05:56 AM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I once ran rm -f without escaping a leading space followed by a wildcard character and it removed every file in the directory. There are no good Linux undelete tools, but foremost is a file carver that can recover files from Linux file systems. The only thing is it doesn't preserve the filenames and it recovers every deleted file it can find. So, finding the file you wanted to recover can be a chore.
 
Old 08-01-2017, 11:42 AM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,845

Rep: Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263
Me too. su'd to root, ran rm -f <paste>* - except the paste (right mouse click) didn't happen (sticky mouse button), so rm'd all files in /root/*
Fortunately, I had a daily backup to go to, but still...
I now am happy to answer "y" to each file to be removed ('cause alias rm='rm -i') rather than scramble to recover from a fat-finger issue.

Agreeing with others, don't use -r or -f routinely.
 
Old 08-01-2017, 11:54 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,938
Blog Entries: 13

Rep: Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970Reputation: 4970
Quote:
Originally Posted by chickenjoy View Post
Hello,

A colleague of mine insist on running rm -rf when he deletes at least a file (does not even have any directories). He said a redhat tech support told him that the -rf will permanently delete the file from the system. I don't see it in any manpage.

I know -r is recursive and -f is force and include directories to be deleted. are inodes affected?
I feel it's a very bad choice to generalize this type of command. Instead, pay attention to what you're doing when you issue a rm command. The explanation as attributed to a tech support person is incorrect.
 
Old 08-01-2017, 12:55 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143Reputation: 2143
Quote:
Originally Posted by chickenjoy View Post
He said a redhat tech support told him that the -rf will permanently delete the file from the system.
If a file is going to be deleted, it doesn't matter whether you used -rf or not, rm will delete it the same way with the same permanence. The -f flag keeps rm from prompting you if it has any questions, and the -r flag means it recursively deletes directories in addition to files, instead of just files. That's it. I don't know what he means by permanently deleting a file, as opposed to just deleting it. rm never uses any kind of "recycle bin" style setup, it will delete the file, but it could still be recovered off of the filesystem using a recovery tool. If you want to delete the file in a way that will prevent recovery, you need to use a completely different tool, such as shred.
 
Old 08-01-2017, 03:59 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,845

Rep: Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263
Quote:
Originally Posted by chickenjoy View Post
are inodes affected?
I see that none of us actually answered the only question you asked...

Yes. inodes are affected. In fact, inodes are all that's affected by the rm command...it simply removes the inode to effect a "file deletion" -- no inode, no file.
 
Old 08-01-2017, 04:19 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,804

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
Quote:
Originally Posted by scasey View Post
Yes. inodes are affected. In fact, inodes are all that's affected by the rm command...it simply removes the inode to effect a "file deletion" -- no inode, no file.
No, "rm" does not directly remove or clear the inode. All it does is remove the link from the directory, and that causes the link count in the inode to be decremented by 1. When the link count becomes zero and the file is not in use by any process, the kernel will then mark the inode as deleted and release any storage space claimed by that inode. The rm command issues the unlink() call. That is all.
 
1 members found this post helpful.
Old 08-01-2017, 05:22 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,845

Rep: Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263
Quote:
Originally Posted by rknichols View Post
No, "rm" does not directly remove or clear the inode. All it does is remove the link from the directory, and that causes the link count in the inode to be decremented by 1. When the link count becomes zero and the file is not in use by any process, the kernel will then mark the inode as deleted and release any storage space claimed by that inode. The rm command issues the unlink() call. That is all.
Point taken. I mis-read the reference I was looking at (and which I can't find again). I thought it said inodes were "created" and "deleted".

To your "not in use" point: I have experienced situations where someone rm'd a file as it was being created by a long-running process without affecting the process at all. It merrily continued to write to the file even though it could no longer be seen by ls, and its log indicated successful completion, but, of course, the file was gone and the job had to be re-run.

Still, the short answer to the OPs question is yes, even if I mis-explained it. Thanks for straightening us out.
 
Old 08-01-2017, 05:46 PM   #11
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
If you delete an open file, but the process that opened it is still running, you can recover the file from that process's entry directory in /proc, which is named after the PID. The file still exists in memory. You just have to copy it back to disk.

One of the great wonders of virtual file systems ...
 
2 members found this post helpful.
Old 08-01-2017, 07:33 PM   #12
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,845

Rep: Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263Reputation: 2263
Quote:
Originally Posted by AwesomeMachine View Post
If you delete an open file, but the process that opened it is still running, you can recover the file from that process's entry directory in /proc, which is named after the PID. The file still exists in memory. You just have to copy it back to disk.

One of the great wonders of virtual file systems ...
Good to know. Unfortunately we didn't know about the rm until after the process had completed. One of the hazards of several developers on a single dev machine. Needless to say, we didn't have access/authority to do those kinds of things in production. <sigh>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this normal ? yusufs Linux - Newbie 1 03-17-2008 08:21 AM
Is this normal? .nu Linux - Newbie 4 07-31-2006 12:39 PM
Is this normal..? phoenix99 Linux - Hardware 2 01-23-2005 01:59 PM
Is this normal? Daliz Linux - Newbie 2 02-10-2004 12:29 PM
is it normal uncle_fungus1 Linux - Software 3 11-22-2003 05:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration