Revision 1 as of 2006-08-22 09:59:50

Clear message

first off lets open a terminal in gnome click on application -> accessories -> terminal (kmenu -> system -> konsole for kde)

To switch between the terminal and your IRC client using only the keyboard you can use "alt and tab" to cycle through the active windows.

I want to introduce the concept of a shell BR you have in front of you in the default black writing on a white background on the left there is something that looks like this


this is your username at your machine and it currently indicates you are in your home directory BR if you type at that  command set | grep SHELL  you will see that the first line returned is  SHELL=/bin/bash  that indicates what "shell" your "environment" is set to use BR this is the program that you use to converse with the kernel BR this program provides a programming environment (usually in the form of scripts) to allow a user to interact with the machine and manipulate it BR there are two ways it does this: BR it invokes command within itself BR or it can invoke commands external to itself BR

the ones within are referred to as "buildins" BR so the first command I want you to in there now is pwd BR this command tells you where you are BR pwd is hard to remember but it actually stands for print working directory BR now you may see from time to time things such as  ls -al  the part after the ls is called an argument BR pwd accepts two arguments BR the first is --help - which displays help for the program and BR the other is --version - which displays the version number BR after both of these functions have completed (and providing they complete correctly) the program exists BR please run the following

pwd --help

[PWD has a bug --help doesn't work, we move on to another command]

to demonstrate an argument let us use the command which invokes manuals BR this is the "man command" BR please type  man --help in your terminals now

you will notice that a lot of data is on the screen and the scroll bar on the right should indicate that some data has passed by however we do not always have the luxury of a scroll bar so now we will have a quick look at how to see more data

so to see the data one screen at a time you can do this:

man --help | more

the function of that pipe (|) is to take the output from man --help and then present it to the command more BR what more does is it allows output to be viewed one screen at at time BR if you press the down arrow the screen will scroll down one line at a time and if you use the space bar it is one page at a time BR however more faces a restriction a big restriction - you can only move in one direction - it only allows you to go down

we can do "more than more" by using a new command less BR the benefit of less is that we can go up and down BR we can use up and down arrows and page up and page down BR this is useful of you have lots of data

so if you do  man --help | less  you can test this you can navigate up and down and then to quit you can press q

now lets have some fun

please type  man man  BR on the foot of the screen you will see something like this  Manual page man(1) line 527/551 (END)  BR this indicates what manual page you are looking at before the bracket(1) in this case man, and it also lets you know how big the manual page is the last number, in this case 551 BR although the manual pages are written in a very "tight" style, if you get used to them you will find them good friends to discover options when you try to do something more complex BR now please press q and exit that man page BR

firstly let me tell you something of the layout of linux as it will help you understand some of what is there in front of you BR when I say layout just now referring to the filesystem BR you are currently in what is called your home directory BR the prompt is as I showed eariler


the ~ after the : is short hand for saying /home/your_username/ BR the word directory in english actually means "list" however to be clear about what a directory is I like to think of the hard drive as a filing cabinet BR there are many drawers in the filing cabinet each of the drawers can contain more drawers BR to see the list of "primary drawers" we can use the command ls which is short for list BR the whole cabinet is called / which we call "slash" not forward slash but slash BR this \ is "back slash" BR there is no forward slash Smile :)

that must be something else you are thinking about Smile :)

so let us get a list of the things in /

ls /
  • Q: is there a meaning for the colors of the dirs and files after ls ? BR A: there is, but lets not get ahead of ourselves

so you see bin BR it is the first directory there BR so now please do

ls /bin

the colour you see for bin indicates it is a directory BR you are now looking at the contents of /bin BR you can see some very common every day commands there BR ls is there BR date BR ps (which shows what processes are running on the computer when given certain arguments) BR tar touch sed and a lot of others BR the colour you see for arch and bash and most of the others in there is for an executable file BR depending on how your console is set up but in general, green BR

ls -al /bin/bash

-rwxr-xr-x 1 root root 664084 2006-04-21 23:51 /bin/bash

that is what it replies or something like that

you will notice that the there are several letters on the left hand side of the screen and some dashes BR they are the file permissions BR r = read from the file | w = write to the file | x = execute (run) the file BR you may notice that I say file BR and also you may remember I referred to "drawers containing drawers" BR well directories have file permissions too BR in fact directories are nothing more than fancy files that contain more files BR and they too have permissions BR if you run

ls -l / | grep bin

you will get back something like:

drwxr-xr-x   2 root   root    4096 2006-07-12 17:50 bin
drwxr-xr-x   2 root   root    8192 2006-08-18 23:37 sbin

now on the extreme left of the permissions you will see the letter d BR this indicates that these files are directories

so now you have two concepts: files and directories BR you have also a concept of permissions, however not in detail

you will notice if I take the /bin/bash permissions that it starts with a - BR then it has the first group of three rwx BR then a group with r-x BR and another group with r-x BR

well reading left to right we call these groups BR Owner Group World (or I have heard it called Everybody) BR

so what does this mean? BR well this gets more meaning from the two columns after the number 2 BR root root BR this is the owner of the file and the group that the file is owned by BR root owns the file and also there is a group called root BR they are not the same Smile :) BR in some cases BR like where your username is the group BR I will break it out into little blocks

so in your own home directory there are files

  • Q: the file is owned by a user called "root" and the file is also owned by a group called "root" ? BR A: yes BR Q: by group root.. u mean the username? BR A: no, explanation is to come

please type ls -al /etc/group

first off note that it is not executable BR second note that while any one in the group root anyone (everybody/world) can read it BR so it is readable by all users on the computer BR now let us look inside that file

less /etc/group

