These pages are deprecated (latest changes date from end 2001). More recent information may be found at http://www.coresequence.com/training.php. I leave the old pages here as they are because lots of people are still visiting them (eventhough they aren't spell-checked), and because the basics are still useful.
| Introduction to Basic Unix System Administration | ||
|---|---|---|
| <<< Previous | Next >>> | |
It's easy enough to lose things on a system, if you don't take care. When looking at a user's homedirectory, you can often mistake it for the unorganized bachellor's studio: heaps of unrelated, obscure stuff, if there are cupboards or shelves they are a mess or worse: unused, personal and professional items in the same room, half forgotten and rotting things, the laundry all over the place and such.
To make life easier on yourself, organize your homedirectory. It's part of an organized filesystem, so don't mess up the beauty but use it to keep all your materials neatly sorted.
Here are some ways of keeping the place clean:
Make a bin directory for your program files and scripts.
Organize non-executable files in appropriate directories, make as many directories as you like. Examples include seperate directories for images, documents, projects, downloaded files, spreadsheets, personal files, ...
Make directories private with the chmod 700 dirname command.
Give your files sensible names, e.g. rather Brief-aan-de-eerste-minister-050301 than letter1.
On some systems, the "quota" program may force you to clean up from time to time, or the fysical 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 win disk space.
Sometimes the content of a file doesn't interest you, but you need the filename as a marker (e.g. you just need the timestamp of the 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:
tille:~>cat verlanglijst > marker tille:~>ls -la marker -rw-rw-r-- 1 tille tille 200 Jun 12 13:34 marker tille:~> > marker tille:~>ls -la marker -rw-rw-r-- 1 tille tille 0 Jun 12 13:35 marker |
The process of reducing an existing file to a file with the same name that is 0 bytes large is called "truncating".
In C shell, the same effect is obtained by copying the Unix empty file on top of the file:
cp /dev/null somefile
![]() | For creating a new empty file, the same effect is obtained with the touch command. See the manpage. On an existing file, touch will only update the timestamp. |
To "almost" empty a file, use the tail command. Supposing my wishlist becomes rather long because I always add stuff at the end but never delete the things I actually get, and now I only want to keep the last five items:
tille:~>tail -5 verlanglijst > newlist tille:~>cat newlist > verlanglijst tille:~>rm newlist |
Some Unix programs insist on writing all sorts of output in a logfile. Usually there are options to only log errors, or to log a minimal amount of information, e.g. setting the debugging level of the program. But even then, you might not care less about the logfile. Here are some ways to get rid of them or at least set some limits to their size:
Try removing the logfile when the program is not running, if you are sure that you don't need it any more now or later. Some programs may even see, when restarted, that there is no logfile and will therefor not log.
If you remove the logfile and the program recreates it, read the documentation for this particular program in search for command options that avoid making logfiles.
Try making smaller logfiles, e.g. by logging only the information that is relevant to you, or by logging only significant information.
Try replacing the logfile with a symbolic link to /dev/null, if you're lucky the program won't complain. Don't do this with logfiles of programs that run at system reboot or programs that run from cron (see Chapter 9: Process Management - Scheduling). These programs might replace the symbolic link with a small file that starts growing again.
Regularly clean out your mailbox, make subfolders and automatic redirects (e.g. using procmail (see manpages) or the filters of your favorite mail reading application). Also clean out your trash folder on a regular basis, if you use one.
To redirect mail, use the .forward file in your homedirectory. The Unix mail service looks for this file whenever it has to deliver local mail. The content of the file decides what the mailsystem 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. E.g. 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 diskspace. The webmaster's .forward may look like this:
webmaster@www ~/>cat .forward soggie@soti.org |
Using mail forwarding is also useful to prevent yourself from having to check n different mailboxes: you can make every address point to a central and easily accessible account.
The .forward file can also contain /dev/null on a single line in some cases. The mail for this user will then be sent to the bottomless pit of the system.
Modern mail systems object to this behaviour and will send an error message to the standard output, e.g.:
tille:~>cat file | mail tille tille:~>/nethome/tille/.forward: line 1: /dev/null... Address tille is unsafe for mailing to files /nethome/tille/dead.letter... Saved message in /nethome/tille/dead.letter tille:~> |
You can ask your system administrator to define forwards for you in the local mail alias file.
When several users need access to the same file or program, when the original filename is too long or too difficult to remember, use a symbolic link in stead of a separate copy for each user or purpose.
Multiple symbolic links may have different names, e.g. a link may be called monficher in one user's directory, and mylink in another's. Multiple links (different names) to the same file may also occur in the same directory (cfr. /lib and /etc/init.d).
The shell contains a built-in command to limit filesizes: ulimit in Bash en Korn shell, limit in C and Turbo C shell.
E.g. if you are not a developper or programmer, you usually don't care about core dumpfiles (they contain debugging information on a program). You can set the maximum filesize of a core dump to 0 bytes. Read the manpage for your shell for more information on the features of the limit or ulimit command.
See Chapter 10: Backup Techniques for an overview of compress tools and their use.
The df command (disk full) displays the results of your efforts. Without options, df will display information about all mounted file systems. You can enter any directory as an option to df:
$ df / (/dev/dsk/c0t0d0s0 ): 1763568 blocks 489908 files /usr (/dev/dsk/c0t0d0s3 ): 3881960 blocks 490363 files /proc (/proc ): 0 blocks 3916 files /dev/fd (fd ): 0 blocks 0 files /var (/dev/dsk/c0t0d0s5 ): 3777052 blocks 491552 files /home (/dev/dsk/c0t0d0s7 ):14118322 blocks 862897 files /opt (/dev/dsk/c0t0d0s4 ): 6001408 blocks 495310 files /tmp (/dev/dsk/c0t0d0s6 ): 1331724 blocks 493766 files $ df -k . Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 962571 80787 824030 9% / $ |
Note that the "disks" displayed by df can be entire disks, but on a Unix system disks are frequently split up in several partitions. The df actually displays information about the partitions on a disk.
The GNU df command also supports the -h option (human readable):
tille@sprawl:~>df -h Filesystem Size Used Avail Use% Mounted on /dev/hdc5 486M 85M 376M 19% / /dev/hda1 129M 6.7M 115M 6% /boot /dev/hdc1 5.1G 2.0G 2.9G 40% /home /dev/hda7 1.6G 1.3G 264M 83% /opt /dev/hda5 2.4G 1.1G 1.2G 46% /usr /dev/hda6 1.6G 311M 1.1G 21% /var tille@sprawl:~> |
The df will also display remote filesystems. It can be very slow when a remote system is down (the command may seem to hang).
Read the manpage for more useful options (e.g. displaying amount of inodes per file system etc.)
It is a good idea to order an upgrade for your disk when it is 75 % full on average, in order to keep working comfortably.
The du command displays the size of a directory and can thus provide more detailed information. GNU du will also support a human readable form, like GNU df:
tille:~/Desktop>du -h . 8.0k ./Trash 32k ./Templates 8.0k ./Autostart 56k . tille:~/Desktop> |
As we already mentioned, the ls -la command displays individual file sizes.
Compressed files are useful, but unpacking them all the time just to get a little bit information out of them and then having to compress them again is very boring.
Most systems support egrep, zgrep, zcat, zmore and such to prevent unnecessary decompressing/compressing actions. See you system's binary directory and the manpages for more info.
| <<< Previous | Home | Next >>> |
| Redirecting I/O | Process Management |