File Commands

File System
Disk Status
  • crfs – create new
  • mkfs – create
  • chlv – expand beyond max LV’s
  • chfs – change attributes
  • fsck – check or fix
  • rmfs – remove
  • mount – mount
  • umount – unmount
  • sync – flushes system buffers to disk
  • df – display status of mounted file systems
  • du – display disk usage
  • istat – display dates of access for a file
  • ls – display contents of a directory
  • fuser – display users using a file system
Directories & Files
  • ln – link files or directories
  • unlink – unlink a file or directory
  • mv – rename files or directories
  • mvdir – rename directories
  • dircmp – compare files in different directories
  • cat – display contents of text or ascii file
  • cp – copy files or directories
  • del – delete file
  • rm – remove files or directories

Understanding the AIX File System

The AIX file system contains 3 major elements:

  • Physical Volumes (PV)
  • Volume Groups (VG)
  • Logical Volumes (LV) IBM likes to use abbreviations, so get used to calling Physical Volumes PV’s, etc.
Definition What is it Examples
Physical Volumes A Physical Volume is an actual physical device, i.e. disk drive. Each disk drive contains a Physical Volume. Physical Volume’s are broken into Physical Partitions (PP’s) where each Physical Partition is 4MB in size. A system with 2 drives, could contain Physical Volume’s hdisk0 and hdisk1.
Volume Groups Volume Group’s are a set of one or more Physical Volume’s. Each Volume Group can contain one or more Logical Volumes Physical Volume hdisk0 could contain Volume Group rootvg and Physical Volume hdisk1 could contain Volume Group datavg.
Logical Volumes Logical Volume’s are used to define groups of files, i.e. File Systems. Each Logical Volume contains Logical Partitions (LP’s) Volume Group rootvg could contain Logical Volume’s hd1, hd2, hd3.
Where the mounting points for hd1 = ‘/’ (root), hd2 = /usr, hd3 = /tmp

Here’s a table to help make this clearer, I hope.

Physical Volume Volume Group Logical Volume
drive 1 = hdisk0 rootvg hd1 mounted as /
drive 2 = hdisk1 datavg hd2 mounted as /var, hd3 mounted as /tmp

You can use smit to display or configure your file systems. Here are some commands that smit uses that you can use at the command line to provide the necessary information. The following commands only display information.

Physical Volume Information
Examples What it does
lspv Displays a list of all Physical Volume’s with the drive name and associated Volume Group’s
lspv <physicalvolume> Displays a specific Physical Volume. Stale partitions refers to mirroring.
If the Physical Volume has no mirrored Logical Partitions, then the value for this field is zero
lspv -l <physicalvolume> Displays what Logical Volumes reside on the named Physical Volume along with Logical Partition’s Physical Partition’s and Mounting Point.
lspv -p <physicalvolume> Displays distribution of Physical Partitions for each Logical Volume that reside on the named Physical Volume along with State, Region, Type and Mounting Point.
lspv -s <physicalvolume> Displays Physical Volume, total, free and used Physical Partitions.
lsvg -n <physicalvolume> Displays total, free and used Physical Partitions and other information.
Volume Group Information
Examples What it does
lsvg Displays all Volume Groups
lsvg <volumegroup> Displays all Volume Groups, total, free and used Physical Partitions
lsvg -p <volumegroup> Displays Physical Volume, State and Physical Partition information
lsvg -l <volumegroup> Displays Logical Volume name, Type, Logical Partitions, Physical Partitions, Physical Volumes, Logical Volume State and Mounting Point
Logical Volume Information
Examples What it does
lslv <logicalvolume> Displays Volume Group, Mirror State, Mount Point and more…
lslv -l <logicalvolume> Displays Physical Volume, Copies, Distribution info

top of page


Maximums

The smallest file extension is 4Kb. If a user creates or extends a file anywhere from 0-4096 bytes, a 4K block will be allocated from the free list to accommodate that request. When a file system is extended by 1 Physical Partition (4 MB), 1024 inodes are allocated to that file system.
length of a filename : 255 characters
number of open files per process : 2,000
number of open files system-wide : 200,000
number of record locks per process: 200,000
number of record locks system-wide: 200,000
bytes per pipe : 32,768
number of pipes per process : 2,000
number of semaphore IDs : 4,096
number of semaphores per ID : 100 K
number of operations per semop call : 1,024
semaphore value : 32,767
adjust on exit : 16,384
number of message queue IDs : 4,096
bytes per message : 8,192
bytes per message queue : 65,536
messages per message queue : 8,192
number of segments system-wide : 16 MB
number of shared memory segments : 4,096
number of segments per process : 10
bytes per segment 256 MB
top of page


Path Definitions

