Please review previous LLs as necessary for both content and if necessary the screenshot and submission instructions in LL2.
The Linux Command Line by Shotts – 1.2, 1.3, 1.4, 1.8
1.2 => Navigation, 1.3 => Exploring the System, 1.4 => Manipulationg Files & Directories, 1.8 => Advanced Keyboard Tricks
This can also be downloaded from the Syllabus link. I recommend you try each command but note that some commands like revealing virtual terminal sessions are not supported for general users (students) on an enterprise system (AcadNX) because security is a primary concern.
Note each week’s reading may also cover components for future Linux Labs so you may need reread chapters each week as necessary.
Again, you must do the required reading and note you will likely have to read this material several times as it will continue to make more sense with each reading. If you just follow these labs without doing the reading, it is likely you will successfully progress to a point (even very far along) and then at some point in a future Linux Lab, something will go wrong and you will be absolutely lost because you will not have the knowledge to understand what is going on.
This happens every semester and I will quickly identify whether the reading has been done. If this occurs my instructions will likely be to return to the beginning to read the material and redo the labs to put the proper file and directory structure in place. Please do not skimp on this necessary preparation as the labs will go very quickly if you perform the proper preparation/reading.
Now if you encounter difficulties, it is unfortunate but welcome to IT as in IT we learn from our and our system’s mistakes. If everything just worked out of the box, we (CS/IT professionals) would be less necessary. So should something go wrong please reread the material or even Google the error message.
Important – if something goes wrong in the labs (i.e. commands don’t work), research the command and check your spelling and spaces (Linux is case sensitive and it is easy to miss spaces reading Linux commands and arguments). With this basis, please read the materials with a high attention to detail. If you use a search engine (e.g. Google) to research these commands, please research from an Ubuntu perspective (e.g. Google “Ubuntu Linux pwd” ) as there may be minor variations across Linux distributions with the more advanced commands (99.9% of the commands used in these labs will be generic and therefore the same across distributions).
Getting help: Please see the bottom of this presentation for instructions on getting help from me using Jing to record your session/problem.
Linux CLI Introduction
Since this is the first Command Line Interface (CLI) lab I will provide some additional background to supplement the reading and provide clarity.
First, note you will also see or hear the CLI correctly referenced as the “Terminal”, “Shell” or Command Line Interpreter.
I may also use the terms Linux and Ubuntu interchangeably as Ubuntu is a Linux variant or distribution.
Please understand the distinction between a command, option and argument noting options and arguments are also referenced in the text as parameters (i.e. they vary according to context/need). This understanding is absolutely necessary for both your reading comprehension but also to communicate to me and your classmates. Linux has predefined commands and options. A command invokes or executes a program (e.g. ls, pwd, etc.). Commands may have predefined options to further define the functionality of the command and options are prefaced by a hyphen or minus sign to communicate this to the OS (e.g. in the command “ls -l”, the “-l” option directs the ls command to display a long listing). Arguments are user supplied and will contain items not pre-identified by Linux. As an example, below I will ask you to create directories with your name and of course Linux had no way to know you would be creating a directory with your name.
Files and Processes Introduction (very basic introduction)
Everything in Linux is either a process or a file.
A process is an executing program identified by a unique PID (process identifier) and we will cover this later.
A file is a collection of data and includes both files and directories however, note that Linux also treats other things (actually everything else such as input/output (I/O) devices) as files. This greatly simplifies the programming interface as we (and processes) interact with files, directories and devices in the same manner (i.e. writing to a file is the same as writing/outputting to a printer, the screen or even the network). Note Linux has a type command that will reveal a file’s type so while not required in this lab, please try the type command.
Basic text files are created by users using text editors or by running compilers that create executable files but also generate “artifact” text files. Examples of text files include; a document (report, essay etc.) or the text (source code) of a program written in some high-level programming language. Executable files contain binary instructions comprehensible directly to the machine or scripts comprehensible to the OS. Directories contain information about their contents, which may be a mixture of other directories (sub-directories) and ordinary files.
Directories (folders in the PC world)
All files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root and is denoted by the backslash (i.e. /). Note that the term “root” is also used to denote the “system administrator or super user (su)”.
In the diagram below, we see that the root directory contains 6 subdirectories (bin, dev, home, etc, lib and usr) and the home directory contains the subdirectories bio1, bio2 and bio3. Note that names within a directory (namespace) must be unique so there is only one etc in the root directory but there are etc directories in both the usr and local directories as these are different namespaces. To disambiguate/differentiate files and directories we often have to provide the file or directory’s full path name where different levels are separated by backslashes. Disambiguate means to uniquely identify files/directories in the namespace where the namespace is all defined names. For our directory tree below we see the three etc directories can be uniquely referenced as /etc, /usr/etc and /usr/local/etc.
General Linux Lab Instructions
To complete each lab you will have to open up a Terminal as you did in LL2 and connect to the HVCC Ubuntu Acadnx server. You will 1st take an Introductory Screenshot to demonstrate your connection to the Acadnx server and capture the time and system state.
Taking a Screenshot and Submitting your Assignment
As in LL2, for this (and future) assignment(s), you will take periodic screenshots as directed and paste the screenshots into a single LastnameFirstnameLL3 document 1 screenshot per page (in future labs you replace the x with the correct LL number… e.g. 4 for LL4, 5 for LL5, etc.). You should preface each screenshot with the exercise number as listed in the tutorials so that I know what step the screenshot documents and again, 1 screenshot per page please. When complete, please save the file in .pdf format and upload this file as directed in the corresponding BB Lecture Module (LMx). Note I will not accept assignments that do not adhere to this single pdf file format with proper screenshot headings 1 per page. (For this lab an example of my file would be LoobyJamesLL3.pdf).
Again, please resize/expand/enlarge your Terminal window but note that while the screenshot may not capture every command you have entered, it will demonstrate your present state and that is all that is necessary. Please note these instructions will be standard for the rest of the course.
1. 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”.
Linux Lab Typographical Conventions
These tutorials will use the following typographical conventions (and you should return to read these conventions as necessary).
Characters written in bold font are Linux commands and options to be typed into the computer as they stand.
Characters written in italic font indicate non-specific file or directory names where you will have to submit components or elements specific to you (i.e. arguments). As an example, in a future lab you will create a directory with your name however I cannot specify instructions for everyone’s name so I will write FirstnameLastname. You will replace FirstnameLastname with your name using the same uppercase/lowercase formatting (recall from the reading that Linux is case sensitive). As an example; if I was to do this, I would create a directory titled JamesLooby.
Words inserted within square brackets like
[Ctrl] or [Enter] indicate keys to be pressed although square brackets can also denote command options as presented in the reading.
Beware of spaces between commands, options and arguments and this of course means you absolutely must know the difference between Linux Commands that the OS understands, Options that go along with specific Commands and Arguments that the user provides.
To begin please connect to the HVCC AcadNX Ubuntu environment as you did in LL2.
3.0 Basic Linux CLI Syntax (please research and understand syntax vs semantics).
The $ (dollar sign) will be used as the CLI prompt consistent with our Ubuntu bash instances (Now did you understand everything in that sentence — if not please research what seemed foreign as you may possibly want to Google and research linux bash or Ubuntu bash).
I will repeat this as students continually misinterpret this. In my examples, I will provide a $ prompt but you should not type the $, only type the commands, options and arguments following the $ prompt. Invariably I will get questions from students that include the $ prompt in their commands and get a “command not found” error. Please do not take offense if my response to the question is “please reread the instructions” as we all must learn to read discriminately for our professional futures.
Note, if your prompt ends in a ‘#’ instead of a ‘$’ you are logged in as a superuser or SU or admin but this is not possible for you in the HVCC AcadNX environment. This will be possible in your Virtual Machines in LL10 and beyond.
First, let’s type in something that is invalid in Linux so that we can see an error message. At the command prompt (email@example.com:~$) type in some gibberish and you may choose anything (I will simply provide the $ but you should not type this although that would be gibberish as well)
Linux will respond, command not found because it is is not one of Linux’s registered commands. Note you will see variations of this in the future if you mistype commands, options or arguments again noting that Linux is case sensitive.
Now let’s try a valid command from the Shotts’ text so please type the following again noting the $ sign is the prompt and we are not retyping the $
I recommend you try all commands in the Shotts text as you read about them.
Linux Lab Typographical Conventions & CLI Syntax Example:
To provide a complete example of our typographical conventions consider the following complete example:
I may ask you to enter the following.
$ ls anydirectory # extra info [Enter]
This means – after the Linux prompt dollar sign prompt ($), type the ls command followed by an argument which in this case is the name of some directory. In this case you will be supplying the name of the anydirectory which at this point does not exist. To continue the example, I could write ls jameslooby where you will be replacing jameslooby with your name. Now if you entered this you received an error as you have not created a directory called “anydirectory” or “jameslooby”.
The # (pound sign or hash tag) indicates a Linux Comment where everything following the # on a line is ignored by the CLI. I will use the comment field to present extra descriptive information as necessary. Note it is not necessary for you to type this comment on the command line beyond the 1st instance to see that it is a comment and ignored by the command line interpreter. As a bit of history, the English Pound Sign £ is not represented on our keyboards so they simply chose the # sign to use in its place.
Lastly, please don’t forget to press the [Enter] key as commands are not sent to the computer until this is done (which of course makes the command execute). Now note I will assume you know to press the [Enter] key to enter the command so I will largely omit this.
Example for you to try: to demonstrate that this works please enter the following at the terminal prompt:
$ ls -al # gobbly gook
Note that you will have additional information tailored to you before the $ prompt that will include your name and your present working directory or path. If you received an error you did not type the command and command line options in correctly and this should serve as a lesson. You should know from the reading that ls is the command and -al are options for the ls command. The -a changes the ls output to be a complete listing (with hidden files that begin with a “.”) and the -l changes the ls output to a long listing.
Note there is a space after ls command and -al option. The space after the # is irrelevant as it is a comment. Also note filenames and their extensions cannot contain spaces in contrast to Windows.
Now type the following and compare the command output to illustrate that the # and what follows it is used to denote a single line comment and has no impact on the command’s output.
$ ls -al #comment is ignored and has no bearing on execution
As you know from your reading, Linux is case-sensitive, so LS is not the same as ls. If you were to type LS you would get an error message since there is not LS command in the shell (the shell is the Operating System program that recognizes these commands). The same applies to filenames, so myfile.txt, MyFile.txt and MYFILE.TXT are three separate files. Beware if copying files to a PC, since DOS and Windows do not make this distinction but many programming languages do. Now to illustrate an incorrect or missing command and ensure that everyone recognizes an error please enter the following.
$ls – al #incorrect space after the –
Ok so we’re learning that we must be very precise with out work as Linux will only accept commands and options it knows and they must be in the precise format. Should you receive an error message the 1st step is to reread and research the command in question.
Note, having introduced the above typographical conventions, please note that I am working alone without an editorial team that creates textbooks so I will surely have omissions or errors. Now to this extent, please let me know if something is not clear as I will clarify it and we will realize Continuous Improvement consistent with contemporary best practices user-centered iterative IS design.
3.1 Listing files and directories
First, as presented in the text and in class, everything appears to be a file to Unix/Linux so the title of this lab is actually redundant (i.e. a directory is a file) and this will be explored further throughout these labs.
ls (list) – Directory Listing
When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name. For me this would be j.looby in the HVCC Ubuntu environment and you would see this in your prompt (form me this is j.looby@acadnx:~$). This home directory is where your personal files and subdirectories are saved.
To find out what is in your home directory, type ls
$ ls # ls is short for list
To reinforce my conventions above, you should only type ls as the $ prompt is already present and anything following the # is treated as a comment but you know this from your reading.
The ls command lists the contents of your current working directory. Since you have not created any files or directories yet, the files and directories you see(maybe none) are inserted by default by the System or in a production environment, the System Administrator when your account was created.
Note ls does not cause all the files in your home directory to be listed, but only those ones whose name do not begin with a dot (.). Files beginning with a dot (.) are known as hidden files and usually contain important configuration information. They are hidden because you should not change them unless you are very familiar with Linux!
To list all files in your home directory including those whose names begin with a dot, type:
$ ls -a # -a is “all” option, also referred to as a complete listing
ls is an example of a command which can take options and arguments
-a is an example of a command line option. The options are system defined and defined and associated with commands and change the behavior of the command. Now to reinforce this in another author’s voice, please read the following as it will give us the correct terminology (e.g. command, options and arguments) and note it will open in a new window so that you retain you place in this tutorial: Linux Command Structure.
There are Linux manual pages that tell you which options a particular command can take, and how each option modifies the behavior of the command. We will use the manual pages in the terminal later but you can type man followed by the command in your Terminal.
Now let’s learn a little more so let’s look at a long listing using the ls long listing options argument:
$ ls -l # -l option is long listing
Now let’s put two option arguments together:
$ ls -la #this is a complete long listing and could be entered as $ ls -l -a
First, please make your Terminal window larger by resizing the window if you have not already done so so that we capture as much as possible (drag lower right corner with your mouse). Again note you may not capture everything in future labs but this will be alright. Take a screenshot and paste it into your submission file with the exercise number heading.
That was a nice gentle introduction but ls is an important and powerful command and many people use it after almost every command to verify what took place so let’s look at all of its capabilities.
I do not expect that you will understand all of this material but it is important to read it so that you can return to reference it as necessary so as previously introduced please read this: http://en.wikipedia.org/wiki/Ls (and don’t be misled by the URL’s capitalized Ls). For subsequent commands you will need to search Wikipedia on your own.
Now having read Wikipedia’s information, let’s introduce the Linux man command and the description and options for the ls command so please enter:
$ man ls
You are now seeing the manual presentation of ls and you may use the spacebar to show the subsequent screens and ‘q‘ to quit (i.e. enter q without the apostrophes). Now reviewing the commands above, we can see that ls is a command and as a command it has a manual page whereas the -a, -l and -la were options listed in the manual page.
3.2 Making Directories
First let’s clear the screen so that it is less confusing so please enter the clear command. Again, I provide the $ prompt but you know you should not be typing this.
Now in the future I will ask you to clear the screen but I will not provide the syntax again (which of course is just the clear command).
mkdir (make directory)
We will now make a subdirectory in your home directory to hold the files you will be creating and using throughout the course of this and subsequent tutorials. To make a subdirectory called ciss100 in your current working directory type the command mkdir and the argument ciss100. Please understand the difference between options and arguments where options are system (Linux) defined and arguments are user defined and supplied.
$ mkdir ciss100 #lowercase ciss100
To see the directory you have just created, type
Now everytime you create a directory or file you should perform an ls to verify it was created correctly and to check your spelling and recall Linux is case sensitive. Note if you perform a mkdir ciss100 again in the same directory Linux will tell you the directory already exists and this applies to files as well.
You now have the following directory structure graphically where ciss100 is a subdirectory of your home directory in this case denoted by the ~/
You can and possibly should read about this and all future commands on Wikipedia as they are presented well and I am trying to move this course to open (free) content. Now note in the command “mkdir ciss100”, mkdir is the command but ciss100 is an argument where arguments are specified by the user (options are system defined or predefined). You could have made a directory using many other names of your choosing and of course “ciss100” will not be found in the mkdir manual page. You may wish to view the manual page to verify this and complete your understanding of commands and their options and user generated arguments.
To list all files in the ciss100 subdirectory from your home directory (i.e. ~/) enter,
$ ls ciss100
Now while still in your home directory, please make another directory titled: “CISS100” (uppercase CISS100) and perform a ls to see that “ciss100” and “CISS100” are different directories. Could you have done this in Windows (i.e. make a ciss100 and CISS100 directory in the same directory)? Why not… because Linux is case sensitive and Windows is not case sensitive so Linux has a much larger namespace (i.e. possible names).
Now your directory structure with 2 subdirectories graphically is:
Exercise 3.2 – mkdir screenshot
Take a screenshot and paste it into your submission file (on a new page) with the exercise number heading
Please clear your screen after taking your screenshot and before continuing.
3.3 Changing to a different directory
cd (change directory)
The command cd directory means change the current working directory to ‘directory‘. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree. One last time, my format cd directory indicates cd is a command and directory is a user supplied argument.
To change to the directory you have just made, type
$ cd ciss100
Now look at your prompt and see how it has changed as it will show you where you are in the directory system or in other words, the path of your present working directory. Now type l
s to see the directory contents of your present working directory (ciss100). This should be empty and of course you do not see the ciss100 directory listed as you saw when performing the ls from the parent directory. Note you can view the contents of the parent directory with a ls ~/
Exercise 3.3 – subdirectory name
Make another directory inside the ciss100 directory named after your first and last name in CamelCase notation (i.e. no spaces between your first and last name). For me, my directory would be JamesLooby (also research CamelCase notation as necessary and note from this point on you are responsible for researching any term or command you do not understand). Perform a directory listing to ensure you created it correctly. My directory structure is now the following where my home directory (~/) has subdirectories ciss100 and CISS100 and the ciss100 directory has a JamesLooby subdirectory. Your structure will of course have a subdirectory with your name in Camel Case notation.
Screenshot – take a screenshot and paste the screenshot into your submission file on a new page and do not forget the screenshot heading
Please clear your screen after taking your screenshot and before continuing.
3.4 The directories . and ..
Still in the ciss100 directory (you can see this from your prompt’s path – path precedes the $), type
$ ls -a
As you can see, in the ciss100 directory (and in all other directories), there are two special directories called . and ..
In Linux, . means the current directory, so typing a . means stay where you are (the ciss100 directory).
$ ls .. # this should look familiar as it shows the directory above
Now enter the following:
$ cd . # NOTE: recall there must be a space between the command and option
Did your prompt change? Perform another listing to verify nothing changes and while this may not seem very useful at first, but using . as the name of the current directory will save a lot of typing, as we shall see later in the tutorial.
In Linux, .. means the parent of the current directory. This will take you one directory up the hierarchy (back to your home directory). Try it now.
$ cd .. # Again note there is a space between cd and the two dots
To see where you are, look at your prompt which contains your present directory path and perform another directory listing as you did above.
Now you could cd .. back to your home directory however typing cd with no argument returns you to your home directory so lets try this by entering the following commands from the top level directory to your FirstnameLastname directory (for me this is ciss100/JamesLooby)
$ cd ciss100
$ cd JamesLooby # again use your FirstnameLastname directory name
$ cd # This returns to the home directory and is very useful lost in the file system
Now let’s change to the FirstnameLastname subdirectory from your home directory directly and then change directories back to our home directory directly. To do this I would change directories to my home directory if necessary and then enter:
$ cd ciss100/JamesLooby
$ cd #of course this returns us to our home directory
Please take a screenshot and paste the screenshot into your document with the appropriate heading on a fresh page.
Please clear your screen after taking your screenshot and before continuing.
pwd (print working directory)
Pathnames enable you to determine where you are in relation to the whole file-system. For example, to find out the absolute pathname of your home-directory, (type
cd to get back to your home-directory if necessary) and then type
The full pathname should look something like this:
3.6 More about home directories & pathnames
First, type cd to get back to your home-directory if necessary, then type the following to list the contents of your ciss100 directory.
$ ls ciss100
$ ls FirstnameLastname # for me this would be ls JamesLooby
You will get a message like this – UserName: No such file or directory
The reason is, UserName is not in your current working directory so its not visible at your present level as you can only see what’s in your present directory (e.g. return to the Linux tree structure file representation to see this). We did this for a reason as the system is deterministic and as you work through the labs you will encounter errors but the errors are not in the system as they will be your/our doing. Please do not just blindly attempt other commands as we must learn to use the system so if something happens that you cannot explain, return to the reading to establish a proper understanding and foundation.
To use a command on a file (or directory) not in the current working directory (the directory you are currently in), you must either cd to the correct directory, or specify its full pathname in the command. To list the contents of your UserName directory from your home directory, you must type the following from your top level user directory.
$ ls ciss100/UserName # for me this is ciss100/JamesLooby
~ (your home directory)
Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing
$ ls ~/ciss100
will list the contents of your ciss100 directory, no matter where you currently are in the file system.
What do you think the following would list:
$ ls ~ #try it if you don’t know
What do you think this would list:
$ ls ~/.. #try this noting I could also enter “cd ..” and then ls
Well think about this… the ‘~’ means the home directory and “/..” means go up one level so that “~/..” so this is the “/home” directory where all user accounts are located. Enter a “cd ..” to go up one level and perform another listing. Perform another “cd ..” and then a perform a listing and you will see that you are at root which was covered in the first reading as well as in class.
3.7 Removing files and directories and touch
Please research the rm and rmdir commands used to remove files and directories. Then please read about the touch command here: http://www.linfo.org/touch.html
Navigate to your home directory if necessary and create a file with your initials using touch (form me this would be jgl).
$ touch jgl #please substitute your initials for mine
Now make sure it is there by performing a listing (i.e. ls) and notice the different color.
Now remove this initial file name as follows:
$ rm jgl #you should verify it is gone with a ls
Please take a screenshot and paste this into your submission file with the proper exercise heading.
Please clear your screen after taking your screenshot and before continuing.
Please navigate (change directories) to your home directory and remove the directory with your uppercase CISS100 (please do not use rm -r as this can be dangerous). Please perform a directory listing to show that CISS100 subdirectory is gone and then take a screenshot and paste this into your submission file with the proper exercise heading.
Use the commands ls, pwd and cd to explore the file system as you see fit knowing this will pay big dividends in the future. You perform a ls to get directory names in your working directory and then you can use cd .. to move up levels in the directory tree and then perform a ls to get directory names and then traverse down these directories using ls DirectoryName (of course replacing DirectoryName with an actual existing directory name visible in your present working directory but your reading should have allowed you to deduce that).
BTW – while I am operating in my user directory structure, I can also go up into the system directory structure. As an example if I go up several levels (i.e. cd .. followed by cd ..), using a ls I’ll see system directories titled “bin”, “boot”, “cdrom”, etc. and I can then enter cd bin. Try listing the contents of the ciss100/Username directory from the top level (I would enter $ ls ciss100/JamesLooby) and following this navigate to the ciss100/Username directory and perform a listing on the home directory using the tilde.
Please submit the single .pdf file with your pasted screenshots titled with the exercise number in the Blackboard (BB) Lecture Module 3 (LM3) Linux Lab3 (LL3) Assignment Folder (i.e. browse and upload from your computer). I also recommend you save a copy in your personal Windows/Mac/Linux system.
Again, you must research the commands (and the options) used in the labs on Wikipedia and I also recommend you view them in the manual (man) pages so that you can become adept with the man page nomenclature and conventions. As an example, to view the man page for ls please type the following in the terminal $ man ls (of course the $ prompt is provided and will not be retyped). The man page will show you all the available options and again, arguments are user specified and will not be listed in the man pages.
Below are the commands used in this lab so please be sure you understand them. Also please be sure you know the difference between a command, option and argument and relative and absolute paths.
Lastly, please use the ls command frequently. I often type ls after every cd, cp, mv, mkdir command to verify what took place. Below the table is a video that may help as well.
Linux Lab 3 Commands
|cd ..||change directory to the parent directory (i.e. go up one level)|
|cd or cd ~||change to home directory|
|ls||list files and directories|
|ls -a||list all files and directories - note -a is an option|
|ls -l||list complete information for files and directories|
|mkdir||make a directory|
|pwd||display the path of the current directory|
|rm||remove a file|
|rmdir||remove a directory|
|ln -s||create a symbolic link|
|touch||create an empty file|
|clear||clears the CLI|
Getting Help From Me
The best way to convey your environment and get help is to use Jing (instructions below) but in the absence of this I need screenshots of long listings for all relevant directories.
In a nutshell Jing will allow you to highlight and record your problem on your screen and explain your problem via screenshots and audio. Please include a listing (ls) (or long and complete listing if appropriate) for every directory you are in during your Jing recording and please speak during the Jing recording telling me what you are doing and why. Here are Prof Doane’s Jing installation and usage instructions:
LL3 Help Recording
Please note the following are some examples but it is not me reproducing LL3 so please do not submit any of the recorded examples.