8.0 Managing Files and Directories


8.1 Quotas

The quota command displays a listing of your disk storage use and limits. Quotas are used to limit the number of files and the amount of disk space used by each user. Disk use is measured in blocks, where 1 block equals 1024 bytes.

There a two quota limits, the soft limit and the hard limit. You can continue to increase your usage over the soft limit until you either reach the hard limit or the established time limit(usually a week). Once either of these events have occured all further attempts at file creation will fail with an error message. If you ever see the messages:

DISK LIMIT REACHED -- WRITE FAILED

FILE LIMIT REACHED -- CREATE FAILED

you have exceeded your hard limit.

% quota -v
Disk quotas for scot (uid 19072):
Filesystem     usage  quota  limit   timeleft  files  quota  limit  timeleft
/home/huron2
                1668   9000  10000                 0      0      0
%
If this command returns nothing you don't have a quota. The following table explains each column.

The du (disk use) command recursively displays the amount of disk space (in blocks) used in each directory. The -s (summary) will display the total blocks used by each directory and the -a (all) option will list filenames.

% du -s *
654     tutorial
%
This will summarize the disk usage starting from your home directory.

If you exceed your quota limit you can use the tar and compress commands to reduce your disk usage. After you have compressed you files and you still need more disk quota speak with your system administrator.

8.2 Finding file and directories

The find command recursively descends a directory locating all the files that meet the criteria given on the command line. Without any options the find command will take no action on the files it finds, so the -print option is used to write the found files to standard output. The format of the find command is:

find path_name_list [options]

Where path_name_list is one or more directories.

% find . -name Makefile -print
/home/huron2/admin/scot/tutorial/Makefile
%
The . is a directory abbreviation for the current directory. The -name option specifies that only files with the given name should be found. The name option can include wildcard characters if they are quoted. There are many options to the find command, a few are listed in Table8.2.
% find . -name "core*" -size +3 -mtime +7 -exec rm -i {} \; -print 
/home/huron2/admin/scot/core: ? (y/n) y
/home/huron2/admin/scot/core
%
Table8.2:  Some Options to Find
--------------------------------------------------------------------
-name file	Find files named file

-size n	        Find files that contain size...
              	   n  exactly n blocks (1 block = 512 bytes)
	          +n  more than n blocks
	          -n  less than n blocks

-mtime n        Find files that were modified
              	   n  exactly n days ago
	          +n  more than n days ago
	          -n  less than n days ago

-exec cmd	Execute command cmd on each file

-type type	Find files that match the type
		   f  ordinary file
		   d  directory
		   b  block device
		   c  character device
		   p  named pipe
--------------------------------------------------------------------
Actions can be taken when files are found by using the -exec option. The -exec option uses the {} (left curly-brace right curly-brace) syntax to specify the current file that find has found. The exec command ends with the \; syntax. If we did not have the print option at the end we would not get a confirmation the file had been removed. had been removed.

8.3 File Archiving

The tar (tape archive) is used to either archive files to tape or to a disk. In these examples we will only be archiving to disk. Lets archive the tutorial files.
% tar -cvf tut.tar tutorial
a tutorial/Makefile 1 blocks
a tutorial/friends 1 blocks
a tutorial/hello.cc 1 blocks
a tutorial/postscript/mosaic.ps 638 blocks
a tutorial/core symbolic link to /dev/null
a tutorial/friends.pl 2 blocks
% ls tut.tar
tut.tar
%
Here we have created tut.tar as an archive of the files in our tutorial directory. The -c (create) option is used to create a new tape archive and write files. The -v (verbose) option display the names of archived files. The -f (file) option specifies that the next argument is the archive source or destination. If you exclude the -f option tar will use the default(usally /dev/rmt/0m). Let extract the tutorial files.
% tar -xvf tut.tar
x tutorial/Makefile, 242 bytes, 1 tape blocks
x tutorial/friends, 416 bytes, 1 tape blocks
x tutorial/hello.cc, 70 bytes, 1 tape blocks
x tutorial/postscript/mosaic.ps, 326291 bytes, 638 tape blocks
x tutorial/core symbolic link to /dev/null
x tutorial/friends.pl, 864 bytes, 2 tape blocks
%
The -x(extract) option will extract the files from the tape archive. Since we have the tut.tar file we can remove our tutorial directory. Before we extracted the contents of a tar file we could have use the -t (table) option to get a listing of the table of contents.

8.4 Compressing Files and Directories

The compress command is used to reduce the size of a file. Compressions often save as much as 30-80 percent of the original space, however you must uncompress files before they can be used. If file compression is possible the suffix .Z will be added to the end of the file to indicate it it is compresses.
% compress -v tut.tar
tut.tar: Compression: 78.19% -- replaced with tut.tar.Z
% ls -l tut.tar.Z
-rw-r--r--   1 scot     admin      79883 Mar 30 16:02 tut.tar.Z
%
The -v (verbose) option is used to list the amount of compression.

The uncompress command has the same syntax as compress.

% uncompress tut.tar.Z
% ls -l tut.tar
% ls -l tut.tar
-rw-r--r--   1 scot     admin     337920 Mar 30 16:02 tut.tar
%
Recently some sites have been using a new compression program. The GNU zip and unzip programs are being used because they offer a more effective compression algorithm. The gzip (GNU zip) command will compress a file and the gunzip (GNU unzip) will decompress a file.

% gzip -v tut.tar
tut.tar:                 82.4% -- replaced with tut.tar.gz
%
Here we see a compression of 82% using gzip, whereas the compress program gave us 78%.

Last Modified: 4/4/94 by Scott Miller