A blog for Linux Lovers.

Archive for the ‘Linux Helps’ Category

Posted by sibu on August 28, 2014

Values in the “TOP command.

PID — Process Id
The task’s unique process ID, which periodically wraps, though
never restarting at zero.

PPID — Parent Process Pid
The process ID of a task’s parent.

RUSER — Real User Name
The real user name of the task’s owner.

UID — User Id
The effective user ID of the task’s owner.

USER — User Name
The effective user name of the task’s owner.

GROUP — Group Name
The effective group name of the task’s owner.

TTY — Controlling Tty
The name of the controlling terminal. This is usually the
device (serial port, pty, etc.) from which the process was
started, and which it uses for input or output. However, a
task need not be associated with a terminal, in which case
you’ll see ‘?’ displayed.

PR — Priority
The priority of the task.

NI — Nice value
The nice value of the task. A negative nice value means higher
priority, whereas a positive nice value means lower priority.
Zero in this field simply means priority will not be adjusted
in determining a task’s dispatchability.

— Last used CPU (SMP)
A number representing the last used processor. In a true SMP
environment this will likely change frequently since the kernel
intentionally uses weak affinity. Also, the very act of
running top may break this weak affinity and cause more
processes to change CPUs more often (because of the extra
demand for cpu time).

%CPU — CPU usage
The task’s share of the elapsed CPU time since the last screen
update, expressed as a percentage of total CPU time. In a true
SMP environment, if ‘Irix mode’ is Off, top will operate in
‘Solaris mode’ where a task’s cpu usage will be divided by the
total number of CPUs. You toggle ‘Irix/Solaris’ modes with the
‘I’ interactive command.

Total CPU time the task has used since it started. When
‘Cumulative mode’ is On, each process is listed with the cpu
time that it and its dead children has used. You toggle
‘Cumulative mode’ with ‘S’, which is a command-line option and
an interactive command. See the ‘S’ interactive command for
additional information regarding this mode.

TIME+ — CPU Time, hundredths
The same as ‘TIME’, but reflecting more granularity through
hundredths of a second.

%MEM — Memory usage (RES)
A task’s currently used share of available physical memory.

VIRT — Virtual Image (kb)
The total amount of virtual memory used by the task. It
includes all code, data and shared libraries plus pages that
have been swapped out and pages that have been mapped but not

SWAP — Swapped size (kb)
Memory that is not resident but is present in a task. This is
memory that has been swapped out but could include additional
non-resident memory. This column is calculated by subtracting
physical memory from virtual memory.

— Resident size (kb)
The non-swapped physical memory a task has used.

CODE — Code size (kb)
The amount of virtual memory devoted to executable code, also
known as the ‘text resident set’ size or TRS.

DATA — Data+Stack size (kb)
The amount of virtual memory devoted to other than executable
code, also known as the ‘data resident set’ size or DRS.

SHR — Shared Mem size (kb)
The amount of shared memory used by a task. It simply reflects
memory that could be potentially shared with other processes.

nFLT — Page Fault count
The number of major page faults that have occurred for a task.
A page fault occurs when a process attempts to read from or
write to a virtual page that is not currently present in its
address space. A major page fault is when backing storage
access (such as a disk) is involved in making that page

nDRT — Dirty Pages count
The number of pages that have been modified since they were
last written to disk. Dirty pages must be written to disk
before the corresponding physical memory location can be used
for some other virtual page.

S — Process Status
The status of the task which can be one of:
‘D’ = uninterruptible sleep
‘R’ = running
‘S’ = sleeping
‘T’ = traced or stopped
‘Z’ = zombie

Posted by sibu on December 28, 2011

SED and AWK command

sed (stream editor)

Sed is a non-interactive editor. Instead of altering a file by moving the cursor on the screen, you use a script of editing instructions to sed, plus the name of the file to edit. You can also describe sed as a filter.
Let’s have a look at some examples:
$sed ’s/to_be_replaced/replaced/g’ /tmp/dummy