Directory What’s in it
/bin utilities
/sbin files needed to boot the machine and mount the /usr file system
/dev special files (I/O devices)
/etc miscellaneous administrative utilities
/home user directories and files
/lib libraries
/tmp temporary files. Needs to be at least 12 MB
/usr common executables that are shared across the same architecture
/usr/adm administrative commands and files
/usr/bin utilities (overflow for /bin)
/usr/lib archive libraries, text processing macros
/usr/spool/mail Email files
/usr/sbin utilities used in system administration, including smit
/usr/share architecture-independent, shareable text files
/usr/share/man manual pages
/usr/share/dict spelling dictionary and its indexes
/usr/share/info InfoExplorer database files
/usr/share/lib architecture-independent data files, including terminfo
/usr/share/lpp data about optional program products (OPP)
/var/adm system logging and accounting files
/var/preserve preserved data from interrupted edit sessions
/var/spool spool files for printing
/var/tmp temporary files

top of page


cat – Concatenates or displays one or more files

Examples What it does
cat -v textfile The -v option will display non-printing characters.
tput clear | cat -v Displays the control codes generated to clear the screen.

top of page


chlv – Used to expand beyond the maximum Logical Volume limit

chlv -x 256 <lv_name> (Where logical volume name is entered without the /dev)

top of page


chfs – Changes attributes of a file system

Block size for this command is 512 byte blocks, where the command df, returns disk info in 1024 byte blocks.  The simplest method of extending a file system is to

  • Take the target size of the file system in MB’s and multiple by 2000.
  • If the file system size is to be extended to 12MB in size, then 12 * 2000 = 24000.

Remember, when you extend a file system, you extend the logical volume that resides under it. Most systems have a default Physical Partition size of 4MB (review output of lsvg rootvg command) and therefore when the file system increases in size, it will increase by a multiple of 4MBs.

chfs -a size=24000 /usr (Increase the /usr file system to 12MBs.)

top of page


cp  – Copies one or more files

Examples What it does
cp /u/roger/test /tmp Copies the file test in the directory /u/roger to the /tmp directory
cp -ipr . /tmp/temp Copies all the files and subdirectories from the current directory to the directory named /tmp/temp.

  • -i If a filename already exists in the destination directory, the system will prompt you to overwrite this file with the one being copied from the source directory.
  • -p Preserves file permissions, owner, group, and modification attributes of the file beingcopied to it’s new destination.
  • -r Copies all files and subdirectories.
cp -r /usr/data /home/data Copies all files and directories from /usr to /home

top of page


crfs – Adds a new file system

Block size for this command is 512 byte blocks, where the command df, returns disk info in 1024 byte blocks.

crfs -v jfs -g rootvg -m /mydata -p rw -a size=100000

  • -v file systems type, jfs=journalized file system
  • -g volume group name where filesystem will reside, rootvg
  • -m mount point for new filesystem, /mydata
  • -p access permissions, rw=read/write
  • -a file system attribute, size=100000

The above command creates a 50MB journeled file system named /mydata with read/write permissions, created under the volume group rootvg

top of page


del – Delete files where system will prompt you to delete the files

