Friday, February 27, 2009

Quickly Find Out What a Command Does Based on Its Name

man -f
If you know a command's name but don't know what it does, there's a quick and dirty way to find out without requiring you to actually open the man page for that command. Use the -f option (or --whatis), and the command's synopsis appears.

$ man -f ls
ls (1) - list directory contents


source scott grannemann

Rebuild man's Database of Commands

man -u
Occasionally you'll try to use man to find out information about a command and man reports that there is no page for that command. Before giving up, try again with the -u option (or --update), which forces man to rebuild the database of commands and man pages it uses. It's often a good first step if you think things aren't quite as they should be.

$ man ls
No manual entry for ls
$ man -u ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
[Listing condensed due to length]

Sort Contents by File Extension

ls -X

The name of a file is not the only thing you can use for alphabetical sorting. You can also sort alphabetically by the file extension. In other words, you can tell ls to group all the files ending with .doc together, followed by files ending with .jpg, and finally finishing with files ending with .txt. Use the -X option (or --sort=extension); if you want to reverse the sort, add the -r option (or --reverse).

Copy Files As Perfect Backups in Another Directory

Copy Files As Perfect Backups in Another Directory

cp -a

You might be thinking right now that cp would be useful for backing up files, and that is certainly true. With a few lines in a bash shell script, however, cp can be an effective way to back up various files and directories. The most useful option in this case would be the -a option (or --archive), which is also equivalent to combining several options: -dpR (or --no-dereference --preserve --recursive). Another way of thinking about it is that -a ensures that cp doesn't follow symbolic links (which could grossly balloon your copy), preserves key file attributes such as owner and timestamp, and recursively follows subdirectories.


source: scott grannemann

How to Visually Display a File's Type ?

How to Visually Display a File's Type ?

Soln: ls -F

Character Meaning


* Executable
/ Directory
@ Symbolic link
| FIFO
= Socket

Monday, February 23, 2009

modinfo

the modinfo command displays information about one or more modules.

Ex:

/sbin/modinfo floppy
filename: /lib/modules/2.6.24-21-generic/kernel/drivers/block/floppy.ko
alias: block-major-2-*
license: GPL
author: Alain L. Knaff
srcversion: 82A3853812A05EA35470909
depends:
vermagic: 2.6.24-21-generic SMP mod_unload 586
parm: floppy:charp
parm: FLOPPY_IRQ:int
parm: FLOPPY_DMA:int

df

df displays information about mounted filesystems. if you add the -T option, then the filesystem type is included in the display.



df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext3 76058116 11954216 60270796 17% /
varrun tmpfs 252996 120 252876 1% /var/run
varlock tmpfs 252996 0 252996 0% /var/lock
udev tmpfs 252996 64 252932 1% /dev
devshm tmpfs 252996 12 252984 1% /dev/shm
lrm tmpfs 252996 39780 213216 16% /lib/modules/2.6.24-21-generic/volatile
/dev/sdb5 ext3 242271360 30132684 199928880 14% /data
gvfs-fuse-daemon
fuse.gvfs-fuse-daemon 76058116 11954216 60270796 17% /home/zodiac/.gvfs
/dev/sdc1 vfat 1951200 8320 194288



to display inode usage

df -i -x tmpfs
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 4792320 192604 4599716 5% /
/dev/sdb5 15269888 341 15269547 1% /data
gvfs-fuse-daemon 4792320 192604 4599716 5% /home/zodiac/.gvfs
/dev/sdc1 0 0 0 - /media/disk


if you aren't sure which filesystem a particular part of your directory tree lives on, you can give the df command a parameter of a directory name or even a filename
Ex:
df -H ~zodiac/myfile.txt
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 78G 13G 62G 17% /


Watching the disk space

If you want to repeat a command many times, for example you are monitoring something, then don’t forget about the watch command. It will print the results of the command to screen every 2 seconds (you can change the interval with -n).

watch --no-title "df -h"