CS246-F20-01-UnixShell
Lecture 1.2
• The UNIX file system
• Introducing the bash shell
CS246
The UNIX file system
Image from
http://www.openbookproject.net/tutorials/getdown/unix/lesson2.html
The UNIX file system
• Pretty much all OSs have a file system of some kind
– Even iOS does, tho it’s hidden from users
– In OSs for small devices, it’s often a single flat space (or a database)
– More often, tho, it’s a tree-like hierarchy of
• directories (folders) that can contain other files/directories and
• “normal” files
• (+ other special kinds of files we won’t discuss much, like symbolic links)
• Your home directory (folder) is where your stuff is stored
– … and not the system stuff, and not the stuff of the others who use your
computer
– My home dir is in:
• /Users/migod on MacOS
• /home/migod on my desktop Ubuntu Linux box
• /ux/migod on plg Ubuntu Linux server
• At the command line, you can reference your home dir by ~ or $HOME
– And ~fred is the home dir of user “fred” (no slash)
The UNIX file system
$ cd ~/Documents/MyBigNovel
The UNIX shell
• sh (“Bourne shell”): the first practical, widely-used UNIX shell
– Later relatives of sh: bash (“Bourne again” shell), ksh (Korn shell)
• Originally, meant for programmers to write shell scripts
– Other common shells: csh, tcsh
• Meant for “end users” (but modern bash is pretty nice too)
• We’ll use bash
% echo $0
-tcsh
% bash
$ echo $0
bash
Oops, wrong shell
Start up bash instead
That’s better
Commands in the UNIX shell
• When you are executing a shell, you are always “somewhere”
in the file system
– pwd tells you what directory you are currently sitting in
• By default, you start in your home dir ($HOME aka ~)
cd with no args takes you back home
cd – takes you to the previous dir you were sitting in
cd .. takes you to the parent of the current dir
cd . leaves you where you are J
% pwd
/Users/migod
% cd temp
% ls
Hearts> balloon.cc oldStuff/
% g++ -o balloon balloon.cc
% ./balloon
clear balloon
red balloon
green balloon
green balloon
% cd Hearts/
% ls
Card.cc Makefile.bak* Trick.cc hearts.xcodeproj/
Card.h Options.h* Trick.h hearts.xml.zip
CardPile.cc Player.cc build/ ideas
CardPile.h Player.h deck1* main.cc
Deck.cc RandomPlayer.cc deck2* mkPrintable*
Deck.h RandomPlayer.h deck3* printme/
Globals.h SmartPlayer.cc hearts.1
Makefile SmartPlayer.h hearts.mdr
% cat Makefile
# Make sure you’re using /usr/ccs/bin/make and not GNU make.
# Use the “which make” command to find out which you’re [more stuff not shown]
Blue means I typed this in
Black is the shell/OS response
% make
g++ -c –g -pedantic Card.cc
g++ -c –g -pedantic CardPile.cc
g++ -c –g -pedantic Deck.cc
g++ -c –g -pedantic Trick.cc
g++ -c –g -pedantic Player.cc
g++ -c –g -pedantic SmartPlayer.cc
g++ -c –g -pedantic RandomPlayer.cc
g++ -c –g pedantic main.cc
g++ -g –pedantic -o hearts Card.o CardPile.o Deck.o Trick.o Player.o
SmartPlayer.o RandomPlayer.o main.o
% ./hearts
Here are the hands of each player for hand number 1
Abe has these cards:
Seven of Diamonds
Queen of Spades
Queen of Hearts
End
CS246