Linux and the Shell Command Line
First - get your pi running
- Hook up
- Keyboard
- Mouse
- HDMI Cable
- Then hook up power and plug it in
Some Linux Shell Commands
There are a whole lot of Linux shell commands literally
thousands. And it is unlikely you will memorize them all, or
even ever use them all. And if you are used to using a point
and click graphical user interface, the terminal (shell)
command line interface can be as confusing as the Word Cloud
above. But this will pass as you gain more experience.
We will cover a few (well more than a few) of the most important
commands.
First some background
- The default shell on the Raspberry Pi is bash. A shell
is the user interface program between the user (us) and the
Kernel.
- From man bash: "Bash is an
sh-compatible command language interpreter that executes
commands read from
the standard input or from a file. Bash also incor‐
porates useful
features from the Korn and C shells (ksh and csh)."
- bash will look for programs to run in $PATH:
/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
Second some very important pieces of information:
- Linux commands and names are case sensitive foo is not the
same as Foo, fOO, foO etc.
- To run a command in your directories you need to type ./foo where foo
is the command name
Information
- man - display a manual page
- apropos search for a relevant manual page
- pwd - print working directory (show me where I
am). It's easy to loose track of the directory you are in.
- ps - process status
- df - show disk usage
- ip address - display the ip address of your pi
- ping - bounce a short message off another machine to see if it
is there.
Directories
- cd - change working directory
- mkdir - make a new directory
- rmdir - remove an empty directory
- pushd - push a directory onto the directory stack. This
is so you can get back to where you came from.
- popd - pop the (top see switches) entry off the directory
stack and goes there
- dirs - show the directory stack
Files
- nano - edit a file.
- ls - list the contents of a directory. The -l switch
shows more detail
- rm - remove (delete) a file
- cp - copy a file to a new file name or a new directory.
- mv - move a file to a different directory or change a file
name.
- chmod - change a file's mode (permission) bits.
Owner
|
group
|
other
|
rwx
|
rwx
|
rwx
|
421
|
421
|
421
|
- 700 is rwx for the owner nothing for everyone else
- 644 is rw for the owner, read only for everyone else
- 755 is rwx for the owner r x for everyone else.
- Or if you want to do it symbolically (the hard way in my
opinion) u+rwx g+rx o+rx is the same as 755, or - to remove a
permission o-rx to remove read and execute from other.
- touch - create an empty file, or update a file's times to now.
- more or less - display a file one screen at a time.
- cat - concatenate, or show a file
Control
- passwd - change your password
- sudo - become super user for a moment. This is
needed when installing programs and editing config files etc.
- apt-get update - update the repository information, install -
install a new program
- halt - halt your pi safely
- echo - display what follows on the screen
- clear - clear the screen
- reboot - reboot your pi safely
Shell Special Keys
- | pipe, copy the output of one program to the input of another
program.
- > redirect, redirect the output from a program to a file.
- Ctrl-C key - terminate the current process
- Tab key - fill in the rest of the command if possible.
- \ - escape the next character.
- ls -l this is my file.txt will try to list the files this,
is, my and file.txt. ls -lthis\ is\ my\ file.txt will
list the desired file info.
- A good reason not to use spaces in file names, but if they
are encountered it can be dealt with.
- * - anything
- ls *foo* will match all files that contain foo
somewhere in their name.
- ~ - The current users home directory.
- ~/foo/bar is the same as /home/pi/foo/bar. Assuming
this is the pi user.
Simple Shell Scripts
- shell scripts. You will often encounter several commands
you use often or a command that is useful but you never remember
where it is. You can stick the commands in a file and then
run the file. EG.
- the file cpuTemp contains
- /opt/vc/bin/vcgencmd
measure_temp
- alias
Homework
- Install the screen capture program scrot using apt-get.
- Explore 5 of the commands above that we did not cover in
detail.
- use scrot
to capture 5 images of you using these commands. 1 for
each command you choose. You can learn how to use scrot using man scrot
- email those images to me. deid@drsol.com
- create and experiment with your own shell script. Email
that script too.