How do I see a list of signals (kill -l)

How do I let a shell script run a script that should only be run by root?

Use sudo...add a line in sudoers like this...

%nobody ALL=/home/httpd/cgi/test_suid, NOPASSWD: ALL

Show me dependent libraries for a group of pids

for n in ; do { cat /proc/$n/maps | perl -pe 's{[^/]*}{};' } ; done > /tmp/liblist.txt
sort /tmp/liblist.txt | uniq

show me all my DCHP lease IP addresses

cat /var/lib/dhcp/dhcpd.leases | grep ^lease | awk '{print $2}' | sort | uniq

How do I throw out binary junk from a file?

tr -cd '\11\12\40-\176' < file_with_binary_junk > cleaned_output_file

How do I undelete a file from Linux EXT3?

EXT3 is really anti-undelete. You have to do a weird grep to find it. This command searches the /dev/md0 partition to find int main. -a forces it to dump out output even if it thinks it's binary. -B2 tell grep to dump the previous 2 lines of context, and -A500 says to dump the subsequent 500 lines.

grep -a -B2 -A500 "int main" /dev/md0 > recovered

rsync'ing remotely

rsync -e ssh -vrz  user@host:

How do I make a bell sound from a commnd line?

'echo -e "\a"'

or here's a quickie script

#!/bin/bash

RINGS=1

if [ $1 ]
then
   RINGS=$1
fi

while [ $RINGS -gt "0" ]
do
   echo -e "\a"
   sleep 1
   RINGS=$(($RINGS -1))
done

Very handy, when you want to know if a job has completed! Make it an alias, or a script.

How do I tell a hard drive to spin down (save power)

hdparm -y /dev/hda puts /dev/hda in standby mode immediately
hdparm -S 2 /dev/hda go into standby mode after an hour of inactivity
hdparm -C /dev/hda show the current status of the drive

My shell is locked up. How do I release it?

You may have accidentally pressed CTRL+S. This suspends scrolling. To resume, do CTRL+Q.

How to fix it when putty shows messed up characters

This seems to be a problem with recent RedHat releases (8 and newer)

1. edit /etc/sysconfig/i18n
2. make sure the LANG and SUPPORTED lines look like this

LANG="en_US"
SUPPORTED="en_US:en"

or

set PuTTy's 'translation' setting to UTF-8.

How to get a sorted list of directory space usage

du --max-depth=2 | sort -n -k 1

How do I see what ports are listening?

netstat -vat

How do I control what things get launched for a given runlevel?

under RedHat, use chkconfig or the friendlier ntsysv

What's the difference between a primary / extended / logical partition?

Each hard drives can contain up to 4 primary partitions, or 3 primary partitions and 1 extended partition. Extended partitions contain smaller partitions within them, called logical partitions. An extended partition can contain up to 32 logical partitions. The partition division is described in the partition table found in sector 0 of the disk.

How do I send a message to all terminals?

The wall command does that.

Login as root, type wall <ENTER>, then whatever you want to say (multiple lines are OK), follwed by <ENTER> and then CTRL-D

How do I adjust and view hard drive performance paramters?

See UsingHDParm and this article

How do I restrict the amount of memory linux uses?

modify your /etc/lilo.conf file so that the stanza representing the boot config has an append line in it, like this (this example restricts it to 128 Megabytes). It's always a good idea to do this to a second stanza because if you mess up a stanza you can kernel panic.

image=/boot/vmlinuz-2.4.7-10smpz
    label=linux-dbamem
    initrd=/boot/initrd-2.4.7-10smp.img
    read-only
    root=/dev/sda2
    append="mem=128M"

How do I get iptables to work?

http://www.linuxguruz.org/iptables/ http://www.linuxguruz.org/iptables/scripts/rc.firewall_012.txt

iptables -A INPUT -p icmp -j DROP drop all pings
iptables -A INPUT -s =SOME_ADDRESS -p tcp --syn -j ACCEPT= accept all tcp from SOME_ADDRESS

How do I set up a ramdisk? (for kernel 2.4)

thanks to 'The Labs'
if you've got RAMFS support compiled in the kernel (which apparently is for RH7.2 default config) you simply do...

mkdir /mnt/mfs
mount -t ramfs ramfs /mnt/mfs

Where's some great info on how linux starts up? (Answer: http://ctdp.tripod.com/os/linux/startupman/index.html )

How do I make the std output of a program become the input args of another?

