Linux Tutorial Six

Other useful Linux commands  

quota

All students are allocated a certain amount of disk space on the file system for their personal files, usually about 1Gb. If you go over your quota, you are usually given a few days to remove excess files.

To check your current quota and how much of it you have used, type

% quota -vs

yppasswd

To change your password, type

% yppasswd

and follow instructions on the screen.

It may take up to 15 minutes for the change of password to take effect.

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 fileserver, type

% df -h .

du

The du command outputs the amount of space 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

% du -hs *

The -s flag will display only a summary (total size) and the * means all files and directories.

gzip

This reduces the size of a file, thus freeing valuable disk space. For example, type

% ls -l science.txt

and note the size of the file using ls -l . Then to compress science.txt, type

% gzip science.txt

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.

% gunzip science.txt.gz

zcat

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

% zcat science.txt.gz

If the text scrolls too fast for you, pipe the output though less .

% zcat science.txt.gz | less

tar

tar command backs up entire directories and files into a single file known as an archive, which tar compresses with gzip if -z flag is used. To make a compressed archive, type

% cd
% tar -czvf unixstuff.tgz unixstuff

Type ls to see if it has worked.

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

% file *

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

% diff file1 file2

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

% find . -name "*.txt" -print

To find files over 1Mb in size, and display the result as a long listing, type

% find . -size +1M -ls

ssh (secure shell)

This command allows you to connect to remote machines. To connect to the Physics Network from off or on campus, type

% ssh username@faraday.mines.edu

where username is your username on the Physics Network. To log out from faraday.mines.edu, type

% exit

Exercise 6a

Login into your neighbor's computer via ssh.

Hint: You will need to find the name of your neighbor's computer.

scp (secure copy)

This command allows you to transfer files/directories between computers. It works just like the Linux cp command except that the arguments can specify a user and machine as well as files/directories. To copy your unixstuff directory into /tmp directory located on faraday.mines.edu and call the copy of your unixstuff directory usernameStuff, type

% cd
% scp -r unixstuff username@faraday.mines.edu:/tmp/usernameStuff

where username is your username.

Exercise 6b

Copy your science.txt file to your neighbor's computer directory /tmp.

Hint: The flag -r is not necessary because we are copying a file and not a directory.

Alex Yuffa © 04/26/2008