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?
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?
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/*
I ran across this also when running
sudo rm /tmp/*
the issue is how wildcards are handled when using sudo. See this discussion for details: https://stackoverflow.com/questions/31558944/why-wildcard-doesnt-work-in-sudo-rm-statement
The gist is you need a shell with sudo privileges:
sudo sh -c 'rm /tmp/*'
should do it
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....
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
Maybe the question was not so stupid, if the problem was related to hidden files. See here for more details: https://askubuntu.com/questions/72446/how-to-remove-all-files-and-subdirectories-in-a-directory-without-deleting-the-d
I solved it myself. Thank you for all your extremely helpful, non-condescending, wonderful help, @lain.
import sys
import os
import fileinput
path = '/tmp/'
listing = os.listdir(path)
for li in listing:
cmd = 'sudo rm -rf /tmp/' + li
print cmd
os.system(cmd)