Archive for the tag 'Files'

SBDavid

lsof - list open files example

To list all open files, use:

lsof

To list all open Internet, x.25 (HP-UX), and UNIX domain files, use:

lsof -i -U

To list all open IPv4 network files in use by the process whose PID is 1234, use:

lsof -i 4 -a -p 1234

Presuming the UNIX dialect supports IPv6, to list only open IPv6 network files, use:

lsof -i 6

To list all files using any protocol on ports 513, 514, or 515 of host wonderland.cc.pur-due.edu, use:

lsof -i @wonderland.cc.purdue.edu:513-515

To list all open files for login name “abe”, or user ID 1234, or process 456, or pro-cess 123, or process 789, use:

lsof -p 456,123,789 -u 1234,abe

To list all open files on device /dev/hd4, use:

lsof /dev/hd4

To find the process that has /u/abe/foo open, use:

lsof /u/abe/foo

To send a SIGHUP to the processes that have /u/abe/bar open, use:

kill -HUP `lsof -t /u/abe/bar`

To find any open file, including an open UNIX domain socket file, with the name /dev/log,use:

lsof /dev/log

fuser - identify processes using files or sockets

In order to look up processes using TCP and UDP sockets, the corresponding name space has to be selected with the -n option. By default fuser will look in both IPv6 and IPv4 sock-ets. To change the default, behavior, use the -4 and -6 options. The socket(s) can be specified by the local and remote port, and the remote address. All fields are optional, but commas in front of missing fields must be present:

[lcl_port][,[rmt_host][,[rmt_port]]]

Either symbolic or numeric values can be used for IP addresses and port numbers.

fuser outputs only the PIDs to stdout, everything else is sent to stderr.

root@dell:~# fuser -nv tcp 25
USER PID ACCESS COMMAND
25/tcp: root 3926 F…. master

FILES

/proc location of the proc file system

EXAMPLES

fuser -km /home kills all processes accessing the file system /home in any way.

if fuser -s /dev/ttyS1; then :; else something; fi invokes something if no other process
is using /dev/ttyS1.

fuser telnet/tcp shows all processes at the (local) TELNET port.

Kinds of device files in Linux operating systems

There are two general kinds of device files in Unix-like operating systems, known as character special files and block special files. The difference between them lies in how data written to them and read from them is processed by the operating system and hardware.

These together can be called device special files in contrast to named pipes, which are not connected to a device but are not ordinary files either.

Symbol Meaning
- Regular file
d Directory
l Link
c Special file
s Socket
p Named pipe
b Block device
SBDavid

ln Make links between files

ln: Make links between files

A “hard link” is another name for an existing file; the link and the original are indistinguishable. Technically speaking, they share the same inode, and the inode contains all the information about a
file–indeed, it is not incorrect to say that the inode _is_ the file. On all existing implementations, you cannot make a hard link to a directory, and hard links cannot cross file system boundaries. (These
restrictions are not mandated by POSIX, however.)

“Symbolic links” (”symlinks” for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually
refers to a different file, by name.

`ln’ makes links between files. By default, it makes hard links; with the `-s’ option, it makes symbolic (or “soft”) links. Synopses:

ln [OPTION]… [-T] TARGET LINKNAME
ln [OPTION]… TARGET
ln [OPTION]… TARGET… DIRECTORY
ln [OPTION]… -t DIRECTORY TARGET…

* If two file names are given, `ln’ creates a link to the first file from the second.

* If one TARGET is given, `ln’ creates a link to that file in the current directory.

Example:

@dell:~/x$ ls -li
total 0
1268369 -rw-r–r– 1 user1 user1 0 Jan 13 16:42 1
1268732 lrwxrwxrwx 1 user1 user1 1 Jan 13 16:42 2 -> 1

1268733 -rw-r–r– 2 user1 user1 0 Jan 13 16:43 3
1268733 -rw-r–r– 2 user1 user1 0 Jan 13 16:43 4
@dell:~/x$

Postfix uses database files for access control

Postfix uses database files for access control, address rewriting and other purposes.

Here is a common example of how Postfix invokes a database:

/etc/postfix/main.cf:
virtual_alias_maps = hash:/etc/postfix/virtual

Whenever you make a change to the main.cf or master.cf file, execute the following command as root in order to refresh a running mail system:

# postfix reload

« Prev - Next »