Basic Linux Command Line for Builders
- 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.
Rob is currently teaching the class with these commands in this order: Rwlove_cli
to begin the class
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-F10or 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$
- Mention that the Linux command line is case sensitive.
Parts of a Command
- 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.
- 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.
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.
lsand 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 Dand 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.
ls yourname(note that it's actually the same files as in Desktop)
ls(note that it removed yourname)
- cd D<tab> (becomes cd Desktop)
- cd ..
- cd /
- You are now in the root of the filesystem. Point out the directories and their uses.
- boot - files necessary to boot the system
- 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
- cd ~
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.
- absolute path - The location of a file or directory in the filesystem starting from root. This always starts with a "/"
- 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
Copying and moving files
-Need to write. Cover deletion by moving to .Trash. -Tony Diethelm
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)
- 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
- 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....
- 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.
- ls (note the presence of the modules file)
- nano modules (note that your changes were saved there)
- nano /etc/mod<tab><tab>
system configuration via tab-completion:
- lsm<tab> (lsmod: list modules. usually we use this to look for 3c509, eexpress or ne modules)
- lspc<tab> (lspci: lists pci devices. look for VGA for video card information)
- 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.
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
- http://www.linuxdevcenter.com/linux/cmd O'Reilly's Alphabetical Directory of Linux Commands
- http://www.karakas-online.de/gnu-linux-tools-summary/ GNU/Linux Command-Line Tools Summary
- http://www.linuxcommand.org/learning_the_shell.php Learning the Shell (The content/flow is pretty close to what is presented on this page)