del /u/roger/*

If ‘y’ is entered for yes, all files will be removed.

top of page


df – Displays summary of disk usage for mounted file systems

df -v

top of page


dircmp – Compares two directories and contents of files found in both directories

dircmp /tmp/COMPANY /u/COMPANY | grep different

Displays only those files that are found in both directories but have differences

top of page


du – Display a summary of disk usage for directories

Output in is 512 byte blocks. Without an argument, du lists the current directory.

Examples What it does
du /tmp Displays total number of 512 byte blocks used by /tmp filesystem and all directories underneath it
du -s /tmp Summarizes disk allocation for /tmp filesystem (including ALL files and subdirectories) in 512 byte blocks
du -a /u/roger/doc.txt Summarizes disk allocation for a particular file

top of page


fsck – Checks and interactively repairs inconsistent file systems

File systems are normally checked everytime the system is rebooted. If a file system is cleanly unmounted via the umount command, it’s unlikely to encounter any problems when the fsck command is run on the file system again. Fsck can only be run on a file system that is unmounted (fsck will not make changes to a mounted file-system). If fsck passes without errors, its safe to mount the file system in question.

  • If there’s a discrepancy between the number of directory references to a file and the link count in the file and the file contains data (UNCLAIMED BLOCKS), the file is linked into the subdirectory named lost+found directory.
  • fsck does not flag a bad block on your Physical Volume.
  • Bad blocks are only relocated on a write operation.
  • Fsck performs read operations and therefore is useful for soft errors – not hard errors.
  • Also updates the JFS log – /dev hd8
Examples What it does
1) fsck -fp /dev/hd1 mount /u To make sure the /dev/hd1 (/u file system) is not damaged, followed by mounting that file system for user access.

  • -f (fast check) Won’t check file systems cleanly unmounted.
  • -p Will fix minor problems without prompting user
    whether the problem detected should be fixed or not.
fsck -y /dev/hd1 The -y option gives fsck permission to automatically repair file systems when necessary.
dd count=1 bs=4k skip=31 seek=1 if=/dev/hd4 of=/dev/hd4fsck /dev/hd4 2>&1 | tee /tmp/fsck.errors Use this command in case the superblock is corrupted. This will restore the BACKUP COPY of the superblock to the CURRENT copy.

top of page


fuser – Identifies processes using a file or file system

fuser -u /dev/hd3

Sample output: /dev/hd3: 2964(root) 6615c(root) 8465(casado) 11290(bonner)

top of page


istat – Displays dates of access for a file

istat myfile (Displays attributes about the file named myfile)

top of page


ln – Gives a file more than one name (alias)

The symbolic link (-s) allows a user to point to a file and/or a directory. Symbolic links can link either a file or directory across a file system. Use
unlink to remove a link.

Examples What it does
ln test1 test2 Creates a link from the original file named test1 to a new file named test2
ln -s /tmp ./junk Links subdirectory junk under the current directory to directory /tmp.
1) cd /u/COMPANY2) ln -s /u/roger/* All the files under /u/roger will now have links to /u/COMPANY.

top of page


ls – Displays the contents of a directory

Options What it does
-a Lists all entries including hidden files  that start with a “.”
-d List directories only
-e Indicates if a file has extended security information – 11th character: + means yes, means no
-l Long listing – more detail
-t Sorts by time of last modification (latest listed first)
-F Puts a / (slash) after each filename if the file is a directory. An * (asterisk) after each filename if the file can be executed. An @ for a symbolic link
-R Lists all subdirectories recursively
-b Lists garbage or hidden characters in octal
Examples What it does
ls -ld . List directory attributes for CURRENT directory
ls -ld .. List directory attributes for PARENT directory (one level up)
ls -aeltFR Lists all files and subdirectories under current directory
ls -l Displays the last time the data in a file has been changed.
ls -lc Displays the last time the attributes of a file have been changed.
ls -lu Displays the last time the data in a file has been accessed.

top of page


mkfs – Makes a file system

Example:
cd /u
find . -print|backup -ivqf/dev/rmt0
cd /
umount /u
mkfs dev/hd1
fsck -p /dev/hd1
mount /u
cd /u
restore -xvf/dev/rmt0
The above procedure is one way of making a file system contiguous again. Over the course of time, thousands of additions, deletions, creation, and extensions of files and/or records will create a file system that looks like Swiss cheese. This results in multiple disk accesses that formally may have taken only one. As a result, the system appears sluggish.

top of page


mount – Displays file system attributes or makes file system available for use

Examples What it does
mount Displays attributes about all file systems that are on-line
mount /u/data Mounts the file system named /u/data for accessibility.
mount /usr/tmp /tmp If you don’t have enough room in the /tmp filesystem for a specific utility to work properly, and you do have enough room in the /usr filesystem, then you can mount the space from the /usr filesystem onto /tmp
mount -o wsize-8192, rsize=8192 Set the read/write buffers to 8K to increase performance for NFS file systems. Since NFS verifies each packet that gets written to the server before it requests the next packet from the client, writes will take longer to execute than a read. By increasing the buffer size, less I/O operations will be needed, thereby increasing performance.
mount -n cad -v nfs /transfer Mount a remote file system (type=nfs) on the mount point named /transfer, that resides on node cad

top of page


mv – Renames one or more files

mv report1 report2 (Renames the file named report1 to report2)

top of page


mvdir – Renames a directory

mv /u/roger /u/scott (Renames the directory roger to scott)

top of page


rm – Removes a file or directory

Examples What it does
rm -i * Will prompt the user to remove each of the files in the current directory beforeremoving them EXCEPT for hidden files.
rm -r /u/roger/docs Will recursively remove all files and any subdirectories found under /u/roger/docs.
rm -i S\&e38912 Removes the file named S&38912. Since this file has a special character (‘&’) that the shell treats differently than most.
-i system prompt if you wish to remove.
rm `find . -print` Removes all files from current directory including hidden files (file names such as {}, -exec, ;, etc)
rm ./-junkfile By preceding the filename (-junkfile) with the pathname (./), you are able to hide the ‘-‘ character that starts the filename. If this was not done, the following error message would be generated: usage: rm [-fir] file ...
rm /home/*/mbox Removes all files named mbox found under any of the subdirectories located in /home.

top of page


rmfs – Removes a file system

mfs /u

Removes a file system and the logical volume under it. The file system must be unmounted prior to the ‘rmfs’ command being executed else you will get a ‘BUSY’ error message. The ‘/u’ entry in /etc/filesystems will also be removed.

top of page


sync – Flushes system buffers to disk

There’s a sync daemon (/etc/syncd) that flushes buffers automatically every 60 seconds (default).

top of page


umount – Unmounts a file system from system usage

umount /u

Unmounts a file system so that files found under that file system will not be able to be accessed. The ‘umount’ will fail if one or more users are either currently on that file system or somebody has a file opened on that file system.

top of page


unlink – Used to remove a link or symbolic link

unlink MyDoc (Removes the link MyDoc from the system)

top of page