Archive for the ‘Tips and Tricks’ Category

Reverse cat

Wednesday, September 14th, 2005

How to concatenate and/or print files in reverse order? tac is your friend.

From the man page:

Write each FILE to standard output, last line first. With no FILE, or when FILE is -, read standard input.

The easiest way to use it…

tac filename.txt

Show shared library dependecies

Monday, August 22nd, 2005

The ldd command lists the dynamic libraries used by a program. This utility is very useful to find out what shared libraries your executables depend on or to do some basic forensic analysis or to help you building chrooted jails.

Simply type this…

ldd /usr/bin/passwd

and you’ll get something like this…

linux-gate.so.1 => (0xffffe000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7fb5000)
libpam.so.0 => /lib/libpam.so.0 (0xb7fab000)
libpam_misc.so.0 => /lib/libpam_misc.so.0 (0xb7fa8000)
libcrack.so.2 => /lib/libcrack.so.2 (0xb7f9c000)
libc.so.6 => /lib/libc.so.6 (0xb7e87000)
libdl.so.2 => /lib/libdl.so.2 (0xb7e83000)
/lib/ld-linux.so.2 (0xb7feb000)

Ethernet card settings in Linux

Thursday, August 4th, 2005

If you have a Linux system, there is a tool that lets you examine and change ethernet based network interfaces.

The ethtool utility is used for querying settings of an ethernet device and changing them. The basic usage is as follows:

ethtool eth0

…and you’ll get something like this:

Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: Unknown! (65535)
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: umbg
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: no

For more information take a look at man pages.

How to create unique temporary files

Sunday, July 10th, 2005

Unix provides a couple of useful commands to create temporary file names or directories that can be used in your applications or shell scripts.

In Linux we have mktemp and tempfile. The simplest usage is as follows:

mktemp
/tmp/tmp.avSbCw

or…

tempfile
/tmp/file8W2jIZ

For more information take a look at man pages for both commands.

Mapping grub device names with Linux device names

Thursday, March 24th, 2005

To map grub device names to linux device names in case of system containing IDE and SCSI storage devices. You can use device.map file with following format to let grub know the boot sequence:

(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdb
(hd2) /dev/hdc
(hd3) /dev/hdd
(hd4) /dev/cciss/c0d0
(hd5) /dev/ida/c1d1

# grub –device-map=/boot/grub/device.map
grub> root (hd0,0)

grub> setup (hd0)

Basic tar usage (GNU tar)

Thursday, March 24th, 2005

As you probably know tar is designed to store and extract files from an archive file (a tarfile). Here I’ll show you some basic usage of this tool…

Here we go!

Archive a set of files:

tar -cvf tarfile.tar /var/log/syslog /var/log/messages

Archive and compress (gzip) a set of files:

tar -cvzf file.tar.gz /var/log/syslog /var/log/messages

Archive and compress (bzip2) a set of files:

tar -cvjf file.tar.bz2 /var/log/syslog /var/log/messages

Extract a tar file:

tar -xvf file.tar
tar -xvzf file.tar.gz
tar -xvjf file.tar.bz2

Display the content of a tar file:

tar -tvf file.tar
tar -tvzf file.tar.gz
tar -tvjf file.tar.bz2

Replace a file in an existing tar file:

tar -rvf tarfile.tar filetoreplace

Update a file in an existing tar file:

tar -uvf tarfile.tar newfile

Copy all files in one directory to another directory on local host:

cd /etc; tar cf – . | (cd /etc.bak; tar xvpf -)

Copy a directory from one host to another and preserve ownership and permissions:

tar -cf – /var/amavisd | ssh user@otherhost tar -xf -

man pages to .ps (postscript)

Sunday, January 9th, 2005

The man command formats and displays Unix manual pages. It has the ability to format the manual pages and send them to the standard output. From manual pages:

-t Use /usr/bin/groff -Tps -mandoc -c to format the manual page, passing the output to stdout. The output from /usr/bin/groff -Tps -mandoc -c may need to be passed through some filter or another before being printed.

So simply type…

man -t man_page_name > man_page_name.ps

… and it will create a postscript formatted file containing the man page. You could then convert it to PDF or whatever you want.

See also:

  • man ps2pdf
  • man psresize

/bin/rm: Argument list too long

Friday, January 7th, 2005

My antispam system is configured to classify incoming messages and copy them to a particular sub-directory. As time pass more a more messages are accumulated in this folder. Recently I tried to eliminate old messages and I found myself with this:

/bin/rm: Argument list too long

And then I took a look at the directory and saw something like this:

ls -al | wc -l
58259

It seems that the rm command can’t deal with such number of arguments. Fortunately there are some workarounds for this problem.

ls | xargs rm

Or you can combine rm with find:

find . | xargs rm

Listing Interrupts

Friday, November 26th, 2004

To list the Interrupts/IRQ:

# dmesg | grep ‘[iI][rR][qQ]‘

$ dmesg | grep ‘[Ii][Rr][Qq]‘

ACPI: IRQ9 SCI: Edge set to Level Trigger.
ACPI: PCI Interrupt Link [LNKA] (IRQs 3 4 5 6 7 9 10 *11 12 14 15)
ACPI: PCI Interrupt Link [LNKB] (IRQs 3 4 5 6 7 9 *10 11 12 14 15)
ACPI: PCI Interrupt Link [LNKC] (IRQs 3 4 5 6 7 9 10 11 *12 14 15)
ACPI: PCI Interrupt Link [LNKD] (IRQs 3 4 *5 6 7 9 10 11 12 14 15)
ACPI: PCI Interrupt Link [LNKD] enabled at IRQ 5
ACPI: PCI Interrupt Link [LNKC] enabled at IRQ 12
ACPI: PCI Interrupt Link [LNKA] enabled at IRQ 11

Changing the look of your Linux

Tuesday, November 16th, 2004

To change your boot time grub background download a splash image and place it under /boot/grub and then edit grub.conf to add the following:

splashimage=(hd0,4)/grub/splash.xpm.gz


Note: (hd0,4) = /boot

To change gnome splash image get a splash image from GNOME-Look and place it under /usr/share/pixmaps/splash/ with the name gnome-splash.png.

To change gdm login manager get the gdm themes from GNOME-Look and use gdmsetup to install new login theme.