Linux Tutorial #7 quota On many computer systems, the system administrator has to restrict the amount of disk space users are allowed to use in order to avoid running out of space on the shared file system. The quota command can be used to find out what your quota is on a particular machine. To check your current quota and how much of it you have used, type % quota v This will show you how many GB of files you can store in your account. If you have a quota of none this means that you can use all the space you need (within reason). The system administrator will establish a policy for what happens if you exceed your quota. For example, you may have 7 days to delete files to get under quota. df (disk free) The df command reports on the amount of space free on the file system. On many systems, there are several disks mounted, and you can find out which disk is nearly full, which is nearly empty, and decide where to put your large files accordingly. For example, to find out how much space is free on the fileserver, type % df du (disk usage) The du command outputs the number of byes used by each subdirectory. This is useful if you have gone over quota and you want to find out which directory has the most files. In your home- directory, type % du This will tell you about the sizes of all of your directories, and their subdirectories. If this is too much information, you can get a quick summary by typing % du - s - h *
The - s flag will display only a summary without listing sizes of subdirectories, the - h flag will report total size in K, M, or G instead of bytes, and the * means all files and directories. gzip There are many ways to compress files so they take less disk space. The gzip command is a popular choice on Linux systems. For example, go to your Linuxstuff directory and type % ls - l science.txt and you should see the following, which tells us the file is 7767 bytes long - rw- r- - r- - 1 csce_user csce_user 7767 Jan 4 12:47 science.txt Then to compress science.txt, type % gzip science.txt % ls - l and you will see that the compressed file science.txt.gz is only 3714 bytes long. - rw- r- - r- - 1 csce_user csce_user 3714 Jan 4 12:47 science.txt.gz In general, gzip will reduce the size of a file by 50%, but in some cases you might get 90% reduction or 10% reduction depending on the file contents. gunzip To expand a gzip compressed file, we must use the gunzip command. This will restore the file to its original size without any loss of information. To see this, type % gunzip science.txt.gz % ls - l You should see science.txt has its original size and original time stamp. zcat The zcat command is a useful utility that will read gzipped files without needing to uncompress them using gunzip first. For example, type % zcat science.txt.gz
If the text scrolls too fast for you, pipe the output though less. file % zcat science.txt.gz less The Linux file command classifies the named files according to the type of data they contain, for example ascii (text), pictures, compressed data, etc. To find out about all of the files in your Linuxstuff directory, type % file * If you have science.txt in your directory, you will see something like science.txt: ASCII text If you have science.txt.gz in your directory, you will see something like science.txt.gz: gzip compressed data diff The diff command compares the contents of two files and displays the differences. Suppose you have a file called file1 and you edit some part of it and save it as file2. To see the differences between these two files type % diff file1 file2 Lines that are identical in both files will be ignored, and each line that is different in file1 compared to file2 will be displayed. Lines that begin with a < character are part of file1, and lines that begin with a > character are part of file2. For example, if you had the phrase hello mom in file1 and you changed this to hello dad in file2, you would see something like 3c3 < hello mom, please send money - - - > hello dad, please send money If there are a lot of changes in a file, you may find that a side- by- side display of differences will be easier to read. To do this, you can type % diff - y file1 file2 less
find The find command searches through the directories for files and directories with a given name, date, size, or any other attribute you care to specify. It is a simple command but with many options. You can read the manual by typing man find. To search for all files with the extention.txt, starting at the current directory (.) and working through all sub- directories, then printing the name of the file to the screen, type % find. - name "*.txt" - print To find files over 1MB in size, and display the result as a long listing, type % find. - size +1M - ls To simply count how many files there are in a directory and all of its subdirectories, you can type % find. wc - l history The Linux operating system keeps an ordered list of all the commands that you have entered. Each command is given a number according to the order it was entered. The history command will show you this list of commands. For example, type % history You should see a list of all of the commands that you have used during this tutorial. This can be helpful in case you have forgotten exactly what command you entered earlier. If you are using the bash shell, you can use the exclamation character (!) to recall commands easily. What you put after the! determine what command is executed again. For example, %!! (recall last command) %!- 3 (recall third most recent command) %!5 (recall 5th command in list) %!grep (recall last command starting with grep)
Summary Command quota df du gzip gunzip zcat file diff find history Meaning check your current disk quota and usage report on how much disk space is free report on how much disk space is being used compress an input file to save disk space uncompress an input file to restore original file read compressed file without uncompressing report on the type of data stored in a file display the differences between two files search directory for files based on name or properties print a list of all commands that have been run Author: M.Stonebank@surrey.ac.uk, 9th October 2000 Edited: jgauch@uark.edu, January 2015