Difference between revisions of "Talk:Basic Linux Command Line for Builders"

From FreekiWiki
Jump to navigation Jump to search
(intial dump of CL class document with tweaks ... 10% done at best)
 
(11 intermediate revisions by the same user not shown)
Line 12: Line 12:
 
:The purpose of this class is to teach builders-to-be real basic stuff about using the [[command line]] in [[linux]] so when we say "ok, now go to dev" you know what to type. This is written as a script that, with ingenuity, can be either a teacher's guide or a self-guided lesson.
 
:The purpose of this class is to teach builders-to-be real basic stuff about using the [[command line]] in [[linux]] so when we say "ok, now go to dev" you know what to type. This is written as a script that, with ingenuity, can be either a teacher's guide or a self-guided lesson.
  
==Proposal for New "Basic" Command Line Class"
+
==Proposal for New "Basic" Command Line Class"==
 +
The following is an edited version of the original CL class documentation with two goals:
 +
* make it shorter
 +
* improve hands on actions versus being talked at
 +
 
 
==to begin the class==
 
==to begin the class==
 +
* Define command line: A way to tell an operating system what to do with the keyboard.  Sure, some of the same things can be done with a mouse, but this is not always possible or desirable.
 +
* Talk about why you would bother to use the  command line.
 +
** Its much easier to do certain things, like move many files of the same type from different locations to a single folder (like pooling your photos or music, for example).
 +
** Some things you can only do in the command line
 +
** GUIs change, but the terminal commands usually stay the same for looooooong periods of time
 +
** If you stick with learning about how computers work, its an easier and more powerful way to string commands together (like a big macro).
 +
* CL can be especially helpful for troubleshooting why your computer is not working properly
 +
* Free Geek uses command line in all of its production areas and tech support
 
This assumes you're at a terminal in the Free Geek classroom.
 
This assumes you're at a terminal in the Free Geek classroom.
 
* log in, close the web browser.
 
* log in, close the web browser.
Line 20: Line 32:
 
::<small>''If you're on a [[FreekBox|FreekBox3]], you can open an xterminal by clicking on the button on the taskbar that looks like a monitor with a black screen.''  On an Ubuntu box, go to Applications>Accessories>Terminal</small>
 
::<small>''If you're on a [[FreekBox|FreekBox3]], you can open an xterminal by clicking on the button on the taskbar that looks like a monitor with a black screen.''  On an Ubuntu box, go to Applications>Accessories>Terminal</small>
 
* Go over the parts of a command prompt. ie: user@system:location$
 
* Go over the parts of a command prompt. ie: user@system:location$
* Mention that the Linux command line is case sensitive.
+
** user is the name of the user
 +
** system is the name of the computer
 +
** location is location in the filesystem
 +