Sed replaces the string ‘to_be_replaced’ with the string ‘replaced’ and reads from the /tmp/dummy file. The result will be sent to stdout (normally the console) but you can also add ‘> capture’ to the end of the line above so that sed sends the output to the file ‘capture’.
$sed 12, 18d /tmp/dummy

Sed shows all lines except lines 12 to 18. The original file is not altered by this command.

awk (manipulation of datafiles, text retrieval and processing)

Many implementations of the AWK programming language exist. AWK scans for a pattern, and for every matching pattern a action will be performed.

I’ve created a dummy file containing the following lines:

$awk ‘/test/ {print}’ /tmp/dummy


The pattern AWK looks for is ‘test’ and the action it performs when it found a line in the file /tmp/dummy with the string ‘test’ is ‘print’.
$awk ‘/test/ {i=i+1} END {print i}’ /tmp/dummy

Another example

-bash-3.00# ls -al |grep boot
-rw——- 1 root root 170 Aug 7 17:14 boot.log
-rw——- 1 root root 0 May 9 2010 boot.log.1
-rw——- 1 root root 0 May 2 2010 boot.log.2

-bash-3.00# ls -al |grep boot |awk ‘{print $9 }’

Posted by sibu on January 11, 2010

Stderr and Stdout Redirection.

1.) stdout to a file

The output of a command will redirect to another file.

Eg:          ls -l > list.txt

2.) stderr to a  file

The following command will redirect the  stderr ouput of a program to a new file.

Eg:       grep sibu * 2> grep-errors.txt

Here, a file called ‘grep-errors.txt’ will be created and it will contain what you would see the stderr portion of the output of the ‘grep sibu *’ command.

3.) Stdout to Stderr

This will cause the stderr ouput of a program to be written to the same filedescriptor than stdout.

Eg:          grep sibu * 1>&2

Here, the stdout portion of the command is sent to stderr..

4.): stderr to stdout

This will cause the stderr ouput of a program to be written to the same filedescriptor than stdout.

Eg:       grep * 2>&1

Here, the stderr portion of the command is sent to stdout.

5.) stderr and stdout 2 file

This will place every output of a program to a file. This is suitable sometimes for cron entries, if you want a command to pass in absolute silence.

Eg:       rm -f $(find / -name core) &> /dev/null

Posted by sibu on June 20, 2009

History with Time and Date.

History with Time and Date

The command history will give you the list of command which you executed earlier. By default you won’t get the the command execution time and date.

If you wish to have a history details with time and date please do the following.

Open /etc/bashrc file and add the following line.

Export HISTTIMEFORMAT=”%h%d - %H:%M:%S”

After adding this line, relogin to the shell and execute the history command.

Posted by sibu on June 18, 2009

Zombie process

Zombie process is an inactive computer process, according to wikipedia article, “…On Unix operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. In the term’s colorful metaphor, the child process has died but has not yet been reaped…”

Use top or ps command to find out zombie process.

# top
# ps aux | awk ‘{ print $8 ” ” $2 }’ | grep -w Z


Z 4104
Z 5320
Z 2945

You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

You can kill zombie process using PID obtained from any one of the above command. For example kill zombie proces having PID 4104.

# kill -9 4104

Please note that kill -9 does not guarantee to kill a zombie process.Write a script and schedule as a cron job.The following is a script to kill Zombie processes.


for each in `ps -ef | grep ” | grep -v PID | awk ‘{ print $3 }’`; do
for every in `ps -ef | grep $each | grep -v cron | awk ‘{ print $2 }’`; do
kill -9 $every;

Posted by sibu on May 24, 2009

Yum Commands

YUM packages updater (Fedora, RedHat and like)

yum install package_name download and install a rpm package
yum localinstall package_name.rpm That will install an RPM, and try to resolve all the dependencies for you using your repositories.
yum update update all rpm packages installed on the system
yum update package_name upgrade a rpm package
yum remove package_name remove a rpm package
yum list list all packages installed on the system
yum search package_name find a package on rpm repository
yum clean packages clean up rpm cache erasing downloaded packages
yum clean headers remove all files headers that the system uses to resolve dependency
yum clean all remove from the cache packages and headers files

Posted by sibu on May 24, 2009

