User Tools

Site Tools


eg-253:unix6

UNIX Tutorial Six

Other useful UNIX commands

quota

If you have a student's login account on a shared Linux system, it is likely that you will have been allocated a certain amount of disk space on the file system for your personal files. If you go over your quota, you are given 7 days to remove excess files.

To check your current quota and how much of it you have used, type <cli>ubuntu@ubuntu:~/unixstuff$ quota -v </cli>

<note>This command is not provided on Live CD version of Ubuntu (or indeed an installed version) since you essentially own the whole system. To install quota type sudo apt-get install quota from the command line. Ubuntu will download the quota package from the internet and install it into the system. The quota command should now be avalable.</note>

df

The df command reports on the space left on the file system. For example, to find out how much space is left on the file system containing your unixstuff directory, type: <cli>ubuntu@ubuntu:~/unixstuff$ df . </cli>

du

The du command outputs the number of kilobyes used by each subdirectory. Useful if you have gone over quota and you want to find out which directory has the most files. In your home-directory, type <cli>ubuntu@ubuntu:~$ du </cli>

gzip

This reduces the size of a file, thus freeing valuable disk space. For example, type <cli>ubuntu@ubuntu:~/unixtut$ ls -l science.txt</cli> and note the size of the file using ls -l. Then to compress science.txt, type <cli>ubuntu@ubuntu:~/unixtut$ gzip science.txt</cli> This will compress the file and place it in a file called science.txt.gz.

To see the change in size, type ls -l again.

To expand the file, use the gunzip command. <cli>ubuntu@ubuntu:~/unixtut$ gunzip science.txt.gz</cli>

zcat

zcat will read gzipped files without needing to uncompress them first.

<cli>ubuntu@ubuntu:~$ zcat science.txt.gz</cli>

If the text scrolls too fast for you, pipe the output though less. <cli>ubuntu@ubuntu:~$ zcat science.txt.gz | less</cli>

file

file classifies the named files according to the type of data they contain, for example ascii (text), pictures, compressed data, etc. To report on all files in your home directory, type

<cli>ubuntu@ubuntu:~$ file * </cli>

diff

This 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 type <cli>ubuntu@ubuntu:~$ diff file1 file2</cli>

Lines beginning with a < denotes file1, while lines beginning with a > denotes file2.

find

This 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 fies 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 <cli>ubuntu@ubuntu:~$ find . -name “*.txt” -print</cli>

To find files over 1Mb in size, and display the result as a long listing, type <cli>ubuntu@ubuntu:~$ find . -size +1M -ls </cli>

history

The bash shell 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.

<cli>ubuntu@ubuntu:~/unixstuff$ history # show command history list</cli>

If you are using the bash shell, you can use the exclamation character (!) to recall commands easily.

<cli>ubuntu@ubuntu:~/unixstuff$ !! # recall last command ubuntu@ubuntu:~/unixstuff$ !-3 # recall third most recent command ubuntu@ubuntu:~/unixstuff$ !5 # recall 5th command in list ubuntu@ubuntu:~/unixstuff$ !grep # recall last command starting with grep</cli>

You can set the size of the history buffer (default is 500) by typing <cli>ubuntu@ubuntu:~/unixstuff$ HISTSIZE=100 </cli>

Summary

Command Meaning
quota display user's file quota
df reports available space on the file system
du show disk space used by file system
gzip/gunzip compress (zip)/uncompress (unizip) a file
sudo task run a task as “super user” (i.e. with administrator privileges)
apt-get install package (download and) install the package package
file file attempt to classify a file according to its contents
zcat file.gz list the contents of a gzipped file without unzipping it
find [options] find files according to a large number of attributes
diff compare two (text) files and print the differences
history show the history of commands entered into the shell

Previous Home Next

Dr Chris P. Jobling 2007/09/21 17:39

eg-253/unix6.txt · Last modified: 2011/01/14 12:45 by 127.0.0.1