Part 3: Basic Operations FAQ
by Peter, Stan, Barbara and Marie Klimas
Answers to Some Frequently Asked Linux Questions
Distributed under the General Public License http://www.gnu.org/copyleft/gpl.html.
Your feedback, comments, corrections, and improvements are appreciated.
Send them to either bklimas@magma.ca
or bw641@freenet.carleton.ca
Start: Linux Newbie Administrator Guide
Part 0: For the Undecided (Linux Benefits)
Part 1: Before Linux Installation
Part 2: Linux Resources, Help and Some Links
Part 3: >Basic Operations FAQ<
Part 4: Linux Newbie Administrator FAQ
Part 5: How to Upgrade the Kernel
Part 6: Linux Shortcuts and Commands
Part 7: Essential Linux applications (proprietary
or not)
Contents of this page:
3.1 Basics
3.1.1 Filenames3.2 Users, passwords, file permissions, and security
3.1.2 What are the different directories for?
3.1.3 How do I run a program?
3.1.4 How can I change the PATH?
3.1.5 How can I shutdown my computer?
3.1.6 How do I deal with a hanged program?
3.2.1 Home directories, root, adding user3.3 Job scheduling with "at" and cron
3.2.2 About password security
3.2.3 I forgot the root password
3.2.4 I have file permission problems. How do file ownership and permissions work?
3.2.5 My mp3 player chokes. The sound is kind of interrupted (how to set suid)
3.3.1 How do I execute a command at a specified time?3.4 Swap space
3.3.2 How do I set up cron?
3.4.1 Swap partitions
3.4.2 Swap files
3.1 Basics
Linux is case-sensitive. For example: my_filE, my_file, and my_FILE are three different files. (Your password is also case-sensitive. Also UNIX and the "c" programming language are case-sensitive.)
Filenames can be up to 256 characters long and they normally contain letters, numbers, "." (dots), "_" (underscores) and "-" (dashes). Other characters are possible but not recommended. In particular, it is not recommended to use special metacharacters: "*" (asterisk), "?" (question mark), " " (space), '$' (dollar sign), '&" (ampersand), any brackets, etc. This is because matacharacters have special meaning to the Linux shell.
It is not possible at all to have '/' (slash) as a part of the filename because '/' is used to represent the top of the directory tree, and as a separator in the pathnames (the same as '\' in DOS).
To manipulate file with names that do contain matacharacters, I use a pair of ' (apostrophes), so that the metacharacters are quoted and therefore their meaning is hidden from the shell. For example, to remove a file "my file*" (contains space and asterisk), I would issue:
rm 'my file*'
Quoting with a pair of " is weaker than quoting with ' . When you use " some metacharacters will get interpreted.
Here is the meaning of some metacharacters:
* = Matches any sequence of zero or more characters (except for
"." dot at the beginning of a filename).
? = Matches any single character.
[abC1] = Matches a single character in the enumerated set. In
this example the set is: 'a', 'b', 'C', or '1'.
[a-z] = Matches any lower-case letter.
[A-F] = Matches any upper-case letter from A to F in the Latin alphabet.
[0-9] = Matches any single digit.
[a-zA-Z0-9] = Matches any letter (lower or upper case) or any digit.
Files with names starting with "." are not shown by the ls
(list) or dir commands unless you use ls -a (list
with the option all).
This is because "." is not matched by "*" if it is the first character
of the filename. Think of files with names starting with "." as an equivalent
of DOS hidden files.
3.1.2 What are the different directories for?
This is explained very nicely in the Linux System Administrator Guide (SAG), which should be available on your system. Try:3.1.3How do I run a program?cd /usr/doc/LDP/sag
lynx sag.htmlThis will start a text-mode browser "lynx" to view this html book. You can also use any other browser, e.g. Netscape for Windows, to view this book. This book and other LDP books are actually quite easy to read.
Briefly, Linux contains five filesystems. These filesystems can reside on a single or different hard drives and/or partitions, depending on the size and need of your system. (A single filesystem can also be distributed between different physical devices, if needed.)
The root "/" filesystem--contains basic operating system and maintenance tools. The content of this filesystem should be sufficient to start up the system and perform emergency maintenance and repairs if they were necessary.
/usr filesystem--contains all commands, libraries, documentation, and other files that do not change during normal operation. This will also contain major applications, for example Netscape.
/var filesystem--contains files that change: spool directories, log files, lock files, temporary files, and formatted manual pages.
/home filesystem--contains user files (user own settings, customization, documents, data, etc).
/proc filesystem--contains entirely illusionary files. They don't really exist on the disk and don't take any space there (although "ls -l" will show their size). When viewing them, you really access information stored in memory. It is used to access information about the system.The parts of the root filesystem are:
/bin--commands needed during bootup that might be used by normal users.
/sbin--commands not intended for use by general users (users may still use them).
/etc--configuration files for your system.
/root--the home directory of the system administrator (called super-user or root).
/dev--device files. Devices appear on Linux as files so it is easy to write to them.
/mnt--mount points for removable media, partitions of other operating systems (like dos), network shares, and anything else that is mounted on the file system temporarily. It normally contains subdirectories for the mounting shares.
/lib--shared libraries for programs on the root filesystem.
/boot--files used by the LILO bootstrap loader. It typically also contains the Linux kernel, but this can be stored somewhere else, if LILO is configured to know where it is.
/opt--optional large applications, for example kde.
/tmp--temporary files. It may clean automatically.
/lost+found--files recovered during the filesystem repair.The most interesting parts of the /usr filesystem are:
/usr/X11R6--X-windows system.
/usr/X11--the same as /usr/X11R6 (it is a symbolic link to /usr/X11R6).
/usr/X11R6/bin --lots of small X-windows apps, and perhaps symbolic links to the executables of some larger X-windows applications).
/usr/doc--Linux documentation.
/usr/bin and /usr/sbin--similar to their equivalents on the root filesystem, but not needed for basic bootup (e.g. during emergency maintenance).
/usr/local--installed "local user" applications, for example Netscape (each in a separate subdirectory).
/usr/local/bin--perhaps smaller "user" apps, and symbolic links to the larger executables contained in separate subdirectories under /usr/local.It is important to understand that all directories appear in a single directory tree, even if the directories are contained on different partitions, physical drives (including floppies, etc), or even if they distributied over the network. Therefore, the are no DOS-type "drive letters" under Linux.
Typing the name of the executable doesn't help? There are three possibilities.3.1.4 How can I change the PATH?The first possibility: you don't type the name of the executable correctly. Check the case--Linux is case sensitive! For example, typing "Pico" or "PICO" will not start the pico editor.
The second possibility: maybe the program is not on your path. Under Linux (or UNIX), an executable must be on your PATH to run it, and the current directory is NOT on your PATH. Type the full path to the executable, or:
cd the_program_dir
./program_nameYou must put the dot and slash or the program will NOT execute. (This is a security feature not to put one's current directory on the path. It makes "trojan horses" more difficult.)
You may check your path using:
echo $PATH
To learn how to change your PATH, or add your current directory to it, see the next answer.
If your executable is lost somewhere in your directory tree, you may want to find it using (for example):
find -name "netscape"
to find a file called netscape. You may be able to achieve the same result faster using
locate netscape
(locate runs faster because it relies on a pre-built database of files on your system).
The third possibility: maybe the file is not executable. If it should be, change the permissions to make it executable. E.g. (as root or the user who owns the file):
chmod a+x filename
will make the program executable for all users. Check if it worked using:
ls -l filename
Read here if you don't understand the output of this command or the whole "third possiblity".
The PATH is the list of directories which are searched for the program the execution of which you request. You can check your PATH using this command:3.1.5 How can I shutdown my computer?echo $PATH
which, on my system , shows the PATH for user "yogin" to be:
/opt/kde/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/yogin/bin
The ":" is a separator, therefore the above PATH represents a list of directories as follows:
/opt/kde/bin
/usr/local/bin
/bin:/usr/bin
/usr/X11R6/bin
/home/yogin/binHere is the output from the command "echo $PATH" run on my system on the account "root":
/opt/kde/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
You can change the PATH for all users on the system by editing the file /etc/profile and adjusting (as root) the line containing "PATH=". I do it using the pico editor (as root):
pico -w /etc/profile
(The option -w turns off the wrap of long lines.)
Re-login for the change to take effect. To set up the PATH for an individual user only, edit the file "/home/user_login_name/.bash_profile" (please note the dot in front of the filename--files starting with a dot are normally invisible, you have to use "ls -a" to see them).
If you really want to have the current directory on your PATH, add "." (dot) to your PATH. The specification for the path in /etc/profile may then look like this:
PATH="$PATH:/usr/X11R6/bin:."
export PATH
Press <Ctrl><Alt><Del>, wait for the shutdown process to complete, and turn off your machine only after it starts rebooting again. Do not turn off your machine without the proper shutdown or else you may have disk error messages next time you boot. (Typically, the errors resulting from improper shutdown will be repaired automatically during the next boot, but occassionally more serious problem may result, and then you may need to repair the files manually or re-install!)3.1.6 How do I deal with a hanged program?If you prefer your computer to go to the halt after you press <Ctrl><Alt><Del> (instead of the default reboot), you can set this up by editing the file /etc/inittab. This file specifies something like this:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r nowChange (as root) the option "-r" to "-h" so that it reads:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -h nowRoot can also use the shutdown command. This command can be used for either a local or remote shutdown of the system. The last one is very useful if a program hangs so that the keyboard is no longer functional. For example:
telnet name_of_machine_with_no_operable_keyboard
[login as a user]
su
[give password]
[kill the offending process or]
/sbin/shutdown -rn nowThis command will shutdown really fast, bypassing standard (longer) shutdown procedure--useful when the system became really buggy (the option -n will make "shutdown" kill all the processes before rebooting).
Please note that for security reasons, you cannot login to a remote machine as root (e.g., over the telnet). You have to login as a user and then execute su and give password to become a super user (root).
The shutdown command may also be used to execute a shutdown later. E.g. (as root):
/sbin/shutdown -r 23:59
will reboot the system 1 minute before midnight.
If the shutdown command is too long for you, you may want to try these two commands, which do exactly what their names suggest (as root):
reboot
haltA fancy way to shut down your computer is to switch your system to the runlevel 0 (for halt) or runlevel 6 (for reboot). Try it using (as root):
init 0
The meaning of the different runlevels is explained in /etc/inittab and here.
Buggy programs do hang under Linux. A crash of an application should not, however, affect the operating system itself so it should not be too often that you have to reboot your computer. In our experience, a misbehaving operating system may be a sign of hardware or configuration problems: we repeatedly encountered problems with the Pentium processor overheating (the fan on the Pentium did not turn as fast as it should or it stopped altogether, the heat sink on the Pentium was plugged with dirt), bad memory chip, different timing of different memory chips (you may try re-arranging the order of the chips, it might help), wrong BIOS setup (you should probably turn off all the "advanced" options). The "signal 11" error message is typically associated with hardware problems and it most likely to manifest itself when you perform intensive tasks: Linux setup, kernel compilation, etc.Not really hanged. Some programs might give the uninitiated impression of hanging, although in reality they just wait for user input. Typically this happens if a program expects an input file name as a command line argument, no input file is given by user, so the program defaults to the standard input (console). For example, this command
cat
may look like it's hanged but it waits for keyboard input. Try pressing <Ctrl>d (which means "end-of-file") to see that this will satisfy the "cat" command. Another example: I have seen many questions on the newsgroups about the "buggy" tar command that "hangs" when trying to uncompress a downloaded file, for example:
tar -zxv my_tar_file
This waits for user input too, since no option -f (filename) was specified so the second parameter "my_tar_file" was not recognized as a filename. The correct command is:
tar -zxvf my_tar_file
Any program (hanged or not) can be killed. A text-mode program in the foreground can often be killed by pressing <Ctrl>C. This will not work for larger applications, still you can get back in control either by sending the program to the background by pressing <Ctrl>z (no guarantee this will work) or switching to a different terminal, for example using <Ctrl><Alt><F2> and login as the same user that hanged the program (this should always work). Once you are back in control, find the program you want to terminate, for example:
ps
This command stands for "print status" and shows the list of programs that are currently being run the current user. In the ps output, I find the process id (PID) of the program that hanged, and now I can kill it. For example:
kill 123
will kill the program with the process id (PID) of 123.
As user, I can only kill the processes I own (this is, the ones which I started). The root can kill any process. To see the complete list of all processes running on the system issue:
ps axu | more
This lists all the processes currently running (option "a"), even those without the controlling terminal (option "x"), and together with the login name of the user that owns each process ("u"). Since the display is likely to be longer than one screen, I used the "more" pipe so that the display stops after each screenful.
The kill command has a shortcut to kill programs by name, for example:
killall netscape
will kill any program with "netscape" in its name.
X-windows-based programs have no control terminals and may be easiest to kill using this (typed in an X-terminal):
xkill
to which the cursor changes into something looking like a death sentence; you point onto the window of the program to kill and press the left mouse button; the window disappears for good, and the associated program is terminated.
If your X-windows system crashes so that it cannot recover, it may be the easiest to kill the X-server by pressing <Ctrl><Alt><BkSpace>. After that, it may be a good idea to run ps axu, find any possible X-programs that might still be running, and kill them. If you don't do this, the misbehaving program that caused your X-windows to crash might cause trouble again.
If you have programs in the background, the operating systems will object your logging out, and issue a message like "There are stopped jobs". To override and logout anyway, just repeat the logout (or exit) command immediately --the background program(s) will be automatically terminated and you will be logged out.Core files. When a program crushes, it often dumps a "core" into your home directory. This is accompanied by an appropriate message. A core is a memory image (plus debugging info) and is meant to be a debugging tool. If you are a user who does not intend to debug the program, you may simply delete the core:
rm core
or do nothing (the core will be overwritten if another core is ever dumped). You can also disable dumping the core using the commmand:
ulimit -c 0
Checked if it worked using:
ulimit -a
(the option "-a" stands for "all"). If you would like to see how the core file can be used, try (in the directory where you have a core file):
gdb -c core
This lunches GNU debugger (gdb) on the core file "core" and displays the name of the program that created the core, signal on which the program was terminated, etc. Type "quit" to exit the debugger.
3.2 Users, passwords, file permissions, and security
3.2.1 Home directories, root, adding users
The (almost) only place on the harddrive that normal users (non-root) can write to is their home directory, which is /home/user_login_name3.2.2 About password securityThis "home" directory is for all user files: settings, program configuration files, documents, data, Netscape cache, mail, etc. As a user, you can create subdirectories under your home directory to keep yourself organized. Other users cannot read your files or write to your home directory unless you give them a permission to do so.
Normal users can also see, read and execute many other files on the filesystem (besides their home directory), but they normally cannot modify or remove them.
The "root", or the "super user", is a special administrative account that has the power to modify any file on the system. It is not a good idea to habitually work on your system as root--your mistakes can cost you dearly. Set up and use a normal user account for every day work. The root account is the only account that exists on Linux after the initial installation.
A user account can be created by root using, for example:
adduser joe
passwd joe
[type the password for the user joe]Root can change any user's password, although s/he cannot read it. (Passwords are encrypted using a one-way encryption algorithm and only this encrypted version is stored on the system, in the file /etc/passwd, the "open" version is never stored. When you login, the password you type is encrypted again using the same one-way algorithm and compared with the already encrypted version stored in the file /etc/passwd.)
The separation of the administrator and user makes Linux systems secure and robust--it even makes viruses under Linux difficult (the programs that a user runs can also write to his/her own directories).
It is customary that the user changes his/her password immediately after the first login, for example:
passwd
(current) UNIX password]: pass_OLD
New UNIX password: pass_NEW
Retype New UNIX password: pass_NEWIn reality, the password will not appear on the screen as you type it.
Weak passwords are probably the most common source of security problems. Here are some examples of hazardous passwords:3.2.3 I forgot the root password
- the word "password" (wow, this one is really weak!);
- your first or last name or user login name;
- name of your wife (husband), daughter, girlfriend, dog, etc.
- name of your company, department, workgroup, etc.
- date of your birth;
- password written in the calendar on your desk or on the side of your computer;
- any word which is in the dictionary (the dictionary does not contain so many words as it might seem);
- a password which you also use in an insecure public place, for example an Internet store or a mailing list.A good password is relatively long (minimum 6 letter), contains a mixture of letters (upper and lower case, if possible) and numbers, and is changed quite regularly (8 weeks?).
The system administrator can set the password policy through the utility included in this configuration program (run as root):
linuxconf
under the menu "user account"-"policies"-"password & account policies".
You have to boot your computer from the Linux boot diskette, find your Linux root partition on the hard drive, and edit the file /etc/passwd. In this file, erase the encrypted password for root, so it is empty. For example, the /etc/passwd entry for root may look like this:3.2.4 I have file permission problems. How do file ownership and permissions work?root:abcdefghijklm:0:0:root:/root:/bin/bash
The "abcdefghijklm" is a 13 character encrypted password (actually, it is a 2 character "salt" and a 11-character encrypted password). I would change this line to:
root::0:0:root:/root:/bin/bash
Now, the root account has no password, so I can reboot the computer and, at login prompt, type "root" and for password just press ENTER (empty, no password). After a successful login, I immediately set the password for root.
An alternative to this procedure is to re-install Linux.
If any other user (non-root) forgets the password, this is not a problem, root can change any password. For example (as root):
passwd barbara
will prompt for a new password for the user "barbara" (no knowledge of old password required).
You might also want to note that "*" in the /etc/passwd password field means that no login is permitted for this account. If you need to temporarily disable a user account, just put a star before the user encrypted password . If you want to restore the account, you just erase the star and the user account is back, with its old password.
The naming and permission conventions are the same for normal files and directories, so whatever is said about files below, applies also to directories.3.2.5 My mp3 player chokes. The sound is kind of interrupted (how to set suid).File owners. Each file has its owner and owner group. These will be shown in the output from the ls -l command (="list in the long format"). For example, the command:
ls -l junk
produced this output on my screen:
-rwx------ 1 yogin inca 27 Apr 24 14:12 junk
This shows the file "junk", which belongs to the owner "yogin" and the group "inca". The owner is typically the person who created (or copied) the file. Only the owner and the root can remove (erase) a file (yet other users may be able to modify or erase the content of the file if they are given the permission to do so--read on).
The ownership of a file can be changed using the commands chown (change owner) and chgrp (change group), which are normally executed by root:
chown peter junk
chgrp peter junk
ls -l junkAfter executing the above 3 line, the command "ls-l junk" produces this output on my screen:
-rwx------ 1 peter peter 27 Apr 25 20:27 junk
Changing the file ownership comes handy if you move/copy files around as root for use by other users. At the end of your housekeeping you should remember to hand-in the file ownership to the proper user.
File permissions. Now, each user can make any file s/he owns accessible in three modes: read (r), write (w), execute (x) to three classes of users: owner (u), members of the owner group (g), others on the system (o). Check the current access permissions using:
ls -l filename
If the file is accessible to all users (owner, group, others) in all three modes (read, write, execute) it will show:
-rwxrwxrwx
Skip the first "-" (it shows "d" for directories). After this, the first triplet shows the file permission for the owner of the file, the second for his/her group, the third for others. A "no" permission is shown as "-". Here is an output from the ls -l command on a file that is owned by root, for which the owner (root) has all permissions, but the group and other can only read and execute:
drwxr-xr-x 2 root root 21504 Apr 24 19:27 dev
The first letter "d" shows that the file is actually a directory.
You can change the permissions on the file you own using the command chmod (="change mode"). For example, this command will add the permission to read the file "junk" to all (=user+group+others):
chmod a+r junk
In the command above, instead of "a" (="all"), I could have used "u", "g" or "o" (="user", "group" or "others"). Instead of "+" (="add the permission"), I could have used "-" or "=" (="remove the permission" or "set the permission"). Instead of "r" (="read permission"), I could have used "w" or "x" (="write permission" or "execute permission").
For example, this command will remove the permission to execute the file junk from others:
chmod o-x junk
Instead of letters, one can also use numbers to specify the permissions. To understand how it works look at this:
read=4
write=2
exectute=1The total permission for a class of users is the sum of the three. Thus:
4 = read only
6 = read and write
7 = read, write and execute.The permission for all the three classes of user (owner, group, others) is obtained by gluing the digits one by one. For example, the command
chmod 770 junk
will give the owner and his/her group the completto of permissions, but no permissions to others. The command:
chmod 666 junk
gives all three classes of users the permissions to read and write (but not execute) the example file named "junk". Please note the "666". It is quite often used and, at least for one person I know, it is a proof that Linux (any UNIX for that matter) is a work of the devil >:-0.
This command:
chmod 411 junk
would give the owner the permission to read only, and the group and others to execute only. This one does not seem useful, but might be funny, at least for those North American Linux users who dial 411 (tel. number) in emergency. Mail me if you can think of any other funny permissions (maybe 007?).
Default file permissions with mask. When a new file is created, it is given default permissions. On my system, these are:
-rw-r--r--
I can check the default file permissions for newly created files using:
umask -S
(The option -S stands for "symbolic" and tells umask to display the permissions in a easy-to-read form.)
I can change the default file permissions for newly created files using a command like:
umask u=rwx,g=,o=
which will give the owner all the permissions on newly created files, and no permission to the group and others.
Using numbers to set default permissions with umask is more tricky. The number shows the permissions that you take away for users (opposite to chmod). Thus:
umask 000
will give full permissions to everybody on newly created files. The next example gives full permissions to the owner, none for everybody else:
umask 077
The MP3 player might not be given enough processor power. It could be that your system is lousy. Or you might be running too many cpu-intensive programs at the same time. Or, most likely, you may need to run the player with a higher priority. (The priority is set with the command nice -- see man nice or info nice). Try to run the player as root--programs run by root are given higher priority than those run by normal users. If this solves the problem, set the "suid" so all users are given the "effective user id" of root when running it, for example:3.3 Job scheduling with "at" and cronchmod a+s x11amp
will do the trick for the xamplifier program. The output from
ls -l x11amp
on my computer is now:
-rwsr-sr-x 1 root root 319172 Mar 13 1998 x11amp
The first "s" indicates that the set-user-id (suid) bit is set. The second "s" indicates that the set-group-id (sgid) is also set. Thus anybody who executes x11amp will now be given the effective user id of the program owner and effective group id of the owner group, which in this case is "root" and group "root".
Setting the suid for a program could possibly become a security hole in your system. This is unlikely the case on a closed home network and when setting suid for a program origin of which is well traceable. However, even at home, I wouldn't suid a piece of code origin of which is uncertain, even if the setup instructions urged me to do so.
3.3.1 How do I execute a command at specified time?
You may want to use the at command. "at" will execute the command(s) you specify at the date and time of your choice. For example, I could start playing music from my CDROM at 7 o'clock in the morning:3.3.2 How do I set up cron?at 7:00
cdplay<Ctrl>dIn the example above, I entered the first line "at 7:00" on the command line and then pressed ENTER. To this, the "at" command displayed a prompt "at>". At this prompt, I entered my command "cdplay" and then pressed the control key and "d" simultaneously to finish the input. If instead of pressing <Ctrl>d , I pressed "ENTER", the next "at>" prompt would appear, at which I would be able to enter the next command to be executed right after "cdplay", also at 7:00. And so on, I could have had many commands scheduled for execution one by one starting at 7:00. After typing the last command, I would finish the input with <Ctrl>d. Think of the <Ctrl>d as sending "end-of-file" to the current input. Don't press <Ctrl>d twice because this will log you out--that's what <Ctrl>d does when entered straight on the Linux command line.
You can list the job you scheduled for execution using:
at -l
which will give you the numbered list of the jobs waiting.
If you changed your mind, you can remove a job from this list. For example:
atrm 8
will remove the job with a number eight.
I could also schedule a job for execution much later, for example:
at 23:55 12/31/00
startxwould start my X-windowing system right on time for the new millennium (5 minutes before midnight on 31 of December 2000).
If you cannot execute the "at" command as a regular user, check if the empty file /etc/at.deny exists and no /etc/at.allow. This should be the default setup and it permits all the users to execute at. If you want only certain users to use "at", create a file /etc/at.allow and list these users there.
For other options, check:
man at
Cron (a Linux process that performs background work, often at night) is set up by default on your Red Hat system. So you don't have to do anything about it unless you would like to add some tasks to be performed on your system on a regular basis or change the time at which cron performs its duties.4.4 Swap spacePlease note that some of the cron work might be essential for your system functioning properly over a long period of time. Among other things cron may:
- rebuild the database of files which is used when you search for files with the "locate" command,
- clean the /tmp directory,
- rebuilding the manual pages,
- perform some other checkups, e.g. adding fonts that you recently copied to your system.Therefore, it may not be the best idea to always switch your Linux machine off for the night--in such a case cron will never have a chance to do its job. If you do like switching off your computer for the night, you may want to adjust cron so it performs its duties at some other time.
To find out when cron wakes up to perform its duties, have a look at the file /etc/crontab, for example:
cat /etc/crontab
It may contain something like this:
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthlyYou can see that there are four categories of cron jobs: performed hourly, daily, weekly and monthly. You can modify those or add your own category. Here is how it works.
The columns in the entries show: minute (0-59), hour (0-23), day of month (1-31), month of year (1-12), day of week (0-6--Sunday to Saturday). The "*" means "any valid value".
Thus, in the example quoted, the hourly jobs are performed every time the computer clock shows "and one minute", which happens every hour, at one minute past the hour. The daily jobs are performed every time the clock shows 2 minutes past 4 o'clock, which happens once a day. The weekly jobs are performed at 22 minutes past four o'clock in the morning on Sundays. The monthly jobs are performed 42 minutes past four o'clock on the first day of every month. The file containing the command to be executed at that time is shown as the last entry on each line.
If you wanted your jobs to be performed at noon instead at 4 in the morning, just change the 4s to 12s. Cron wakes up every minute and examines if the /etc/crontab changed so there is no need to re-start anything after you make the changes.
Swap is an extension of the physical memory of the computer. Most likely, you created a swap partition during the initial RedHat setup. You can verify the amount of swap space available on your system using:cat /proc/meminfo
The general recommmendation is that one should have: at least 4 MB swap space, at least 32 MB total (physical+swap) memory for a system running command line-only, at least 64 MB of total memory for a system running X-windows, and swap space at least 1.5 times the amount of the physical memory on the system.
If this is too complicated, you might want to have a swap twice as large as your physical (silicon) memory, but not less than 64 MB.
If you ever need to change your swap, here are some basics.
Swap partitions. You can have several of them, each up to approximately 124 MB. Here are the steps to create and enable a swap partition:
- Create the partition of the proper size using fdisk (partition type 82, Linux swap).
- Format the partition checking for bad blocks, for example:
mkswap -c /dev/hda4
You have to substitute /dev/hda4 with your partition name. Since I did not specify the partition size, it will be automatically detected.
- Enable the swap, for example:
swapon /dev/hda4
To have the swap enabled automatically at bootup, you have to include the appropriate entry into your /etc/fstab file, for example:
/dev/hda4 swap swap defaults 0 0
If you ever need to disable the swap, you can do it with:
swapoff /dev/hda4
Swap files. Swapping to files is usually slower than swapping to a raw partition, so this is not the recommended permanent swapping technique. Creating a swap file, however, can be a quick fix if you temporarily need more swap space. You can have up to 8 swap files, size of each can be up to 16 MB. Here are the steps for making a swap file:
- Create a file with the size of your swap file:
dd if=/dev/zero of=/swapfile bs=1024 count=8192
This physically creates the swap file /swapfile, the block size is 1024 B, it contains 8192 blocks, the total size is about 8 MB. (The dd command copies files. In the example above, the input file was /dev/zero, the output file was /swapfile. You cannot use the cp command for creating a swap file because the swap file must be continuous.)
- Set up the file with the command:
mkswap /swapfile 8192
- Force writing the buffer cache to disk by issuing the command:
sync
- Enable the swap with the command:
swapon /swapfile
When you are done using the swap file, you can turn it off and remove:
swapoff /swapfile
rm /swapfileYou may also want to see the nice info written by Linus Torvalds himself:
man mkswap
Go to Part 4: Linux Newbie
Administrator FAQ