RPM commands

rpm -ivh package.rpm install a rpm package
rpm -ivh –nodeps package.rpm install a rpm package ignoring dependencies requests
rpm -U package.rpm upgrade a rpm package without changing configuration files
rpm -F package.rpm upgrade a rpm package only if it is already installed
rpm -e package_name.rpm remove a rpm package
rpm -qa show all rpm packages installed on the system
rpm -qa | grep httpd show all rpm packages with the name “httpd”
rpm -qi package_name obtain information on a specific package installed
rpm -qg “System Environment/Daemons” show rpm packages of a group software
rpm -ql package_name show list of files provided by a rpm package installed
rpm -qc package_name show list of configuration files provided by a rpm package installed
rpm -q package_name –whatrequires show list of dependencies required for a rpm packet
rpm -q package_name –whatprovides show capability provided by a rpm package
rpm -q package_name –scripts show scripts started during installation / removal
rpm -q package_name –changelog show history of revisions of a rpm package
rpm -qf /etc/httpd/conf/httpd.conf verify which rpm package belongs to a given file
rpm -qp package.rpm -l show list of files provided by a rpm package not yet installed
rpm –import /media/cdrom/RPM-GPG-KEY import public-key digital signature
rpm –checksig package.rpm verify the integrity of a rpm package
rpm -qa gpg-pubkey verify integrity of all rpm packages installed
rpm -V package_name check file size, permissions, type, owner, group, MD5 checksum and last modification
rpm -Va check all rpm packages installed on the system - use with caution
rpm -Vp package.rpm verify a rpm package not yet installed
rpm2cpio package.rpm | cpio –extract –make-directories *bin* extract executable file from a rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm install a package built from a rpm source
rpmbuild –rebuild package_name.src.rpm build a rpm package from a rpm source

Posted by sibu on May 24, 2009

File search commands

find  / -name file1 - search file and directory into root filesystem from ‘/’
find / -user user1 - search files and directories belonging to ‘user1′
find /home/user1 -name \*.bin - search files with ‘. bin’ extension within directory ‘/ home/user1′
find /usr/bin -type f -atime +100 - search binary files are not used in the last 100 days
find /usr/bin -type f -mtime -10 - search files created or changed within 10 days
find / -name \*.rpm -exec chmod 755 ‘{}’ \;   - search files with ‘.rpm’ extension and modify permits
find / -xdev -name \*.rpm - search files with ‘.rpm’ extension ignoring removable partitions as cdrom, pen-drive, etc.…
locate \*.ps - find files with the ‘.ps’ extension - first run ‘updatedb’ command
whereis halt -  show location of a binary file, source or man
which halt  - show full path to a binary / executable

Posted by sibu on May 24, 2009

User management commands

Users and Groups

groupadd group_name create a new group
groupdel group_name delete a group
groupmod -n new_group_name old_group_name rename a group
useradd -c “Name Surname ” -g admin -d /home/user1 -s /bin/bash user1 create a new user belongs “admin” group
useradd user1 create a new user
userdel -r user1 delete a user ( ‘-r’ eliminates home directory)
usermod -c “User FTP” -g system -d /ftp/user1 -s /bin/nologin user1 change user attributes
passwd change password
passwd user1 change a user password (only by root)
chage -E 2005-12-31 user1 set deadline for user password
pwck check correct syntax and file format of ‘/etc/passwd’ and users existence
grpck check correct syntax and file format of ‘/etc/group’ and groups existence
newgrp group_name log in to a new group to change default group of newly created files.

Posted by sibu on March 10, 2009

Difference between soft link and hard link

Hard Links :

1. All Links have same inode number. -l command shows all the links with the link column(Second) shows No. of links.

3. Links have actual file contents

4.Removing any link ,just reduces the link count , but doesn’t affect other links.

Soft Links(Symbolic Links) :

1.Links have different inode numbers.

2. ls -l command shows all links with second column value 1 and the link points to original file.

3. Link has the path for original file and not the contents.

4.Removing soft link doesn’t affect anything but removing original file ,the link becomes “dangling” link which points to nonexistant file.