Advanced Command Line

From FreekiWiki
Jump to navigation Jump to search

Introduction and Prerequsites

This class is intended to be an extension of the Basic Linux Command Line for Builders class. It will review how to read a command and then explain the various option types. We'll then learn a few ways to interact with files and directories. You'll then learn about I/O redirection and finally some features of shells.

The instructor will expect that the students understand basic command line syntax as well as the advanced techniques of tab-completion and history usage, both of which are taught in the basic command line class. It's OK if you don't remember everything, but the more you can remember the more new stuff we'll be able to discuss.

Deconstructing a Command

Let's break down a command (a fairly complicated one) and see what it's doing and how to read it. The command we'll deconstruct is the following,

ls -la --sort=size -r /lib/modules/2.6.18-3-686/mod*

First let's examine what each element in this command is.

  • ls - This is the command you're going to run, it is an executable program which exists on your system (i.e. you can find the ls command, try 'which ls'.
  • -la - These are two short-hand options; the -l and the -a options. These options list using the long format and list all of the contents of a directory, respectively.
  • --sort=size - This is a long-hand option that takes an argument. In other words, we're telling the ls command to sort the output and specifically we're telling it to sort according to the file's sizes.
  • -r - This is another short-hand option that could have been combined with the other short-hand options, but it wasn't. It tells the ls command to list in reverse.
  • /lib/modules/2.6.18-3-686/mod* - This is the path which we wish to list. Note the '*' at the end; it's the wildcard character. It instructs ls to list only files within the /lib/modules/2.6.18-3-686/ directory that begin with "mod" and have zero or more characters following it. This means that these are all valid matches for the wildcard; "mod", "modd", "mod182", "modABC123" and "modihdasfkahsldkjhfhdsflkahsdlkhfalhdsflkajhslk3246367".

Examining Files

Copying, Creating and Moving Files

Copying, Creating and Moving Directories

BASH

I/O Redirection

Course Outline

  • Deconstruct a command
    • ls -la --sort=size -r /lib/modules/2.6.18-3-686/mod*
    • multiple option types
  • Examining files
    • file
    • cat
  • copying, creating and moving files
    • touch
    • cp
    • mv
  • copying creating and moving directories
    • mkdir
    • rmdir
    • cp -r
    • mv
  • bash
    • programming language
    • environment variables
    • PATH and tab completion
    • /etc/init.d/networking
  • I/O redirection
    • ls /media /foo 1> out.txt 2> err.txt
    • '>'
    • '>>'
    • tee
  • process model
    • ps (only user's processes)
    • ps -axf (all processes)
    • xeyes
    • suspend
    • bg and fg
    • kill
    • jobs
  • Advanced Topics
    • grave accent