Command Line Basics Part 1

Revision 1 as of 2010-07-10 19:15:10

Clear message

Session Logs

   1 [19:02] <Pendulum> next up is _marx_ with Command Line Basics
   2 [19:02] <Pendulum> Mark Cox lives in Winston-Salem, North Carolina. He has made his living as a carpenter since getting out of the Army in '85.  He has been using Linux since 1998. Mark has been using Ubuntu since 5.04.
   3 [19:02] <Pendulum> He hopes to be unique by being the first Grandfather in recorded history to convert his grandsons to Ubuntu instead of the other way around. Mark's two oldest grandchildren were dazzled by "the cube" over the holidays.
   4 [19:02] <_marx_> Thanks Pendulum
   5 [19:03] <_marx_> Welcome everyone to Command Line Basics
   6 [19:03] <_marx_> When we use the command line we are using a shell. In this context a shell is the most basic way a user can interact with a computer's operating system kernel.
   7 [19:03] <_marx_> A shell is a piece of software. A unix type system can have many different shells installed.
   8 [19:04] <_marx_> The user can choose which shell they use. Most GNU/Linux distributions use the Bourne Again SHell (bash) as the login shell.
   9 [19:04] <_marx_> The again part is because the first iteration was called the Bourne SHell (sh).
  10 [19:05] <_marx_> Now in the first UUD this next line sparked some comments
  11 [19:05] <_marx_> Beginning with the 6.10 release Ubuntu began using dash (the Debian Almquist Shell) as the default system shell. The default login shell is still bash.
  12 [19:06] <_marx_> For this session we don't need to be concerned with the differences between dash and bash.
  13 [19:06] <_marx_> Today we will learn how to navigate the Linux file system, view the contents of a file, copy and rename files and directories, pipe output of one command to another, direct output to a file, install programs, navigate the internet all via the command line interface.
  14 [19:07] <_marx_> For our exercises today I will be using the Gnome terminal.
  15 [19:08] <_marx_> so I am assuming that you are using gnome. If you aren't just open a terminal or Konsole in KDE
  16 [19:09] <_marx_> I want to make opening a terminal a click or two faster so click Applications > Accessories and drag Terminal into your top panel. I'm not real familiar with KDE and Xfce so maybe just drop the icon on the desktop to create a launcher.
  17 [19:09] <_marx_> This creates a launcher that will start a terminal session without using the menu system.
  18 [19:10] <_marx_> Now let's open a terminal session, just click the icon we just created in the top panel.
  19 === Johnson is now known as Guest76322
  20 [19:10] <_marx_> Everyone have a terminal open now?
  21 [19:11] <_marx_> I'm going to try to remember to wrap all my command examples with quotes around them so just type whatever is inside the single quote marks.
  22 [19:12] <_marx_> Let's type our first command: 'whoami'.
  23 [19:13] <_marx_> Well now you know who you are!
  24 [19:14] <_marx_> That was an informative command, no?
  25 [19:14] <_marx_> So where are we? Let's use print working directory to find out; 'pwd'.
  26 [19:15] <_marx_> the concept of "where am I" is an important basic unix concept
  27 [19:16] <_marx_> Next let's see what files are here. To do this we'll list the contents with the list command; ls is list so type "ls".
  28 [19:17] <_marx_> eviltux, 'hostname'
  29 [19:18] <_marx_> I realize -chat isn't being logged but what just transpired there illustrates another important concept.
  30 [19:18] <_marx_> There always more than one way.
  31 [19:19] <_marx_> This will list the files in our current directory.
  32 [19:19] <_marx_> notice i said directory
  33 [19:19] <_marx_> Ah, if you are moving from a GUI oriented operating system a directory is the same thing as a folder.
  34 [19:20] <_marx_> To list all the files and directories that are here type "ls -a" The -a means all.
  35 [19:20] <_marx_> Interesting eh? You should see a bunch of files and directories with a "." in front of them.
  36 [19:21] <_marx_> These are called "dot files" or hidden files. Some are files and some are directories.
  37 [19:22] <_marx_> The -a addition is an option or flag for the ls command. Another is -l.
  38 [19:23] <_marx_> Let's try typing 'ls -l'.
  39 === virtuald_ is now known as virtuald
  40 [19:23] <_marx_> This outputs a long listing which includes file permissions, owner and group, size and date accessed.
  41 [19:24] <_marx_> Now we can put two or more options together like 'ls -al'
  42 [19:24] <_marx_> or 'ls -alh'
  43 === eviltux is now known as ^_^EvilTux^_^
  44 [19:24] <_marx_> the -h option makes the file size output more Human readable
  45 [19:25] <_marx_> Next we will move around the file system.
  46 [19:25] <_marx_> To move around the file system we use the cd command.
  47 [19:25] <_marx_> This command means change directory.
  48 [19:26] <_marx_> Everyone type 'cd /'
  49 === ^_^EvilTux^_^ is now known as EvilTux
  50 [19:27] <_marx_> So where are we now? Well we are in the root of the Linux file system.
  51 === rmcbride_ is now known as rmcbride
  52 [19:27] <_marx_> But exactly where are we? Let us use the pwd command to find out. Type 'pwd' to print working directory.
  53 === Adityab|Busy is now known as Adityab
  54 [19:28] <_marx_> Well that just shows "/" so what is here? Let's type "ls" to find out.
  55 [19:28] <_marx_> Questions on ls, cd or pwd?
  56 [19:29] <_marx_> date
  57 [19:30] <_marx_> Okay let's go look at something interesting here. 'cd etc/init.d'
  58 === EvilTux is now known as eviltux
  59 [19:31] <_marx_> how many got a file not found error?
  60 [19:32] <_marx_> bash: cd: etc/init.d: No such file or directory
  61 [19:32] <_marx_> if you get that error you weren't in / when you did cd etc/init.d
  62 [19:33] <_marx_> Now let's get the heck out of here as this is all the startup scripts for your system.
  63 [19:33] <_marx_> not a good place to play around
  64 [19:34] <_marx_> Just type "cd" By default that will take you back to your home directory. Do a "pwd" to confirm.
  65 [19:35] <_marx_> To simply view the contents of a file we can use less, more or cat, which dumps the content to standard output.
  66 [19:35] <_marx_> Since we are now in our home directories we'll have to use the full path to a file in /etc to view it so let's try 'less /etc/init.d/gdm'
  67 [19:36] <_marx_> We should now all be looking at the gnome display manager startup script.
  68 [19:37] <_marx_> <eviltux> QUESTION: Can't we do: cat file.txt | less?
  69 [19:37] <_marx_> yes but that's redundant
  70 [19:38] <_marx_> and less will let you move up and down in the file with up and down arrow keys
  71 [19:38] <_marx_> Use "q" to exit less.
  72 [19:41] <_marx_> We're not going to get into editing something like this today as it is way beyond the perview of basic command line.
  73 [19:42] <_marx_> So let's move on to copying and renaming files.
  74 [19:42] <_marx_> Everybody go home with 'cd'
  75 [19:42] <ClassBot> suprengr asked: did someone remember to tell new users 'paste' is SHIFT Ctrl-V
  76 [19:43] <_marx_> now classbot kicks in :\
  77 [19:43] <_marx_> click the center button, or wheel or left and right at the same time
  78 [19:44] <_marx_> Let's make a directory to store our practice excercises "mkdir stuff" or whatever you would like to name it.
  79 [19:44] <_marx_> mkdir means make directory
  80 [19:45] <_marx_> List your home again and that directory should be there; now cd into it with 'cd stuff'
  81 === eviltux is now known as libeviltux-dev
  82 [19:47] <_marx_> now there are of course several ways to create a file
  83 [19:48] <_marx_> perhaps the most basic is 'touch'
  84 [19:48] <_marx_> 'touch testfile' in /home/username/stuff
  85 [19:49] <_marx_> other ways include using an editor, example 'vim testfile' would create testfile and open it in the worlds best text editor
  86 [19:50] <ClassBot> There are are 10 minutes remaining in the current session.
  87 [19:52] <_marx_> Questions?
  88 [19:53] <ClassBot> libeviltux-dev asked: what would happen If I did this: echo "stuff" > testfile; tail testfile >> testfile
  89 [19:53] <_marx_> !q
  90 [19:53] <_marx_> oops
  91 [19:54] <_marx_> libeviltux-dev, you should have a file contaning two lines stuff and stuff
  92 [19:55] <_marx_> try it and see!
  93 [19:55] <ClassBot> There are are 5 minutes remaining in the current session.
  94 [19:58] <_marx_> i'm going to refill my mug before the next session starts, brb < 1 minute