** dollar sign means a user without special priveleges (# is administrative, or root)
 +
* Mention that the Linux command line is case sensitive.  Meaning A and a are not the same letters.
 +
* Finally, point out that because command line is so powerful, true mastery can take years.  Just focus on what you need to do and you'll often learn commands faster than just reading them like a book.
  
 
==Make a File==
 
==Make a File==
Line 27: Line 44:
  
 
===Parts of a Command===
 
===Parts of a Command===
 +
* A command is a program!  You can also start programs you are more used to, like Firefox, with the CL.  Like most programs you can use, it does more than one thing.
 
* Go over the parts of a command. ie: command -options target(s)
 
* Go over the parts of a command. ie: command -options target(s)
 
* '''command''' - The name of the program being run is the start of a line and must be separated from the options and target by a space or spaces. These are almost  
 
* '''command''' - The name of the program being run is the start of a line and must be separated from the options and target by a space or spaces. These are almost  
Line 39: Line 57:
 
* '''target''' - This is the thing acted on, a file or directory generally.
 
* '''target''' - This is the thing acted on, a file or directory generally.
 
* We will save in-depth talk about the extra information you see with the "-l" option for another class.
 
* We will save in-depth talk about the extra information you see with the "-l" option for another class.
 +
* Command, option, path (argument) ... can move options and paths around, but usually you will leave the path at the end in case you mistype it and need to correct it (up arrow).
 +
* Have student type ls /home.  This allows the student to see a practical use of ls (in this case its to see that names of the users on the computer).
 +
* Remind students that if they remember the name of a command (but not its options) they can type man "commandname" for its manual. 
 +
* Show students the manual for ls
  
 
==listing, linking, removing, tab completion:==
 
==listing, linking, removing, tab completion:==
Line 52: Line 74:
 
* <code>ls -l</code> (note that yourname points to Desktop)
 
* <code>ls -l</code> (note that yourname points to Desktop)
  
Note: periodically remind them about [[tab completion]] if they're not picking it up- it's a real arthritis-saver.
+
Note: periodically remind them about [[tab completion]] if they're not picking it up- it's a real arthritis-saver.  It also means you do not have to memorize nearly as much.
  
 
* <code>ls D<tab></code>
 
* <code>ls D<tab></code>
Line 58: Line 80:
 
* <code>[[rm]] yourname</code>
 
* <code>[[rm]] yourname</code>
 
* <code>ls</code> (note that it removed yourname)
 
* <code>ls</code> (note that it removed yourname)
 
  
 
== moving around ==
 
== moving around ==
 
*cd D<tab>      (becomes '''cd Desktop''')
 
*cd D<tab>      (becomes '''cd Desktop''')
 
*ls
 
*ls
*cd ..
+
*cd .. (goes backwards, or up)
 
*ls
 
*ls
 
*cd /
 
*cd /
 +
*cd /home/username/Desktop/just_pick_a_file_name
 
*ls
 
*ls
 
*: You are now in the root of the filesystem.  Point out the directories and their uses.
 
*: You are now in the root of the filesystem.  Point out the directories and their uses.
<i>
+
*Now you let the student know that most of their personal stuff with be in /home/username/some_directory and that talking about what lives in what directory is a subject of a later class.
:'''boot''' - files necessary to boot the system
+
*cd ~ (goes home)
:'''dev''' - "device": pointers to devices
 
:'''etc''' - configuration files
 
:'''home''' - directories for user accounts
 
:'''media''' - mount points for floppy, cdrom etc
 
:'''mnt''' - temporary mount point
 
:'''proc''' - snapshot of operating system
 
:'''tmp''' - temporary files
 
:'''usr''' - userspace programs and documentation
 
:'''var''' - files of variable size, logs, print and email spools, web files
 
</i>
 
 
 
*cd ~
 
 
*ls
 
*ls
  
  
 
===Filesystem structure===
 
===Filesystem structure===
The Linux filesystem is arranged as a single tree (an upside-down tree if you are really a visual person), rather than as a set of containers as in MS Windows.  Drives and other devices all have to be mounted somewhere on this tree to be recognized. The filesystem starts with "/" which is the root of the filesystem.
+
The Linux filesystem is arranged as a bush starting from the roots and moving through branches to leaves. There are not letters representing hard drives.   The filesystem starts with "/" which is the root of the filesystem (or roots of a bush). Each branch has a name (and looks like a folder if using a GUI).  Some branches are hidden so that people feel less inclined to monkey with them (recall ls -a) and to save time.  *Note* - Now is good time to explain the difference between the root user and the root of the filesystem.
 +
 
 
* '''absolute path''' - The location of a file or directory in the filesystem starting from root.  This always starts with a "/"
 
* '''absolute path''' - The location of a file or directory in the filesystem starting from root.  This always starts with a "/"
 
::/home/guest/files/example.txt
 
::/home/guest/files/example.txt
 +
 
* '''relative path''' - The location of a file or directory starting from you current working directory.  It never starts with a "/".  The following example assumes you are in /home/guest
 
* '''relative path''' - The location of a file or directory starting from you current working directory.  It never starts with a "/".  The following example assumes you are in /home/guest
 
::files/example.txt
 
::files/example.txt
  
 +
* Some stuff, especially stuff critical to the functioning of the operating system, will not let you read or write it (you don't have permission).
  
 
==Copying and moving files==
 
==Copying and moving files==
-Need to write. Cover deletion by moving to .Trash. -Tony Diethelm
+
-cp /home/username/Desktop/ etc ... to ... /home/username/where_its_going (works just like GUI copy)
 +
-mv /home/username/Desktop/ etc ... to ... /home/username/where_its_going (works like cut and paste)
  
 
==more tab-completion, text editors, modules file:==
 
==more tab-completion, text editors, modules file:==
now we're going to use a text editor, which is basically like a very simple word processor- no bold, underlining or italics- just plain old text. (in this example i use nano, since that's what most build instructors end up teaching.  mcedit is another text editor that would work)
+
now we're going to use a text editor, which is basically like a very simple word processor- no bold, underlining or italics- just plain old text. (in this example i use nano, since that's what most build instructors end up teaching.  mcedit is another text editor that would work).  Tab completion works like "word-wheeling" in iTunes (most people have used iTunes).
  
 
* nano /etc/m hit tab twice. (note all the possible completions)
 
