Useful linux commands: null,zero,full,lsof

Posted on November 1, 2009. Filed under: Linux | Tags: , , , |

Linux / Unix Command: null

NAME

null, zero – data sink

DESCRIPTION

Data written on a null or zero special file is discarded.

Reads from the null special file always return end of file, whereas reads from zero always return characters.

null and zero are typically created by:

mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
chown root:mem /dev/null /dev/zero
chmod 666 /dev/null /dev/zero

References:

http://linux.about.com/library/cmd/blcmdl4_null.htm

DESCRIPTION
File /dev/full has major device number 1 and minor device number 7.

Writes  to  the  /dev/full device will fail with an ENOSPC error.  This
can be used to test how a program handles disk-full errors.

Reads from the /dev/full device will return characters.

Seeks on /dev/full will always succeed.

CONFIGURING
If your system does not have /dev/full created already, it can be  cre-
ated with the following commands:

mknod -m 666 /dev/full c 1 7
chown root:root /dev/full

Reference:

man full

lsof

lsof is a command meaning “list open files”, which is used in many Unix-like systems to report a list of all open files and the processes that opened them. This open source utility was developed and supported by Vic Abell, the retired Associate Director of the Purdue University Computing Center. It works in and supports several UNIX flavors.[2]

Open files in the system include disk files, pipes, network sockets and devices opened by all processes. One use for this command is when a disk cannot be unmounted because (unspecified) files are in use. The listing of open files can be consulted (suitably filtered if necessary) to identify the process that is using the files.

# lsof /var
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
syslogd     350     root    5w  VREG  222,5        0 440818 /var/adm/messages
syslogd     350     root    6w  VREG  222,5   339098   6248 /var/log/syslog
cron        353     root  cwd   VDIR  222,5      512 254550 /var -- atjobs

To view the Port associated with a daemon :

 # lsof -i -n -P | grep sendmail
 sendmail  31649    root    4u  IPv4 521738       TCP *:25 (LISTEN)

From the above we can see that “sendmail” is listening on its standard port of “25”.

  • -i Lists IP sockets.
  • -n Do not resolve hostnames (no DNS).
  • -P Do not resolve port names (list port number instead of its name).

Reference:

http://en.wikipedia.org/wiki/Lsof

man lsof

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: