LL9 – More SysAdmin Commands & Variables

Hello and congratulations, this is the last lab in preparation for the Virtual Machine Final Projects and if you are here you can definitely handle the final project.  Most importantly the final project is going to give you resources and skills you never would have imagined you could achieve in your 1st semester as a CIS student.

Note as before, you are responsible for all previous Linux coursework and for researching the commands below in more depth using Wikipedia and the built-in Linux man pages.  You will also be taking screen shots, pasting them into your LastnameFirstnameLL9 .pdf file and submitting (uploading) this to BB.


Required Reading

The Linux Command Line by Shotts – 1.1,2.11, 3.14, 3.18, 

Previous material as necessary


Intro ScreenShot

Open or launch your SSH application (e.g. Mac Terminal or Win PuTTy). Please resize your Terminal to make it larger to capture as much as possible but note you may not capture everything and this will be fine. If possible just take a screenshot/picture of your open terminal as if you include other items the text in the Terminal can be very small making it harder for me to see your commands. Paste this screenshot into your correctly named pdf document and label or title this screenshot “Intro Screenshot”.


9.0 sudo apt-get install

Note that a sysadmin will have to install packages over time and this is done with apt-get install but this also requires super-user privileges therefore the sudo. We will not do this yet but please research both apt-get and install.

As examples, you would need to use sudo apt-get install to use the following functionality we used in the previous labs (please do not try this now in the VDI as you do not have sudo privileges).  You will also need to use sudo apt-get install in the final projects.

$ sudo apt-get install vim

$ sudo apt-get install finger

$ sudo apt-get install mailutils

$ sudo apt-get install getmail4

$ sudo apt-get install traceroute

$ sudo apt-get install whois

$ sudo apt-get install talk

$ sudo apt-get install ncompress #used for compress/uncompress but this should be installed in acadnx


9.1 quota

In a production environment, all users are allocated a certain amount of disk space on the file system for their personal files. There are several methods of managing this as you may not be allowed to exceed your quota or if you go over your quota, you may be given a predetermined amount of time to remove excess files. To check your quota on a production system you would enter the following however there are no quotas on acadnx student accounts so this will not reveal anything useful: $ quota -v 


9.2 df

The df command reports on the space left on the file system (free disk space or disk free). Note you can also use df . to find out the space in your current directory.  For example, to find out how much space is left on the fileserver, type

$ df  #df -h is often more readable

Exercise 9.2:  Take a screenshot and paste it into your .pdf file.  

Please clear your screen after taking your screenshot and before continuing.


9.3 du

The du command outputs the number of kilobyes used by each subdirectory.  This is very useful if you or someone has gone over quota and you want to find out which directory has the most files. In your home-directory, type

$ du

Exercise 9.3: Perform a du, pipe it through less, take a screenshot of the first less screenful and paste it into your file labeling it appropriately.

Please clear your screen after taking your screenshot and before continuing.


9.4 compress

compress reduces the size of a file, thus freeing valuable disk space. Navigate to your ciss100/FirstnameLastname subdirectory and perform a long listing to note the size of your files.  Following this compress your lastnamefirstnameLL2.txt file.  I did this for my file as follows:

$ compress loobyjamesLL.txt 

This will compress the file and place it in a file called loobyjamesLL.txt.Z.  To see the change in size, perform another long listing.  Now recall there are 2 types of compression – lossy and lossless and this compression is lossless.  If you do not recall the difference between lossy and lossless compression and when they are used you need to read up on this as it is required. Note you may have to sudo apt-get install ncompress in your upcoming VB Ubuntu instance to perform compression/uncompression.

Exercise 9.4: Take a screenshot at this point and paste it into your file labeling it appropriately.

Please clear your screen after taking your screenshot and before continuing.

9.5 uncompress

To uncompress the file, use the uncompress command as follows and you will need to do this to continue working with this file.

$ uncompress loobyjamesLL.txt.Z


9.6 gzip

gzip also compresses a file using lossless compression, and is more effective than compress. For example, to gzip loobyjamesLL.txt, I entered

$ gzip loobyjamesLL.txt

This will zip the file and place it in a file called loobyjamesLL.txt.gz

Exercise 9.6: Compress your lastnamefirstnameLL.txt file using gzip. Perform another long listing to contrast the compressed file sizes (i.e. compress vs. gzip) take a screenshot and paste it into your .pdf document.

Please clear your screen after taking your screenshot and before continuing.

9.7 gunzip

To unzip the .gz file, use the gunzip command.  Please do this:

$ gunzip lastnamefirstnameLL.txt.gz 


9.8 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 *


9.9 history and !

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

$ history #show command history list

You can use the exclamation character (!) to recall commands easily.

$ !grep #(recall last command starting with grep)

I’m staying in bold font here to draw your attention to the !command (e.g. grep) as this will save you time in the coming weeks! Now I did not use grep in this session so I have no results from !grep

Excercise 9.9: Please take a screenshot, paste it into your document.

Please clear your screen after taking your screenshot and before continuing.


9.10 Linux Variables

Variables are a way of passing information from the shell to programs when you run them. Programs look “in the environment” for particular variables and if they are found, they will use the accessible stored values. Some variables are set by the system, others are set by you, yet others are set by the shell, or by any program that loads another program.

Standard Linux variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE names and shell variables have lower case names.

Each time you login to Linux, the system looks in your home directory for initialisation files. Information in these files is used to set up your working environment. When we open a terminal, our bash shell uses/executes 2 files called .bashrc and .profile. located in your home directory (note that both file names begin with a dot so recall you must use ls -a to see them). Take a look at the contents of these files using the tool of your choice (cat, more, less, etc.).  If you use an editor (e.g. vim) to view the contents of these files – DO NOT CHANGE ANYTHING!!!


9.11 Environment Variables

An example of an environment variable is the OSTYPE variable. The value of this is the current operating system you are using. Type

$ echo $OSTYPE #note you should be looking up echo

More examples of environment variables are as follows so look at some of them using the echo command and don’t forget to preface the environment variable with a dollar sign ($).

USER (your login name)

HOME (the path name of your home directory)

HOST (the name of the computer you are using)

ARCH (the architecture of the computers processor)

DISPLAY (the name of the computer screen to display X windows)

PRINTER (the default printer to send print jobs)

PATH (the directories the shell should search to find a command)

Finding out the current values of these variables.

Environment variables are set using the setenv command, displayed using the printenv or env commands, and unset using the unsetenv command.  To show all values of these variables, type

$ printenv | less

Exercise 9.11: Use your spacebar to move through all the printenv | less environment variables, take a screenshot and paste it into your assignment.

Please clear your screen after taking your screenshot and before continuing.

9.12 Shell Variables

An example of a shell variable is the history variable. The value of this is how many shell commands to save, allowing the user to scroll back through all the commands they have previously entered.  Now lets look at the history variable’s size (i.e. how many commands it will store)

$ echo $HISTSIZE

Now let’s use history to find out something really useful like what “less” commands have we entered using a pipe and grep

$ history | grep less

Now we probably don’t have duplicates however let’s get rid of duplicates from our history display by modifying the varialble

$ export HISTCONTROL=ignoredups #try the history command again to verify

Note: The “ignoredups” setting ignores repeated lines. Typing “ls” twenty times in a row only ends up with one of them in history. However, typing “ls” and then “ps” and then “ls” again will store “ls” and “ps” every time – unless you have bash 3 and set “erasedups“. If that’s set, no duplicates get entered in bash history at all.

More examples of shell variables are

cwd (your current working directory)

home (the path name of your home directory)

path (the directories the shell should search to find a command)

prompt (the text string used to prompt for interactive commands shell your login shell)

shell variables are both set and displayed using the set command. They can be unset by using the unset command. To show all values of these variables, type

$ set | less #use ‘q’ to break out of this process after 1 screen of variables

Exercise 9.12: Take a screenshot, paste this into your document and submit your assignment.

Please clear your screen after taking your screenshot and before continuing.


Let’s learn about auto-completion if you have not already found and observed it. For example, return to your home directory and type cd c and instead of pressing enter, press the TAB key twice.  The shell is smart enough to figure out what matches there could be, and tell you what they are!

This may not seem like much, but think about saving on average 5 keystrokes every time you type something.  It’s VERY helpful!  It works with system commands, too… try typing tou and hit the TAB key once.  What command will it find?  We’ve used it before.


Environment & Shell Variables in closing (advanced and not required)

In general, environment and shell variables that have the same name (apart from the case) are distinct and independent, except for possibly having the same initial values. There are, however, exceptions.

Each time the shell variables home, user and term are changed, the corresponding environment variables HOME, USER and TERM receive the same values. However, altering the environment variables has no effect on the corresponding shell variables.

PATH and path specify directories to search for commands and programs. Both variables always represent the same directory list, and altering either automatically causes the other to be changed.

Linux Lab 9 Commands

Command Description
!recall commands
compresscompresses file (lossless) and assigns .Z extension
dffree disk space
dudisk usage
echodisplay a line of text
exportexport variables
gunzipuncompresses .gz compressed file
gzipcompresses (lossless) better than compress and applies .gz extension
historyshow command history
quotaallocated disk space
uncompressuncompresses files with .Z extension
CLI auto-completion completes commands using tab key

Leave a Reply