* nano /etc/m hit tab twice. (note all the possible completions)
Line 104: Line 118:
 
* nano /etc/modul<tab> (note how it completed it out to modules)
 
* nano /etc/modul<tab> (note how it completed it out to modules)
 
* nano /etc/modules
 
* nano /etc/modules
*:this file basically contains certain hardware modules(or in windows terms "drivers") to load when the computer starts up. in build, we're usually looking for 3c509, eexpress or ne.  use the arrow keys to move the cursor to the bottom of the screen, and type in whatever you want to say....
+
* nano /h <tab> /user <tab> /D <tab> /j <tab>
 +
* sudo nano /home/user/Desktop/just_etc ...
 
* ctrl-o to save it.  in the "File Name to write: " section near the bottom, it should say "/etc/modules". hit enter to save it. ''(note, they get a permission denied message, because they are not root)''
 
* ctrl-o to save it.  in the "File Name to write: " section near the bottom, it should say "/etc/modules". hit enter to save it. ''(note, they get a permission denied message, because they are not root)''
 
* try again: ctrl-o, and change "/etc/modules" to "modules"
 
* try again: ctrl-o, and change "/etc/modules" to "modules"
 
* ctrl-x to exit.
 
* ctrl-x to exit.
* ls (note the presence of the modules file)
 
 
* nano modules (note that your changes were saved there)
 
* nano modules (note that your changes were saved there)
* nano /etc/mod<tab><tab>
 
 
  
 
==system configuration via tab-completion:==
 
==system configuration via tab-completion:==
 
* ls<tab><tab>  
 
* ls<tab><tab>  
* lsm<tab> (lsmod: list modules. usually we use this to look for 3c509, eexpress or ne modules)
+
* lsp<tab> (completes lspci ... lists what is connected to the PCI bus)
* ls<tab><tab>
+
* explain that tab completion works for commands also
* lspc<tab> (lspci: lists pci devices.  look for VGA for video card information)
 
 
 
 
 
==networking==
 