first line BR root:x:0: BR so this is a group BR the group has a numerical id it is 0 (as seen in the output) then as you look down the file you will see your username it will be a member of some of the groups in the machine. BR On ubuntu group 106 admin, for instance, is occupied by users who have "administration powers" BR if you press the space bar you will get to the end of the file

you will see the first user created on the machine as a group name = the username and with a GID (group id number) of 1000

in a business you might have a group sales BR and they would all be able to access the files belonging to the group "sales" BR now the reason we went down this road (and whole chapters in books have been written about permissions) BR was to explain that a file has an owner (as in a user) and a group owner and these things can be used to grant access to the users on the box or deny them access to a file BR this is important because if you can't run a file you may be trying to access something that the system will not allow BR

so now in your home directories BR all that information in a way that people don't usually "see" is BR please type

stat Desktop

ompaul@desktop:~$ stat Desktop/
  File: `Desktop/'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 303h/771d       Inode: 4653091     Links: 7
Access: (0755/drwxr-xr-x)  Uid: ( 1000/  ompaul)   Gid: ( 1000/  ompaul)
Access: 2006-08-20 12:20:29.000000000 +0100
Modify: 2006-08-20 08:05:46.000000000 +0100
Change: 2006-08-20 08:05:46.000000000 +0100

okay you will see the file name at the top BR I said eariler that directories were files BR you will see Desktop/ being called a file BR now for the most mind blowing thing you will ever learn about linux and unix based systems (at least in my opinion) BR EVERYTHING IS A FILE BR and I mean that. your screen, your keyboard, your mouse, they can be read, written to. your printer, your usb key, the whole system is a collection of files. You take data and you move it from one place to another this all goes back to an early design choice and it was very fortunate for us they choose that what it means is that you can take the output of a file and redirect it to another you an then add to it subtract and a whole lot of other things BR I will demonstrate that next

first off let us create a file in our home directories. BR the way to create an empty file is to use the touch command BR it is normal to refer to random files as "foo"

please type touch foo123 in your terminal BR now stat it BR the inode data there is its actual address on the file system BR which contains the info about where the file lives on the system BR as you note the file is owned by you BR it is readable and writable by you BR it is readable by the group and anyone on the machine BR you remember eariler we used man --help BR well let us capture that data in the file foo123 BR so do this

man --help > foo123

we can now look at the file with stat BR or we can do it the way most people do it

ls -l foo123

right now it looks like -rw-r--r-- 1 ompaul ompaul 2390 2006-08-20 12:45 foo123 BR the 2390 is the size of the file BR lets overwrite BR but first have a quick look

less foo123

press the space bar until you get to the end BR then press q to get out of less

so do this

wc foo123

now what do you think your looking at? BR lets find out what your looking at

man wc

what does that tell you BR wc - print the number of newlines, words, and bytes in files

so it tells you the lines that are in the file BR please press q to leave the man page BR so we have seen the original stat data of the file BR lets look at that

stat foo123 >> foo123

that should be fun BR after that type wc foo123

okay so when we type wc foo123 we note that the line has a size BR then if we do the next part: stat foo123 >> foo123 BR we add the stat info onto the end of the file BR so the point here is that the > single redirection pipe BR takes some "random input" and puts it into the file "in this case foo123" BR when we use the >> this APPENDS the additional data to the file BR in this case we got it to add on the contents for foo123 to the tail end of the file BR you can see this if you now type less foo123

now that is three pipes covered BR "A | B" take the data from the left (A) and hand to the the program on the right (B) to be processed BR we have also taken random data and put it into a file BR usually that is output we want to capture to analyse for later BR that is done with the > BR and then we can open an already full file and append data to it BR this is the >> BR NOTE the > overwrites all previous data BR

ls BR ls -al BR | BR > BR >> BR touch BR man BR and the concept of an argument BR

now to find your way around the file system BR you are in your home directory BR you can move from there to your desktop BR so in the terminal please type

cd Desktop

you have now moved to the desktop BR if you touch foo1234 here you will create an empty file on your desktop BR please do so and check it exists by minimising your irc window

to explain some more about where you are please consider the file system to be like this

 /                  <---- also referred to as root
 /home/                  <---- this is where all the users home directories live
      /ompaul/                <-- as it is in my case - this will be your username :)
             /Desktop/              <-- note the capital D

the full path is BR /home/ompaul/Desktop/ BR now we also know about /bin/ BR there are hundreds of directories on the machine BR and thousands of files (if not millions) BR now

cd /

takes you to the root of the file system BR you do not want to be creating things there BR in fact you do not have rights to create data in that directory BR the place you should create data is in you own directory or some subdirectory below that BR now if you are in the Desktop directory you can create a new directory in that BR mkdir myfirstdirectory BR you can then enter that BR

cd myfirstdirectory

so now you are within that location BR lets do something BR lets use the df command which tells us information about the file system layout BR but lets make it human friendly output BR do the following

df -h

now if you want to compare how much disk space is used over time BR we can record the disk space used today BR so do this

df -h > dfinfoAug20-2006

so this gives us as humans a file we can relate to BR now if you go to your desktop and click on myfirstdirectory BR you can find the file we just created in it

okay lets make a copy of that file into our home directory in the terminal BR type this much only

cp df

now hit tab key BR see it complete the file name BR now you want to get it into your home directory BR

cp dfinfoAug20-2006 /home/ompaul/.

note the dot at the end

I could change its name with this

cp dfinfoAug20-2006 /home/ompaul/MyNewName

or even do this

cp dfinfoAug20-2006 ~/.

which is the same as the first one

the dot means "keep the same file name" BR but .is is a hidden file called .is Smile :)

ls -al

the a means hidden and the l is long format (give lots of detail)

(at this point all the Students left, and the class gets cut short)

For more information see: https://help.ubuntu.com/community/BasicCommands