like this... (note the backquote ` chars)
du -c `find . -iregex '.*\.\(gif\|jpg\|jpeg\|bmp\|png\),v'`

to get the total space used by all *.gif,v and *.jpg,v files, recursively. Cool!

also, you can use xargs like this...

find . -name '*.txt' | xargs grep 'foo'

which will look in all the .txt files to find if they have 'foo' in them.

How do I do I make a command go off at a certain time?

echo "echo foo" | at 10:00

...where echo foo is your command. This will send you an email with the output. Or do...

echo "[some command] >> /dev/null" | at 10:00

... to supress the mail

How do I kill a reluctant process? (Answer: killall -9 process)

What the heck does the BROADCAST setting mean and what do I set it to?

It's the address used to send a message to every system on the LAN. It's often the address of the machine except with the last IP octet set to 0xFF. Ok, but still unsure what network processes actually use this capability.

Which default files get copied to a new user's home directory? (Answer: the ones in /etc/skel)

What do those runlevels correspond to?

0: halt the computer
1: single-user mode
2: multi-user mode without networking
3: multi-user mode with networking
4: reserved for customization, otherwise does the same as 3
5: same as 4, it is usually used for GUI login (like X's xdm or KDE's kdm)
6: reboot the computer

How do I put something in the log from a script? (Answer: logger)

How do I play with video modes? (Answer: vidmode)

How do I compute the checksum of a file (Answer: cksum, md5sum)

How can I learn all about shadow passwords?

Read this)

How do mess around with processes? (status, kill, etc.)

Play with...
vmstat, pkill, tload, pstree

see also this

How do mess around with keyboard bindings?

Play with...
showkey, setfont, dumpkeys

How do I update the locate database? (answer: updatedb)

How do I strip out debugging symbols to make an executable smaller? (answer: strip --strip-debug some_file)

How do I figure out what version of the Glibc library I have? (answer: execute /lib/libc.so.6)

Cool shell utils to play with...

true & false, printf, tee, expr, basename, dirname, xargs (applies a command to a list of files)

How to create an empty file (answer: touch some_file)

How to dump out strings found in a binary file (answer: strings some_file)

How to extract .bz2 files

bzcat blah.tar.bz2 | tar xv

How to set an environment varialbe?

export NAME=value

Why does samba say The account is not authorized to login from this station

You need to enable password encryption on the samba server for NT4.0 SP3, WIN2K, etc.

How do I make samba not ask for passwords for a share?

set the security setting in the global variables to 'SHARE'. Otherwise the windows username & password has to match one samba knows about.

How to turn off ping replies

echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
make it echo 0 to turn it back on

How to backup a ton of files regularly

rsync is your friend. Although it can do backups across a network (which I haven't set up) it is also super handy just for doing backups on the same machine. For instance on this machine I use it to backup files form one hard drive to another. Here's a great document explaining how to use it. For my backups I do...

#!/bin/bash

rsync --force -av /home/httpd/ /bak/twiki/

if [ "$?" -ne "0" ]
then
   echo "Backup failure!" | mail -s "Backup failed!" mr_walsh@yahoo.com
else
   echo "Backup OK!" | mail -s "Backup OK!" mr_walsh@yahoo.com
fi

Setting up aliases in bash

Put them in /etc/bashrc

alias lsd='ls -l | grep "^d"'
alias twiki='cd /home/httpd/twiki'

How to add a user to a group

gpasswd -a [user] [group]

How to send a pop-up message to a windows machine from a linux machine

smbclient -M <machine name> < <messagefile>

How to query an RPM package file?

( a great reference found here )

query an RPM file you haven't installed yet rpm -qilp <rpmfile.rpm>
see all installed packages rpm -qa
Figure out which RPM package somefile goes with rpm -qf <somefile>
Figure out which RPM package somefile goes with and dump all the info about the package rpm -qilf <somefile>
Show files installed by a certain package =rpm -ql <rpmfile.rpm>
Install a package or upgrade if already installed =rpm -Uvh <rpmfile.rpm>
Remove a package =rpm -e <rpmfile.rpm>
Extract the files rpm2cpio intel-mkl-7.2p-8.i386.rpm (pipe) cpio -iv --make-directories

How do I mount a Floppy?

First, make sure you have a /mnt/floppy directory. If not, create it ( mkdir /mnt/floppy )

  • For a Windows disk, type mount -t msdos /dev/fd0 /mnt/floppy.
  • For a linux disk, type mount /dev/fd0 /mnt/floppy or mount -t ext2 /dev/fd0 /mnt/floppy

To unmount, just do umount /mnt/floppy

How to mount a directory from a windows box

mount -t smbfs -o username=mwalsh,workgroup=nuron //192.168.10.5/data2 /mnt

where

  • //192.168.10.5/data2 is the host and volume
  • /mnt is the directory where you go to access this on the Linux box

How to install a redhat package

Go to the directory where the Redhat Package file(s) is/are (.rpm), then type:

rpm -i file.rpm

where

  • file.rpm is the file or files (wildcards are ok) of the rpm's you want to install.

How to change what gets mounted at bootup, or set mounting aliases

Edit the file /etc/fstab

Here's a sample:

/dev/hda1               /                       ext2    defaults        1 1
/dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner    0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/pts                devpts  gid=5,mode=620  0 0
/dev/hda5               swap                    swap    defaults        0 0

  • The noauto mount option means the filesystem doesn't get mounted at boot time
  • The errors=remount-ro means that if linux discovers errors while mounting, the filesystem gets mounted in read-only mode for fixage
  • The user mount option allows any user, not just root to mount a the filesystem

How do I (un)mount a CDROM?

To mount, just type mount /mnt/cdrom. The fstab file (see above) is used to automatically do the right thing. In other words, you could also type mount /dev/cdrom /mnt/cdrom and accomplish the same thing.

To unmount, Just type umount /mnt/cdrom. If it fails and says "device is busy", make sure that no program is using any files off of it. Also make sure none of the shells are currently in that directory.

NOTE: RichKendall (01-15-01) Also make sure that none of the applications you have open were started from a directory on the mounted path. For example, you will have trouble if you do the following:

  1. mount /mnt/cdrom
  2. cd /mnt/cdrom
  3. start application foo
  4. cd /
  5. umount /mnt/cdrom

Even though you are not currently on the mounted path, you cannot unmount the directory because an application (that is still running) was started when you were at that path. To unmount the cdrom, you will need to exit application foo. A good rule of thumb is to never start an application from a path that will later change/disappear.

How do I fix a text file that a Windows editor messed up?

(Cleaning out all those nasty \R's (or ^M) characters)

tr -d '\r' < filetoclean > cleanedoutputfile

How do I create a symbolic link?

ln -s realThingFileName symbolicLinkName

Note: if you leave off symbolicLinkName it makes it the same as realThingFileName

My RedHat takes forever to boot, pausing while loading sendmail or the logger

(by Dave Hill)

(see www.redhat.com/support/alex/171.html)

(MattWalsh) I think in most cases this happens when switching a RedHat box from DHCP to static IP. The way to fix this appears to be adding your machine and its static IP to the /etc/hosts file as shown...

127.0.0.1 localhost localhost.localdomain
192.168.200.1 mymachine mymachine.mynetwork.net

How do I execute a command locally from an ftp prompt? (Answer: !command)

How do I automate ftp copying in a loop

...Say, for doing network loading for testing (by Sam Hurst)

note: ftp doesn't seem to like long macro names...you might get an error saying 'undefined macro name ...'. So use a short name like 'loop'

  1. Launch an ftp prompt
  2. ftp> macdef loop
  3. get someFileName
  4. <enter additional desired ftp commands, one line at a time>
  5. $loop (to run itself recursively)
  6. (hit enter with a blank line to terminate)
  7. ftp>  $loop (runs the macro. CTRL-C to kill)

...or better yet, create a file like this...

open 10.3.58.113
user [login id] [password]
prompt
lcd [directory 'someBigFile' is in]
macdef loop
get someBigFile
lcd [directory 'someBigFile' is in]
put someBigFile
lcd [directory 'someBigFile' is in]
$loop

$loop

then, to run, type ftp -n < yourScriptName.

Note the lcd seems to be needed between transfers. This also has the benefit of echoing a line to the screen each time something happens so you know that things are still alive.

ftp takes forever to connect

Edit the /etc/resolve.conf file. Add or fix the line that says nameserver to say...

nameserver 143.183.2.3

Disabling anonymous ftp

Add a line with simply guestserver on it. Can't believe how hard it was to find this! If you want to allow some machines to be able to connect, then list them after guestserver

Why doesn't sshd accept my passwords?

Make sure you compile with PAM support (--with-pam). Then also make sure to copy a new PAM config file. With OpenSSH 3.1, there were 2 files in the contrib/redhat directory: sshd.pam (copy to /etc/pam/sshd and sshd.init (copy to /etc/init.d/sshd).

How do I dump log msgs from my most recent startup? (Answer: dmesg)

That cool page with lots of wc examples...

http://www.linuxjournal.com/article.php?sid=1327

-- TWikiGuest - 07 Dec 2001

Topic revision: r47 - 08 Mar 2006 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback