How do I delete everything in the /tmp/ folder?
Solution 1
You shouldn't do that, since there may be unix sockets in use (or needed) there, etc.
But still, if you wish:
rm -rf /tmp/*
Solution 2
First, I am not savy enough to advise anyone on this matter, However, I can post what I have done in the past to address these issues.
sudo -- rm -rf /tmp/
sudo -- cd /tmp/
sudo -- chmod 777 /tmp
then restart server, all the needed tmp files will be rewritten into /tmp/ by system upon restart...
Including needed /tmp/ files by any website software, etc., on the server.
This will permanently remove any /tmp/session files and free up much space....
Solution 3
As other posters have mentioned, it's hard to answer an uncooperative asker, but this is the closest I can get to an answer that'll probably work without you actually giving more details as to what specifically is going wrong. It gets around the possibility of an issue with glob expansion (is "*" expanding as root or user? is it expanding to beyond the shell's (rather large) builtin limit?) or with current-directory (are you still in /tmp after the sudo?).
if `sudo id` | grep uid=0; then
sudo find /tmp/ -maxdepth 1 \! -name . -exec rm -rf {} \;
else
echo The problem, Alex, is that sudo "isn't" actually giving you root.
fi
Related videos on Youtube
Alex
Updated on September 18, 2022Comments
-
Alex over 1 year
I do "sudo rm *" and it does not remove everything. (I probably have lots of objects in there which I don't need.)
I'm not asking whether it's ok to remove everything in tmp - i'm asking how to do it :)
Is there a shell script that can do it?
-
Alex almost 12 yearsIf it's so easy, please help me answer it. I did "sudo rm * -rf" , and there are still objects in there. Please be kind enough to help me , if it's so easy for you.
-
user9517 almost 12 yearsYou have been provided with the answer of how to do it. Why it doesn't work is a different matter altogether. It's likely that there are permission or attributes that are preventing you from removing the files.
-
mpez0 almost 12 yearsWere the files that are "still there" actually there before the rm? That is, if you still have processes running they may still be creating files in /tmp/.
-
Andy Lester over 11 yearsIf there are files still there, there's probably a very good reason for that. Stop and learn why. Post what files are still there so we can help you understand why they're there.
-
-
Silviu almost 12 years...where r stands for recursive, meaning to delete the folders and their content too and f stands for force, never prompt anything.
-
Alex almost 12 years"sudo rm -rf /tmp/*; ls" ...still lists objects in there (pictures, mainly)
-
DerfK almost 12 years@Alex Then pick one of those files (not a directory) that didn't get deleted,
sudo rm thatfile
without any options, and update the question with whatever error you get. If you don't get an error, did it work? -
phemmer almost 12 yearsThis is insane overkill. You were asked for additional info which you didnt provide, thus nobody was able to explain why you were having issues.
-
James Youngman almost 12 yearsThis is a bad idea, because it's a security hole. Someone could have created a file with a
;
in its name, for example.