Monthly Archives: March 2008

Almost all modern shell allows you to search command history if enabled by user. Use history command to display the history list with line numbers. Lines listed with with a * have been modified by user.
Shell history search command

Type history at a shell prompt:
$ history
Output:
Sample output:
6 du -c
7 du -ch
8 ls [01-15]*-2008
9 ls -ld [01-15]*-2008
….
41 g++ prime1.cpp
42 ./a.out
43 ssh ankit@delta
44 scp ~/Desktop/passport.jpg ankit@delta:
45 man expr
46 iptab
47 history

….

996 ping intrarouter.delta.nitt.edu
997 ssh ankit@intrarouter.delta.nitt.edu
998 alias
999 ~/scripts/clean.rss –fetch
1000 vnstat
1001 ~/scripts/clean.rss –update

To search particular command, enter:

$ history | grep command-name
$ history | egrep -i 'scp|ssh|ftp'

Emacs Line-Edit Mode Command History Searching

To get previous command containing string, hit [CTRL]+[r] followed by search string:
(reverse-i-search):

To get previous command, hit [CTRL]+[p]. You can also use up arrow key.
CTRL-p

To get next command, hit [CTRL]+[n]. You can also use down arrow key.
CTRL-n

fc command

fc stands for either “find command” or “fix command. For example list last 10 command, enter:

$ fc -l 10

To list commands 130 through 150, enter:
$ fc -l 130 150

To list all commands since the last command beginning with ssh, enter:
$ fc -l ssh

You can edit commands 1 through 5 using vi text editor, enter:
$ fc -e vi 1 5

Delete command history

The -c option causes the history list to be cleared by deleting all of the entries:
$ history -c

There are total 4 steps involved for hard disk upgrade and installation procedure:

Step #1 : Partition the new disk using fdisk command

Following command will list all detected hard disks:
# fdisk -l | grep '^Disk'

Output:
Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes
A device name refers to the entire hard disk.

To partition the disk – /dev/sdb, enter:
# fdisk /dev/sdb
The basic fdisk commands you need are:

  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • w – write the new partition table and exit

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1


Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H


Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab

Append as follows:
/dev/sdb1 /disk1 ext3 defaults 1 2
Save and close the file.

Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup

You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new root password.

Step # 5: Exit and restart MySQL server.

Here are commands you need to type for each step (login as the root user):
Step # 1 : Stop mysql service
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
Step # 2: Start to MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988

Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe[6025]: started
Step # 3: Connect to mysql server using mysql client:
# mysql -u root
Output:
Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-logType ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>
Step # 4: Setup new MySQL root user password.
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step # 5: Stop MySQL Server:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld

STOPPING server from pid file /var/run/mysqld/mysqld.pid

mysqld_safe[6186]: ended[1]+ Done mysqld_safe –skip-grant-tables
Step # 6: Start MySQL server and test it
# /etc/init.d/mysql start
# mysql -u root -p