Linux Hints and Tips

See also The Linux Documentation Project


Pronunciation

Linux (pronounced with a short i, as in LIH-nucks)

The following page has a sound file which plays a recording of how Linus Torvalds pronounces it himself.

or even a YouTube clip:

Different formats at

and The Linux Documentation Project at


Clock setting

See The Clock Mini-HOWTO for much more detail.

These are brief notes on maintaining and setting an accurate system clock under Linux without using the Network Time Protocol (NTP).

Just after and before rebooting (or adjustig hwclock in any way!) run...

  • adjtimex --log --watch

Callibrate hwclock by setting the time, but first give it a chance to adjust to the correct time with

  • hwclock --test --debug --adjust

e.g. * hwclock --test --debug --utc --set --date="-2 seconds"

  • hwclock --set --date="hh:mm:ss"

  • hwclock --set --date="m/d/yy hh:mm:ss"

Adjust it as little as possible, really only worth doing just before a reboot. Remember to do an adjtimex --watch before the reboot!

You should be able to adjust the sytem time with, but doesn't work for me!

  • adjtimex --offset usec (microseconds)

I don't think this interferes with any drift calculations (or does anything).

Other commands that provide info

  • hwclock --show
  • adjtimex --review
  • adjtimex --print

Changing the system clock's tick and fequency

Show the suggested tick and fequency values, based on the previously logged actuals.

  • adjtimex --review

Change the system clock to use these new values

  • adjtimex --tick 9996 --freq 333748

Executing commands recursively

Simple Example

  • find -type f | xargs grep 'findme'

More Complex

This command will recursively work its way down through the current sub-directories executing the command 'md5sum -c md5.sum'. The '-x' option to 'sh' shows the commands being excecuted.

  • export WRKDIR=pwd
  • find -type d | awk "{print \"cd \"\$0 \" ; md5sum -c md5.sum; cd $WRKDIR\"}" | sh -x

Boot Disk

Tools for creating boot disks varies with distributions. The following relates to Mandrake.

First obtain the Linux version you're running with:

  • uname -a

This reports someting like:

  • Linux www.mydomain.com 2.4.20-18.7 #1 Thu May 29 08:57:32 EDT 2003 i486 unknown

In this case, the version number is '2.4.20-18.7'

  • mkbootdisk [--compact] <version>

E.g.

  • mkbootdisk 2.4.20-18.7

Note: These days, most kernels won't fit on a floppy without a lot of work pairing it down. A better options is to use one of the Linux distros that boots from a CD.

Also bear in mind that your distro's installation boot CD may have a repair option. The most likely reason for needing a boot disk is some other program overwriting the boot sector. E.g. Mandrake 9.2 install boot disk will repair the boot sector.

Lilo can be persuaded to make a backup copy of the boot sector. Normally this will be an old version, but by renaming the normal backed up version (/boot/boot.0300 on my system), you could rerun lilo to create a copy of the current one. Lilo can also be used to restore such a copy ('lilo -u' or 'lilo -U' Read the man pages!). You might be able to use this in conjunction with a live CD like MandrakeMove. Have a look at the lilo man pages.

Grub is well worth considering. See GrubTips. It's not easy to create a boot floppy for lilo anymore. On many occasions I've had lilo mess up the hard disk's boot sector and left me scrabbling for a live CD or maybe a boot floppy. With grub, you've got a lot more you can do to rescue your system using Grub's fairly simple command line. The command line is pretty straight-forward and includes help.


Killing multiple tasks

Test with the grep statement first!

Just the grep:

  • ps auxw | grep runawaytask | awk '{print $2}'

With the kill

  • kill -9 ps auxw | grep runawaytask | awk '{print $2}'

See also: man killall


Copying files using SSH

  • scp ~foo/.ssh/id_rsa.pub foo@bar.cs.umd.edu:~foo/.ssh/authorized_keys2

Trouble-shooting


CDROM not ready.

If you get the following message turning up in your syslog, you may have a rogue X process still running in the background.

   kernel: sr0: CDROM not ready. Make sure there is a disc in the drive.

Check if kscd is running with

   ps aux | grep kscd

Check whether KsCD is sitting in your systray. That's no doubt the cause. Failing that you could kill the process with (getting [pid] from the previous command.

   kill -s SIGHUP [pid]


Remount Read-Only drive for Read-Write

  • mount -o remount,rw /mnt/

Disable Terminal Bell/Beep

X

  • xset -b.

You can also change the bell behaviour in other ways. Have a look at the man pages for xset.

Shell

Update /etc/inputrc to include:

  • set bell-style none

Add the following to /etc/profile, if necessary:

<code>
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc"]; then
INPUTRC=/etc/inputrc
fi
</code>

or maybe...

/etc/inputrc: * system-bell none


Switching between ext2 and ext3 file systems

The ext3 file system is the same format as ext2, but with a journal for recovery in the event of an un-clean shutdown.

Changes must be performed on an unmounted filesystem. After a change, run 'e2fsck -f my_device' to check the file system.

Check the man pages for tune2fs(8) before starting. This is just a hint and doesn't contain the warnings that the documentation does.

Note: The -O option is a letter, not a number.

Converting ext2 to ext3

  • tune2fs -O has_journal /dev/hda1

Converting ext3 to ext2

  • tune2fs -O ^has_journal /dev/hda1

Disk I/O Performance Test

  • hdparm -t -T /dev/hda1

or, from ftp://samba.org/pub/tridge/dbench/

  • dbench 10

to simulate 10 clients


Disk Monitoring

SmartSuite

"SMART suite controls and monitors storage devices running the Self-Monitoring, Analysis and Reporting Technology System (S.M.A.R.T.) build into ATA and SCSI Hard Drives. This is used to check the reliability of the hard drive and predict drive failures. The suite contains two utilities: smartctl is a command line utility designed to perform simple smart tasks; smartd is a daemon that periodically monitors smart status and reports errors to syslog."


Passwords

This section moved to PasswordGeneration.

Quick append to file

$ cat >> myfile <<EOF
first line
second line
EOF


- - -

Shell Scripting

See the Advanced Bash-Scripting Guide

Redirect all output

  • ls -yz > /dev/null 2>&1

Saving and Restoring the Master Boot Record

Save the MBR and the primary partition table

# dd if=/dev/hda of=backup-of-hda-mbr count=1 bs=512

If you only want to restore the actual MBR code and not the primary partition table entries, just restore the first 446 bytes: (The first 446 bytes are MBR, then 64 bytes of primary partition table).

#dd of=/dev/hda if=backup-of-hda-mbr bs=446 count=1.

UDev

See WritingUdevRules


-- Frank Dean - 5 Jan 2003

Related Topics: XfreeTips, CygwinHintsAndTips, AwkUtils, LinuxGroups, LinuxHardware, SambaConfiguration, LinuxLilo, CdBurning, KdeTips, LogicalVolumeManagement, RootKitDetection, GrubTips, DebianPcmcia, XimianEvolution, SystemVStartupScripts, DebianTips, LinuxPrinting, LinuxSoftwareRaid, HowToRebuildInitrdImage, PasswordGeneration, UbuntuTips, XenTips, HalSleepQuirks, XorgTips