Null/Shell
http://pzwart1.wdka.hro.nl/pad/p/null
Living in a Shell
Unix like OS are multi-user system, allowing a number of users to be logged at the same time and perform different tasks. Each user get's his/ser own home in ~/
shell / terminal
Shell is the program that interprets the commands written by the users (or other programs) and returns their output. There various shells: sh, bash, zsh. You can find out what shell you are running by prompting $SHELL
The Terminal is a wrapper program which runs a shell. It was once a physical device - a dumb terminal - consisting of monitor and keyboard, which would constitute a interface to the computer. Typical a computer would have many dumb connected to it.
ssh: remote access
If you have an account in a remote machine, you can login onto it from your machine by running the ssh
- secure shell program.
ssh username@hostname
once inside the machine
You can
- move around with the
cd
(change directory) - ask where are you
pwd
(print work directory) - list the files in your current directory
ls
- ask who are you
whoami
- ask what other users are logged in
users
communicating with other users
wall
- let's you send messages to all the logged users
write username
- writes private message to user
ASCII Art text
with: figlet "asciiart text"
Challenge: Use figlet fonts. Figlet fonts are stored in /opt/figlet_fonts/
ASCII Art images
with: jp2a img.jpg
Challenge: download an jpg image to the Pi and convert it into ASCII art
pipes, writes, appends
|
(a pipe) sends the output of one program to the input of another program.
$ echo "my sentence"| wc
the echoed sentence "my sentence" is pipped into the program wc which counts the number of lines, words, and characters
>
Writes the output of a command to a file, rather than to print on terminal.
man df > df_output.txt
redirect the content of man dfM
to a file called df_output.txt
If the said file doesn't exit it will create it, if it already exists it will overwrite its contents/
>>
appends the output of a command to a file, without overwriting the original file.
echo 'also add this' >> df_output.txt
will add 'also add this' to the contents of df_output.txt
Raw printing
In raw printing the printer does not interpret a description of the forms to draw. In raw printing plain-text characters are send to the printer and outputted by the printer in the sequence they are received, one line at a time.
echo "Hello Printer" > /dev/usb/lp0
will result in "Hello Printer" being printed.
Common Raw Printing Languages
The simplicity of raw printing has its shortcomings. You can easily print ASCII characters, but what if you want print large titles, or words in bold, or other character sets than ASCII, or even images?
One popular raw printing languages is ESC/POS, which stands for Epson Standard Code.
ESC/POS
Hexadecimal
get manual
rawprinting.py
In the Pi you have a program rawprinting.py
located in /usr/local/bin
that sends text to the printer and changes its modes.
To ask for help about this script run: rawprinting.py -h
Challenge: Print stuff and change the mode of the printer
Raw printing - script
Challenge: Can you get around to change the behavior ofrawprinting.py
script?
You can ask for help by running rawprinting.py -h
The script make use of ESC/POS - sequences of hex values, sent to the printer to change its behavior.
Some of the codes
"reset": "\x1B\x40", "justify_left": "\x1B\x61\x00", "justify_center": "\x1B\x61\x01", 'halfwidth_on': "\x1B\x21\x01", 'halfwidth_off': "\x1B\x21\x00", 'doubleprint_on': "\x1B\x47\x01", 'doubleprint_off': "\x1B\x47\x00", 'emphasis_on': '\x1B\x45\x01', 'emphasis_off': '\x1B\x45\x00', 'size_large': "\x1B\x21\x90", # 0=None 70=very lage+intalic, 90= medium large 'size_medium': "\x1B\x21\x90", 'size_small': "\x1B\x21\x00", 'space_btw_letters': '\x1B\x20\x01', # n [0,255] 'direction_0': '\x1B\x56\x00' , 'direction_90': '\x1B\x56\x01' , 'papercut':'\x1D\x56\x00',
ensure
Users can write to /dev/usb/lp0
Give users sudo
software
- figlet
- jp2a
- wget
- curl
subjects
- shell / terminal
- multi-user session
- access another machine: ssh
- communication among users
- ASCII art
- figlet
- jp2a
- (text to speech)
- raw printing
Shell Cheat Sheet
$ cd
- change directory
$ pwd
- print working directory
$ ls
- list directory
$ rm
- remove file or directory
$ cp
- copy file or directory
$ mv
- move or change name of file or directory
$ cat
- concatenate print they content
$ echo
- repeats what is written after
meta characters
Meta Characters are characters that have special meaning within the terminal
~
the tilde stands for the user's home.cd ~/
change directory to home.
dot stands for this directory.ls .
list this directory..
dot dot stands for the parent directory to this directory.cp myfile.jpg ..
copy myfile.jpg to the parent directory*
asterisk is a wildcards which represents zero or more charactersls P*.jpg
will list all the files, in the current directory, that begin with P and end with .jpg\
backslash it is a literal character. It escape the meta value of the meta-characters and display them only as literal characters.echo Foo \*
will outputFoo *
If \ wasn't there it would output all the files in that directory.
man pages
man pages are manuals of program. They tells you what the program is, what it can do and how.
$ man df
show the manual for the program df that is used to display the free disk space
Can you find out how to display the output from df in a human readable format?
pipe
A pipes (" | ") sends the output of one program to the input of another program.
$ echo "my sentence"| wc
the echoed sentence "my sentence" is pipped into the program wc which counts the number of lines, words, and characters
write
>
Writes the output of a command to a file, rather than to print on terminal.
man df > df_output.txt
redirect the content of man dfM
to a file called df_output.txt
If the said file doesn't exit it will create it, if it already exists it will overwrite its contents/
append
>>
appends the output of a command to a file, without overwriting the original file.
echo 'also add this' >> df_output.txt
will add 'also add this' to the contents of df_output.txt
==package managers== Package managers like apt and aptitude (on Debian/Ubuntu Linux distributions) and Homebrew and MacPorts on Mac, allow more (command-line, but not only) programs, than the ones that come with the operating, to be installed on our system. Will need to install 2: * figlet - A program to make large titles our of ASCII characters * imagemagick - The swiss army knife for image manipulation on the command line == Challenges == * You need to use '''figlet''' to print words and sentence on the terminal as large titles * Using Wget and imagemagick you need to ** Download an image from the web without using the browser to download the image, but the '''wget''' program using imagemagick's '''display''' program display the image ** using imagemagick's '''display''' program display the image, but flipped and monochrome ** using imagemagick's '''convert''' program the image to monochrome and to a different file extension.
references
- In the Beginning Was the Command Line http://www.cryptonomicon.com/beginning.html
- The Cathedral and the Bazaar, Eric S. Raymond http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/