Linux

  1. Home
  2. Computing & Technology
  3. Linux

Introduction to Linux

From Machtelt Garrels, for About.com

7.1.2. Make space

On some systems, the quota system may force you to clean up from time to time, or the physical limits of your hard disk may force you to make more space without running any monitoring programs. This section discusses a number of ways, besides using the rm command, to reclaim disk space.

Run the quota -v command to see how much space is left.

7.1.2.1. Emptying files

Sometimes the content of a file doesn't interest you, but you need the file name as a marker (for instance, you just need the timestamp of a file, a reminder that the file was there or should be there some time in the future). Redirecting the output of a null command is how this is done in the Bourne and Bash shells:


   

andy:~> cat wishlist > placeholder

andy:~> ls -la placeholder
-rw-rw-r-- 1 andy andy 200 Jun 12 13:34 placeholder

andy:~> > placeholder

andy:~> ls -la placeholder

-rw-rw-r-- 1 andy andy 0 Jun 12 13:35 placeholder

The process of reducing an existing file to a file with the same name that is 0 bytes large is called "truncating."

For creating a new empty file, the same effect is obtained with the touch command. On an existing file, touch will only update the timestamp. See the Info pages on touch for more details.

To "almost" empty a file, use the tail command. Suppose user andy 's wishlist becomes rather long because he always adds stuff at the end but never deletes the things he actually gets. Now he only wants to keep the last five items:


   

andy:~> tail -5 wishlist > newlist

andy:~> cat newlist > wishlist

andy:~> rm newlist

7.1.2.2. More about log files

Some Linux programs insist on writing all sorts of output in a log file. Usually there are options to only log errors, or to log a minimal amount of information, for example setting the debugging level of the program. But even then, you might not care about the log file. Here are some ways to get rid of them or at least set some limits to their size:

  • Try removing the log file when the program is not running, if you are sure that you won't need it again. Some programs may even see, when restarted, that there is no log file and will therefore not log.

  • If you remove the log file and the program recreates it, read the documentation for this particular program in search for command options that avoid making log files.

  • Try making smaller log files by logging only the information that is relevant to you, or by logging only significant information.

  • Try replacing the log file with a symbolic link to /dev/null ; if you're lucky the program won't complain. Don't do this with the log files of programs that run at system boot or programs that run from cron (see Chapter 4 ). These programs might replace the symbolic link with a small file that starts growing again.

7.1.2.3. Mail

Regularly clean out your mailbox, make sub-folders and automatic redirects using procmail (see the Info pages) or the filters of your favorite mail reading application. If you have a trash folder, clean it out on a regular basis.

To redirect mail, use the .forward file in your home directory. The Linux mail service looks for this file whenever it has to deliver local mail. The content of the file defines what the mail system should do with your mail. It can contain a single line holding a fully qualified E-mail address. In that case the system will send all your mail to this address. For instance, when renting space for a website, you might want to forward the mail destined for the webmaster to your own account in order not to waste disk space. The webmaster's .forward may look like this:


   

webmaster@www ~/> cat

* License

* Introduction to Linux Index

About.com Special Features

Linux

  1. Home
  2. Computing & Technology
  3. Linux
  4. Linux Documentation
  5. Introduction to Linux
  6. Introduction to Linux - 7.1.2. Make space