LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cannot remove contents of the /tmp folder (http://www.linuxquestions.org/questions/linux-newbie-8/cannot-remove-contents-of-the-tmp-folder-705067/)

bergman 02-16-2009 09:43 AM

cannot remove contents of the /tmp folder
 
Hello,

Im trying to delete the contents of my /tmp folder, so from within /tmp I issue this command:

Code:

rm -r *
but it gives me the error message:

Quote:

rm: invalid option -- _
Ive tried the above command as root also.

The permissions on the /tmp folder are 'drwxrwxrwt', Im wondering what the 't' is ?

Is there a special command to delete the contents of the /tmp folder?

eco 02-16-2009 10:01 AM

You can try the following but you should be careful as it will probably delete files that are in use:

Code:

# rm -rf -- *
The '--' mans there are no more parameters.

Use at your own risk.

bach-fiend 02-16-2009 03:59 PM

deleting files that are in use
 
This is legal in unix, I'm pretty sure. a "rm" command will succeed but the file will stick around UNTIL IT IS NO LONGER OPEN. THEN it will be really removed.

raj k yadav 02-17-2009 07:12 AM

't' is denoted for sticky bit. You cannot delete files which are not owned by you if sticky bit is applied on a directory.

chitambira 02-17-2009 07:51 AM

You can remove the stiky bit as root:
chmod -t /tmp
if /tmp is owned by root, then he shopuld be able to remove the files anyway

rich_c 02-17-2009 09:00 AM

Just do a reboot. That should clear out /tmp. It seems to have done on my system. My last reboot was 8 Feb and there are no files older than that in /tmp.

jdkaye 02-17-2009 10:06 AM

Yes, Rich_c is right. Just wait for your next reboot and /tmp gets cleared out automatically. I don't think it's a clever idea to remove everything from /tmp on a running system. Lots of apps put stuff there until they are closed down. Removing these /tmp file would probably bring your system down. You can certainly delete specific files that you know are no longer necessary (I use /tmp as my default download folder and delete installation files all the time). Why do you want to delete everything from /tmp anyway?
cheers,
jdk

bergman 02-17-2009 02:32 PM

Thanks everyone.

Rebooting didnt remove the files in /tmp (slackware 12.1), but doing:

Code:

# rm -rf -- *
as suggested did remove all the files, and it doesnt seem to have created any problems (at least not yet!)

p.s jdkaye, I just wanted a clearout ;)

Ranguvar 02-17-2009 02:40 PM

Don't remove the /tmp sticky bit evar. It's for security :)

jdkaye 02-17-2009 11:30 PM

Quote:

Originally Posted by bergman (Post 3447363)
Thanks everyone.

Rebooting didnt remove the files in /tmp (slackware 12.1), but doing:

Code:

# rm -rf -- *
as suggested did remove all the files, and it doesnt seem to have created any problems (at least not yet!)

p.s jdkaye, I just wanted a clearout ;)

bergman,
There are always going to be files in /tmp for the reasons explained above. Are you sure the ones that you save in /tmp when you rebooted arent' fresh ones installed after your latest reboot? You can check the date/time of the files by doing
Code:

ls -l [filename]
cheers,
jdk

bergman 02-18-2009 02:17 AM

There are a few hidden files and directories which seem to have been created since the reboot (.xorg.conf, .X0-lock, etc), but alot fewer than there were.

I suppose Im trying to clean up a directory which by its nature is 'untidy'.

rich_c 02-18-2009 03:25 AM

Quote:

Originally Posted by bergman (Post 3447949)
I suppose Im trying to clean up a directory which by its nature is 'untidy'.

And probably best left ignored, unless it's using an awful lot of space. Mine's got 5.2MB in the 10 days since last reboot.

bernihard 02-18-2009 09:17 AM

A useful command for know if some process is using any file inside /tmp folder do the following:

Code:

fuser /tmp
The output will be the PID of the processes using files under /tmp


All times are GMT -5. The time now is 12:55 AM.