* ping glacier (we're pinging the server named glacier, which is the server used in the build area)
 
* ctrl-c to quit
 
*: note the difference from the dos ping utility which quits after 4 pings
 
* ifconfig (note eth0 and eth1 are both seen in lspci, note lo interface)
 
 
 
==extras- dmesg, grep, piping:==
 
Go over these if there is time.
 
* [[dmesg]]
 
* dmesg | [[less]]
 
* dmesg | [[grep]] eth
 
  
  
Line 139: Line 137:
  
 
any other questions?
 
any other questions?
 
[[Category:Classes]]
 
[[Category:Command line]]
 
[[Category:Build]]
 
  
 
==Reference for further study==
 
==Reference for further study==

Latest revision as of 14:23, 30 April 2010

I always give an example of a man page. -- MW 12:10, 27 Aug 2005 (PDT)

This page on linuxcommand.org
http://linuxcommand.org/lts0040.php ... could fill an hour of a class with just that.
Would talk about this, possibly
  • location of common information, e.g., processor information in the file system
  • symbolic links, in relation to GRUB, available kernels, etc.
  • Read and write, from the standpoint of both a user and an operating system
  • linux can teach you about how an operating system works because you can look at the steps individually.
  • a big problem with cl students is they want to start learning about how an operating system works, but even small questions in that direction blow up really quickly.


The purpose of this class is to teach builders-to-be real basic stuff about using the command line in linux so when we say "ok, now go to dev" you know what to type. This is written as a script that, with ingenuity, can be either a teacher's guide or a self-guided lesson.

Proposal for New "Basic" Command Line Class"

The following is an edited version of the original CL class documentation with two goals:

  • make it shorter
  • improve hands on actions versus being talked at

to begin the class

  • Define command line: A way to tell an operating system what to do with the keyboard. Sure, some of the same things can be done with a mouse, but this is not always possible or desirable.
  • Talk about why you would bother to use the command line.
    • Its much easier to do certain things, like move many files of the same type from different locations to a single folder (like pooling your photos or music, for example).
    • Some things you can only do in the command line
    • GUIs change, but the terminal commands usually stay the same for looooooong periods of time
    • If you stick with learning about how computers work, its an easier and more powerful way to string commands together (like a big macro).
  • CL can be especially helpful for troubleshooting why your computer is not working properly
  • Free Geek uses command line in all of its production areas and tech support

This assumes you're at a terminal in the Free Geek classroom.

  • log in, close the web browser.
  • open a terminal session, ICEWM>Programs>XShells>Xterm (if the text is too small, hold down the control key and the right mouse button to get a font size menu)
  • make the window larger, using either Alt-F10 or the maximize button.
If you're on a FreekBox3, you can open an xterminal by clicking on the button on the taskbar that looks like a monitor with a black screen. On an Ubuntu box, go to Applications>Accessories>Terminal
  • Go over the parts of a command prompt. ie: user@system:location$
    • user is the name of the user
    • system is the name of the computer
    • location is location in the filesystem
    • dollar sign means a user without special priveleges (# is administrative, or root)
  • Mention that the Linux command line is case sensitive. Meaning A and a are not the same letters.
  • Finally, point out that because command line is so powerful, true mastery can take years. Just focus on what you need to do and you'll often learn commands faster than just reading them like a book.

Make a File

  • sudo nano /home/username/Desktop/just_make_up_a_file_name
  • Enter text. For example, "Hello, World!"

Parts of a Command

  • A command is a program! You can also start programs you are more used to, like Firefox, with the CL. Like most programs you can use, it does more than one thing.
  • Go over the parts of a command. ie: command -options target(s)
  • command - The name of the program being run is the start of a line and must be separated from the options and target by a space or spaces. These are almost
  • option - These modify the command. They mostly either begin with a "-" or a "--"
    • single letter options start with a single dash and can generally be strung together. The following examples are equivalent. Remember all commands are executed by pressing enter.
ls -a -l
ls -al
ls -la
  • long option names start with a double dash. They cannot be combined, and may or may not have an equivalent single letter equivalent. The following are equivalent, reversing the sort order of the results of the command.
ls --reverse
ls -r
  • target - This is the thing acted on, a file or directory generally.
  • We will save in-depth talk about the extra information you see with the "-l" option for another class.
  • Command, option, path (argument) ... can move options and paths around, but usually you will leave the path at the end in case you mistype it and need to correct it (up arrow).
  • Have student type ls /home. This allows the student to see a practical use of ls (in this case its to see that names of the users on the computer).
  • Remind students that if they remember the name of a command (but not its options) they can type man "commandname" for its manual.
  • Show students the manual for ls

listing, linking, removing, tab completion:

In this section, students learn that they are located in the file system, that you need to hit enter to make the command run, that the way the command runs can be modified with flags, and how to use tab completion.

  • First: Point out that students can recall previously typed commands by pressing the up arrow.
  • type ls and hit enter. (list files in the current directory)
  • ls -l (and hit enter... the long listing, point out time/date info)
  • ls -a (shows all files, note that most begin with . Point out . (the current directory) and .. (one step towards root in the filesystem))
  • ls -al (shows all files the long way)
  • ls (point out the Desktop directory again)
  • ls D and hit tab, and hit enter. (note how it finished out the rest of the word Desktop)
  • ln -s D<tab> yourname
  • ls -l (note that yourname points to Desktop)

Note: periodically remind them about tab completion if they're not picking it up- it's a real arthritis-saver. It also means you do not have to memorize nearly as much.

  • ls D<tab>
  • ls yourname (note that it's actually the same files as in Desktop)
  • rm yourname
  • ls (note that it removed yourname)

moving around

  • cd D<tab> (becomes cd Desktop)
  • ls
  • cd .. (goes backwards, or up)
  • ls
  • cd /
  • cd /home/username/Desktop/just_pick_a_file_name
  • ls
    You are now in the root of the filesystem. Point out the directories and their uses.
  • Now you let the student know that most of their personal stuff with be in /home/username/some_directory and that talking about what lives in what directory is a subject of a later class.
  • cd ~ (goes home)
  • ls


Filesystem structure

The Linux filesystem is arranged as a bush starting from the roots and moving through branches to leaves. There are not letters representing hard drives. The filesystem starts with "/" which is the root of the filesystem (or roots of a bush). Each branch has a name (and looks like a folder if using a GUI). Some branches are hidden so that people feel less inclined to monkey with them (recall ls -a) and to save time. *Note* - Now is good time to explain the difference between the root user and the root of the filesystem.

  • absolute path - The location of a file or directory in the filesystem starting from root. This always starts with a "/"
/home/guest/files/example.txt
  • relative path - The location of a file or directory starting from you current working directory. It never starts with a "/". The following example assumes you are in /home/guest
files/example.txt
  • Some stuff, especially stuff critical to the functioning of the operating system, will not let you read or write it (you don't have permission).

Copying and moving files

-cp /home/username/Desktop/ etc ... to ... /home/username/where_its_going (works just like GUI copy) -mv /home/username/Desktop/ etc ... to ... /home/username/where_its_going (works like cut and paste)

more tab-completion, text editors, modules file:

now we're going to use a text editor, which is basically like a very simple word processor- no bold, underlining or italics- just plain old text. (in this example i use nano, since that's what most build instructors end up teaching. mcedit is another text editor that would work). Tab completion works like "word-wheeling" in iTunes (most people have used iTunes).

  • nano /etc/m hit tab twice. (note all the possible completions)
  • nano /etc/mo<tab><tab> (note the shorter list)
  • nano /etc/mod<tab><tab> (note the shorter list)
  • nano /etc/modul<tab> (note how it completed it out to modules)
  • nano /etc/modules
  • nano /h <tab> /user <tab> /D <tab> /j <tab>
  • sudo nano /home/user/Desktop/just_etc ...
  • ctrl-o to save it. in the "File Name to write: " section near the bottom, it should say "/etc/modules". hit enter to save it. (note, they get a permission denied message, because they are not root)
  • try again: ctrl-o, and change "/etc/modules" to "modules"
  • ctrl-x to exit.
  • nano modules (note that your changes were saved there)

system configuration via tab-completion:

  • ls<tab><tab>
  • lsp<tab> (completes lspci ... lists what is connected to the PCI bus)
  • explain that tab completion works for commands also


final check-in:

do they seem to understand the concept of typical command syntax: command <option flags> arguments

"what to do, how to do it, and what to do it to"

any other questions?

Reference for further study