Monday, July 28, 2008

Finding the Largest and the Smallest File in a Directory

1. In order to find 9 largest files in a directory (say /etc),
please give following command:
$ ls -lS /etc | head

total 2816
-rw-r--r-- 1 root root 600399 2008-07-28 10:11 prelink.cache
-rw-r--r-- 1 root root 362047 2007-04-18 14:10 services
-rw-r--r-- 1 root root 144190 2007-10-12 15:08 lynx.cfg
-rw-r--r-- 1 root root 122098 2008-07-25 10:47
-rw-r--r-- 1 root root 117276 2007-09-17 17:57 Muttrc
-rw-r--r-- 1 root root 114765 2007-10-11 01:28 gwen-public-ca.crt
-rw-r--r-- 1 root root 84649 2007-08-23 12:54 sensors.conf
-rw-r--r-- 1 root root 44990 2007-10-16 18:50 php.ini
-rw-r--r-- 1 root root 31274 2007-10-09 14:33 jwhois.conf

2. In order to find 9 smallest files in a directory (say /etc),
please give following command:

$ ls -lSr /etc | head
total 2816
-rw-r--r-- 1 root root 0 2007-08-03 06:09 odbc.ini
-rw-r--r-- 1 root root 0 2000-01-13 04:48 motd
-rw-r--r-- 1 root root 0 2000-01-13 04:48 exports
-rw-r--r-- 1 root root 0 2007-08-16 19:23 environment
-rw-rw-r-- 1 root disk 0 2007-08-22 17:15 dumpdates
-rw-r--r-- 1 root root 0 2007-09-24 19:28 cron.deny
-rw------- 1 root root 1 2007-10-05 17:41 at.deny
lrwxrwxrwx 1 root root 7 2008-07-18 03:26 rc -> rc.d/rc
lrwxrwxrwx 1 root root 10 2008-07-18 03:26 rc6.d -> rc.d/rc6.d

Wednesday, July 23, 2008

Installing Linux (Fedora 8) on Macbook Pro

I was trying to install Linux on Macbook Pro along with Mac OS X, because
it has Intel Processor, Intel chipset on Motherboard
and Nvidia 8600 GT graphics card. I followed steps
given in Debian Wiki (Mainly upto rEFIt part) and
in Mactel (for remaining part).

I would like to suggest some tips regarding installation of
Fedora 8 along with Mac OS X on Macbook Pro.

  1. Audio: Download the latest Linux kernel and compile it with Intel HD Audio drivers 82801H (ICH8 Family).
  2. Video: Boot into new kernel, and install NVidia driver, restart X server by logging out and logging in.
  3. Keyboard: Download pomme daemon, Compile and install it. Now Optical Drive Eject button will work.
  4. Backlight: Even after installing pommed, I was seeing very bright screen. I was not able to stare at screen for more than a minute. Later, after some tweaking of /etc/pommed.conf , I was able to decrease the backlit. I changed init = -1 to init = 1, as shown below:
# nVidia GeForce 8600M GT backlight control (MacBook Pro v3 & v4)
lcd_nv8600mgt {
# initial backlight level [12] (0 - 15, -1 to disable)
init = 1
# step value (1 - 2)
step = 1
# backlight level when on battery [6] (1 - 15, 0 to disable)
on_batt = 6

PS: Everything else should work as given in Mactel site. Feel free to write
comments. If you have any doubt, mail me at mitesh[dot]singh[dot]jat[at]gmail[dot]com

Friday, July 18, 2008

What is Pseudo Terminal (PTY)?

Honestly, I did not know about the Pseudo Terminal before facing a problem. I had overwritten /etc/fstab in Fedora 8. As a result, I was not able to open either Terminal or Konsole. The error, I was getting, was:

Not enough permission for PTY device.

Then, I searched Internet for PTY device, there I found the full form of PTY, which is Pseudo Terminal.

Like the /dev directory, /dev/pts contains entries corresponding to devices. But unlike /dev, which is an ordinary directory, /dev/pts is a special directory that is created dynamically by the Linux kernel.The contents of the directory vary with time and reflect the state of the running system.

The entries in /dev/pts correspond to pseudo-terminals (or pseudo-TTYs, or PTYs). Linux creates a PTY for every new terminal window you open and displays a corresponding entry in /dev/pts.The PTY device acts like a terminal device—it accepts input from the keyboard and displays text output from the programs that run in it. PTYs are numbered, and the PTY number is the name of the corresponding entry in /dev/pts.

Then, I searched for how to open Pseudo Terminal with enough permissions.

Solution: Since I had overwritten the /etc/fstab, the entry to

mount devpts was not present. I then created the following entry in /etc/fstab file.

# file_system mount_point type options dump pass

none /dev/pts devpts (rw,mode=620) 0 0

Thursday, July 10, 2008

Password-less SSH for Batch Processing

1. Generation of Public-Private RSA key pair.

$ mkdir -p ~/.ssh
$ cd ~/.ssh
$ ssh-keygen -f keyname-identity -P '' -t rsa1

2. Allowing Password less Login on remote-machine.

Copy your public key on remote-machine.
$ scp remote-machine:./.ssh/authorized_keys

Edit authorized_keys on remote-machine
Please place this line before your public key
in the authorized_keys file content

For example:

from="local-machine",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,command="ls -la" 2048 35 1383...

3. Please make your private key secure.

$ chmod 511 ~/.ssh
$ chmod 400 ~/.ssh/keyname-identity

!! Caution !!

Putting a password less key in a file is exactly like writing a password on a piece of paper. A person who can access to your key file can do whatever you can do with the key.

Tuesday, July 8, 2008

Creation of ISO Image of CD/DVD

If you want to create ISO image of CD/DVD in the
optical drive, please give the following command:

$ dd if=/dev/hdc of=/path/of/iso/image/xyz.iso

You can replace /dev/hdc (for Secondary Master)
with the CD/DVD drive path on your system. like

/dev/hdb (for Primary Slave)
/dev/sdc (for SATA optical drive,
or newer drive naming convention)

Tuesday, July 1, 2008

Most CPU Using Processes

The following 1 line script prints the processes which are using CPU most of the time:

$ top -d 3600 -n 24 | awk '{arr[$13] += $10} END { for (x in arr) print x" \t"arr[x]; }' | sort -r -n -k2 > daily_stats

You can vary value of -d ---- and -n -- of top, to increase accuracy of
statistics. i.e. (delay) * (count) should be 86400 always for daily
for example:

$ top -d 1800 -n 48 | awk '{arr[$13] += $10} END { for (x in arr) print x" \t"arr[x]; }' | sort -r -n -k2 > daily_stats