Anyone ever actually tried 'rm -rf /*' in Linux? [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Anyone ever actually tried rm -rf /*, or something similar, in Linux? You always hear people joke about it, but I'm curious if it actually executes, and if so, what kind of damage it actually does (not in terms of deleting disk).

Just for you, I tried it. I got a whole bunch of "rm: cannot remove ...", even with sudo. If you would like to try it out, I recommend VirtualBox and a copy of Ubuntu.

Have I "tried" it? No. Have I done it? Yes, and it's bad. However, if you're lucky:
You weren't logged in as root, so the damage will be minimal
You've installed safe-rm which will prevent stuff like this.

Yes, I did, but only in a VM that could be reverted, just to test and demonstrate (I used to teach OS).
In older distributions it will execute and wipe out your distribution, but in most newer distributions this will fail.
If you want to try, do it in a place you don't care about, or in a VM that you can revert like me.

Wikipedia : rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters[2] . The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of nearly every writable mounted filesystem on the computer to be deleted, up to the point the system itself crashes from missing some crucial file, directory, or the like.
http://en.wikipedia.org/wiki/Rm_(Unix)
I think some distros added a protection.
EDIT : muffinista gave the link to the protection.

Related

mv confusion: I deleted /usr/local/bin by following the socketxp guide, but only the first time around [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
Improve this question
I was following the SocketXP Agent Download & Setup, and on the very first step I am asked to run the following command:
curl -O https://portal.socketxp.com/download/linux/socketxp && chmod +wx socketxp && sudo mv socketxp /usr/local/bin
This was followed by some confusion, becuase the bin-folder now appeared to be an executable. It turns out that rather than inserting socketxp into the /usr/local/bin folder, I actually deleted the whole folder and replaced it with the socketxp file, now renamed to a file called bin.
However, after recreating the folder, I see I can transfer test files into it without issues with
~touch test
~sudo mv test /usr/local/bin
So after seeing this, I re-ran the same socketxp installation command, and this time around it worked fine.
I'm at a loss as to what the original problem was, but I am very interested in not having this happen again. I suspect I am missing some basic mv knowledge. Grateful for any tips and pointers that can explain for me what caused the issue
I was doing this on a 64-bit Linux SIMATIC controller from Siemens, which runs an OS based on Debian.
I am asked to run the following command:
curl -O https://portal.socketxp.com/download/linux/socketxp && chmod +wx socketxp && sudo mv socketxp /usr/local/bin
This was followed by some confusion, becuase the bin-folder now
appeared to be an executable. It turns out that rather than inserting
socketxp into the /usr/local/bin folder, I actually deleted the whole
folder and replaced it with the socketxp file, now renamed to a file
called bin.
Not plausible. When the destination path in a mv command is a directory, the source file(s) are moved into that directory (unless that is overridden by a command-line option). This is consistent with what you observed in subsequent experiments.
However, if only one source is given and the destination path either does not exist (but its parent directory does) or designates a regular file, then mv renames the source to the destination. We can only guess about what actually happened, but my first guess would be that /usr/local/bin did not initially exist. That might have arisen because of an earlier error, such as executing rm -rf /usr/local/bin when you really meant rm -rf /usr/local/bin/*, or perhaps the machine just came that way.
In Linux you can use mv also to rename files. To prevent a mistake like yours, always add a / at the end of a path that you want to move something into:
sudo mv test /usr/local/bin/
This would have behaved as you expected and put the file test into the folder /usr/local/bin.
As #JohnBollinger stated, the behaviour to expect would be that mv moves files into an existing folder if you do not explicitly tell it that the last parameter is NOT a directory.
In your case it could have been that /usr/local/bin simply didn't exist when you executed your command. In this case the variant with the appended / would have emitted an error message. Or you accidentally specified the option -T (maybe intended for some other command or a copy-paste-mistake?)

Linux - I ve chmoded all my server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have made a big mistake in a wrong command and ended up chmoding 777 all my server.
Result is no service want to start because of writable files.
Is there a way to fix this like a default restore without loosing my database/files?
PS: I m on centos 64 bit
PS2 I can t access ssh on my server but I still have webmin access so I can execute command from it
Reinstalling is probably the only way to be sure... but google shows
google: rpm set file permissions
http://www.cyberciti.biz/tips/reset-rhel-centos-fedora-package-file-permission.html
RPM syntax to fix permission
To set permissions of files in a package, enter:
rpm --setperms {packagename}
Reset the permissions of the all installed RPM packages
and
You need to use combination of rpm and a shell for loop command as follows:
for p in $(rpm -qa); do rpm --setperms $p; done
That should fix a lot. ... but only files from a package. Other data... search for files with mode 777 and figure out what you need. For most maybe chmod o-w FILE would work. It's risky, it doesn't restore the permissions, but only changes them.
find / -perm -777 -exec chmod o-w {} \; # There are faster ways using xargs

Keeping a copy of a file in a same directory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am working on linux scripts , Assume that the directory is consisting of these following scripts .
ls *.sh
test.sh
MyScripts.sh
My question is , before making any modifications to test.sh script , i want to keep a backup copy of it , so that if anything messes up , i will be not screwed up .
please tell me how can i keep a copy of test.sh in the same directory ?? before making any modifications to the actual file test.sh .
Thank you very much .
Consider using revision control, such as git or Subversion.
You can make a copy before your work too:
cp test.sh test.sh.orig
The usual approach is to
cp test.sh test.sh~
(or test.sh.bck or whatever naming convention). In fact, any decent editor should have an option to do this automatically for you. Vim does it by default (saves a backup name filename~ on modification)
May I heartily suggest a version control solution for this purpose instead?
Good 'starter' options include:
bazaar
mercurial
I personally vouch for git.
I took care to name (D)VCS methods that have ample interoperability options so as to prevent data lockin.
cp test.sh test.sh.`date +"%m_%d_%Y"`
Will make a timestamped backup named test.sh.10_10_2011

Lost my file in linux [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
In linux terminal, I accidentally mistyped
sudo mv myfile.zip /~
My purpose was to move under the home folder but it was not there.
Although I tried to find it by both
sudo find / -name 'myfile.zip'
and
sudo locate myfile.zip
could not find it. Where it can be?
Thanks in advance.
You might be surprised to find a file named ~ right under /.
It's called /~. That's a perfectly valid filename (remember, shell only expands ~ at the * beginning* of a path and you typed it in the middle, so the shell left it at that).
You moved it to /~ --- it is at root and named ~.
Your file is now no longer named myfile.zip, but ~. You should find it exactly where you told it to go, at: /~
It will be under / and its name will be ~.
You'll be surprised that unlike Windows, Unix-like systems can take a lot of things very literally, you can even create a file with the name *.* if you quote properly. The system won't complain about it, and it will even work.

ubuntu /var file full and do not have read permissions [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I seem to have hosed myself, as I was running/learning some failing PHP/MySQL data scrape script and went off to bed. I don't know if it looped or what exactly happened, but I came back and it showed disk almost full. The analyzer said I had used almost 100G of a 100G drive on a /var directory. I try du and df-ah, but it will not show where the hog is. Says, "Permission denied." for many of the directories.
Clues:
1) gdm directory is listed as recent but won't let me look inside.
2) I was running an edit program called gksudo gedit, because I could not write to /var/www files for PHP. It appears that in the ps window, a nautilus program is dormant.
Any help is greatly appreciated and I love ubuntu, but I'm pretty much a linux newbie.
Thanks.
Do you have root permissions?
sudo bash
Then you can go in and look into what is going on.
cd /var
du -s *
Oh, and I hope I don't have to mention that you should not delete stuff that you didn't create yourself. You might just delete something important.
You report that /var/log/apache seems "large". I do NOT recommend simply deleting the files. Instead, if you are very very sure that no-one will ever need to see any historical archives of the errors and accesses made, you can:
cd /var/log/apache
for f in *; do > $f; done
which will truncate the files. This will make it less likely to cause problems due to non-existant files or bad permissions or required rotation signaling. If you might need these files in the future, we could talk about using logrotate to try and save them.
The filesystem permissions require root access to read many of the directories in /var:
ls -l /var
...
drwx--x--x 3 root root 4096 2011-04-04 23:13 www
You just need root privileges to read them all:
sudo -s
cd /var/www
ls -l
Be careful running with a root shell. You can make a ton of mistakes really quickly, some might be difficult to undo. :)

Resources