0

Many programs have created a huge amount of swap files. They annoy me, because some of them contain sensitive information. How should I deal with them? Is this command a good idea:

find . -iname "*swp*" -exec rm '{}' \;

How should good programs handle their swap files?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

3 Answers3

2

If the files "annoy" you because they contain sensitive information, then you should know that simply removing the files with the rm command does not actually erase the data fro your hard drive.

I'm not really sure where your swap files are or what application is creating them. Typically swap files are created by the operating system in a specially-designated directory. For example, on my Mac:

$ ls /private/var/vm/
-rw------T  1 root  wheel  4294967296 Mar 15 19:41 sleepimage
-rw-------  1 root  wheel    67108864 Mar 15 21:10 swapfile0
$ 

If you want to erase the information in the swap files, you really need to overwrite them. You can do that with "dd" but you are better off doing it with srm. Unfortunately, srm defaults to overwriting each file 7 times, which is 6 times more than is necessary. (Use it with the -s option to get a single overwrite).

So if you want to use your find, use:

find . -iname "*swp*" -exec srm -s {} \;

Make sense?

vy32
  • 28,461
  • 37
  • 122
  • 246
  • I believe these are not the type of swap file the OP is talking about, but you're right about rm leaving the data on the disk until it is later overwritten. –  Aug 27 '10 at 08:17
  • Is it safe to remove the swap files manually? Would it not make the system unstable? – Ani May 10 '13 at 07:03
  • Removing the file won't make the system unstable. If the file is open it will still be present, it will just not have a name. Of course, overwriting the contents of a swapfile that's in use will * DEFINITELY* make the system unstable. But it could be fun! Who knows, you might corrupt your entire disk! – vy32 May 10 '13 at 18:26
  • ... but at least that would be something else to be annoyed about! – vy32 May 10 '13 at 18:27
  • yh, thats true... and how is this different from simply using "rm" command? – Ani May 10 '13 at 18:31
  • rm doesn't overwrite. The data are still on the disk... probably unencrypted. – vy32 May 11 '13 at 03:05
0

depends where it's run from, but it should be fine, though I would ammend the match to be "*.swp" or "*swp" for a more perfect match

Luke Schafer
  • 9,209
  • 2
  • 28
  • 29
0

if they run as your user id then the files created probably aren't readable by anyone else. If they are then you have deeper security issues.

SpliFF
  • 38,186
  • 16
  • 91
  • 120