Tutorial on Figuring Out Your Server: Files, Directories

Env Variables
Who
This tutorial has examples for four versions of UNIX: Linux, Oracle’s Solaris, Apple’s Macintosh OS X and IBM’s AIX
Files, Directories and Storage
Once you have examined your environmental variables, you may have found one or more directories you wish to examine. If nothing grabs you, try looking at your home directory or perhaps the /etc directory. Once you have made your choice, cd to that directory.

The ls command
The most commonly used command to see what files you have is:
ls –l | more

Common variations are:

ls –la
shows all files, including files hidden with a . at the start of the file name.

ls -ld
shows directory information rather than the contents of the directory.

ls -li
shows the inode number in the first field. The operating system stores files by inode number, the directory links the name to the inode. A file can have multiple links (names) but only one
inode. For example, if you wanted to see if /bin/bash and /usr/bin/bash were really the same binary, you could use ls –li:

$ ls -li /bin/bash /usr/bin/bash
373637 -r-xr-xr-x 1 root bin 516392 Jan 5 2000 /bin/bash
373637 -r-xr-xr-x 1 root bin 516392 Jan 5 2000 /usr/bin/bash

In this example, /bin/bash and /usr/bin/bash are the same binary with inode 373637.

All UNIX files have its description stored in the inode. The inode contains info about the file
such as: size, its location, time of last access, time of last modification, permission and pointers
to the data blocks of the file. Directories are have an inode. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file.

The output for variations of ls -l is called the long format and includes:
• inode number (only if you use ls –li).
• one character describing the file type. Normal files have the type - while directories have
the type d. Other possibilities are described in Chapter 5.
• three fields of 3 characters each which describe the file permissions. r means you can
read, w means you can write, x means you can execute (or cd into if it’s a directory). First
field applies to the owner, the second to members of the group and the third to everyone
else. It is probably a security risk to give w or x permissions to everyone else.
• a number indicating the number of links to the file or directory (a file with five names
pointing to one inode will have 5 in this field).
• a field indicating the owner’s userID.
• a field indicating the group ID. This is often, but not necessarily owner’s default group.
• a number indicating the size of the file.
• The month, day and time the file was last modified.
• The file’s name.

Disk Usage
The du command is used for determining how much disk space is being used. Particularly useful is du –s * which summarizes the information by directory. The –s argument allows you to specify the files and/or directories you wish to examine.

cupertino [1]> du –s * | more
14843736 Documents
483056 Library
3492160 Pictures
16 cronop
65896 downloads

You can find out where most disk usage occurs by piping the output from du –s to sort. Try these commands:
du –s * | sort –n
du –s * | sort –nr
du –s * | sort –nr | head

You can also use the sort command in conjunction the find command to find the largest files.
find . –type f –printf “%k %p\n” | sort –nr | more

If you wish to see where your directory is physically located, use the df command. The output
from this command will show you if the data is stored on a local disk or remotely on a filer or
NFS server. Since Solaris does mirroring with the operating system, you may also be able to see if the disk is mirrored or not. Other operating systems tend to hide this information. If the
mirroring is handled by the hardware it will be transparent to the OS.

Linux:
penguin [1]> df –k | more
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda2 8254272 306580 7528396 4% /
/dev/volgrp01/banktools
14449712 3164372 10698140 23% /banktools
/dev/hda1 256667 29429 213986 13% /boot
none 1282932 0 1282932 0% /dev/shm
/dev/volgrp01/tmp 2064208 32864 1926488 2% /tmp
/dev/volgrp01/usr 4128448 532748 3385988 14% /usr
/dev/volgrp01/var 4128448 529936 3388800 14% /var
scsinfspfs01:/export/home/DEV/ADMINS/nbk6v7b
20971520 18825580 2087820 91% /home/nbk6v7b
nyinfpadm1:/export/home/sysadmin
143742676 121557612 20747636 86% /home/sysadmin

Solaris:
paloalto [1]> df -k
Filesystem kbytes used avail capacity Mounted on
/dev/md/dsk/d0 28798228 20511327 7998919 72% /
/proc 0 0 0 0% /proc
fd 0 0 0 0% /dev/fd
mnttab 0 0 0 0% /etc/mnttab
/dev/md/dsk/d2 4129290 3076788 1011210 76% /var
swap 2413032 32 2413000 1% /var/run
swap 2414600 1600 2413000 1% /tmp
/dev/vx/dsk/rootdg/ecm 95551 22545 63451 27% /export/ecm
/dev/vx/dsk/rootdg/home 143742674 121557612 20747636 86% /export/home
/dev/vx/dsk/rootdg/tempdbdev 983020 409817 474901 47% /sybase/tempdbdev
/dev/vx/dsk/rootdg/NYUSS1 3932128 1033036 2505880 30% /sybase/NY_INF_PADM1
/dev/vx/dsk/rootdg/webroot 5160542 3079184 2029753 61% /export/webroot
/dev/vx/dsk/rootdg/jumpstart 29491064 23852601 2689357 90% /export/install
/dev/vx/dsk/rootdg/linux 58982144 50563970 2519960 96% /export/linux
/dev/vx/dsk/rootdg/rrdsar 10321884 5459994 4758672 54% /var/home/admin

OS X:
cupertino [1]> df –k .
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/disk0s3 78019632 39814776 37948856 51% /

AIX:
endicott[1]> command
scsbasaqap01[2]> df -k
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 131072 96300 27% 2667 5% /
/dev/hd2 2359296 689752 71% 31791 6% /usr
/dev/hd9var 1048576 966348 8% 8938 4% /var
/dev/hd3 1048576 1007556 4% 117 1% /tmp
/dev/fwdump 262144 253876 4% 17 1% /var/adm/ras/platform
/dev/hd1 524288 147772 72% 48 1% /home1
/proc - - - - - /proc
/dev/hd10opt 3407872 1006440 71% 3251 1% /opt
/dev/ts1000 524288 305068 42% 513 1% /usr/local
/dev/ts1001 6029312 5577544 8% 727 1% /banktools
/dev/ap1000 20447232 18033080 12% 4128 1% /unibol
/dev/ap5000 7208960 6982472 4% 25 1% /usrtmp
/dev/ap5001 1048576 951828 10% 2063 1% /usrsys
/dev/ap5002 8257536 7896624 5% 22 1% /uninq
/dev/ap5003 51249152 50224140 3% 195 1% /spflprvy
/dev/ap5004 1048576 1040248 1% 17 1% /glspfl
/dev/ap5005 81920000 63014380 24% 4404 1% /micro
/dev/ap5006 81920000 67437656 18% 1913 1% /commissions
/dev/ap5007 5111808 5071336 1% 29 1% /Spars
/dev/ap5008 51249152 36467316 29% 169172 6% /bks
/dev/ap5009 81920000 14356088 83% 52189 2% /un
/dev/testlv 131072 126916 4% 17 1% /testvol

List Directory Contents
You can use ls –R to recursively list the contents of all directories encountered. This type of output is often referred to as a directory tree.

You can use
du –d depth
to generate information in a tree, where depth is how many directories deep it should go down.

Suggestions for Future Learning
This tutorial is excerpted from UNIX For Application Support Staff Chapter 1. More information on ls can be found in Chapter 5 and on mirroring in Appendix 2.



Tutorial Contents



Name Service queries with DNS and NIS



What Is My Server’s Configuration ?

Hardware Information : CPU and Memory

Environmental Variables : Your Configuration


Disk Usage  and Listing Directory Contents

Who Else  is Logged in?


Env Variables
Who