Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shells, Help, and Paths.

Similar presentations


Presentation on theme: "Shells, Help, and Paths."— Presentation transcript:

1 Shells, Help, and Paths

2 What is a “Shell” A shell is a program used to parse and execute “commands”. Popular Shells: – bash → /bin/bash – csh / tcsh → /bin/tcsh – zsh → /bin/zsh By “default”, all Linux installs usually come with sh, bash, and tcsh.

3 Commands A “command” has two main parts, the command and some number of arguments. When running a command, the shell checks if the command exists. If not, it produces an error. If the command is a “built-in”, it is handled by the shell. – Checked for correctness (command and arguments) If the command is not “built-in”, the shell does NOT check arguments. The shell executes the program and passes the arguments to it.

4 Other shell curiosities
Prompts → left and right prompts, user configurable. Show: – time of day – cwd (current working directory) – username – command history – system information Output redirection & Pipes Can have variables (like programs)

5 More on Shells The shell itself is simply a program.
Everyone can run the shell of their preference. This is set in /etc/passwd You will write your own shell in C/C++ (in CS352) Terminal: a window running a shell (xterm, konsole, gnome-terminal) Virtual Console: Text mode from Xwindows. Runs login + shells.

6 Linux (GNU) Utilities Man Short for manual Gives a “manual page”
Information about specific application Information about configuration file Information about system calls (if applicable) General Usage information

7 Linux (GNU) Utilities Why man? Program semantics:
e.g. to copy files, is it: copy <source> <destination> or copy <destination> <source> More likely, you forget the switches.

8 Linux (GNU) Utilities - switches
YES! Commands have switches Usually of the form “-a” or “-B” or sometimes “--long-switch” Usually can appear in any order cmd -a -b == cmd -b -a Can be case sensative cmd -r != cmd -R

9 Switches Switches can have arguments!
Could be: mycmd -b or mycmd -b= or mycmd --block-size or mycmd –block-size=1024 Switches can be grouped, (sometimes even drop the “-”) Example: tar -c -z -v -f mydirectory.tgz www/ tar -czvf mydirectory.tgz www/ tar czvf mydriectory.tgz www/

10 More on system help man switches info
-s: specify a list of sections to check -a: print all matching pages, not just first found info Like man, but fancier. Different format than man. More like an electronic book than man page

11 More on system help apropos man -k == apropos
Want to know something about floppy drives? pyrite-n2:~> apropos floppy fd (4) - floppy disk device fdformat (8) - Low-level formats a floppy disk floppy (8) - format floppy disks mbadblocks (1) - tests a floppy disk, and marks the bad blocks in the FAT mformat (1) - add an MSDOS filesystem to a low-level formatted floppy disk mkbootdisk (8) - creates a stand-alone boot floppy for the running system man -k == apropos

12 Paths Recall that the UNIX file system is a large tree:

13 Paths, cont. You can ALWAYS reference a file or directory based on the root of the tree. For example, if I want to read the ssh configuration files, I know it is at: /etc/ssh/ssh_config and the server configuration file is at: /etc/ssh/sshd_config A file/directory reference that starts from the root of the filesystem is called an “absolute path”

14 Paths, cont. So, we can access any file based on its location and path from the root of the filesystem. But... Cumbersome (lots of directories?) Makes for VERY long scripts Difficult to move files/folders to sub- folders example: Move file from /home/user/project/myprog.c to /home/user/myotherproject/src/myprog.c

15 Paths, cont. Relative Paths! Working Directory:
So we don't have to use absolute path for everything. Concept of “Working Directory” Working Directory: The directory associated with a process (a running executable) Remember that the shell is simply an executable file invoked by the kernel.

16 Paths, cont. pwd “print working directory”
Will echo your current working directory to the terminal When we know where we are in the directory structure, we can use relative path names. pyrite-n2:~> pwd /home/ssg/bbritt

17 Paths, cont. Relative Paths: Do not start with /
Assumes that all path names are prefixed by `pwd` for example: (assuming /home/user/cs252 is `pwd`) vim hw3/blah.c is the same as vim /home/user/cs252/hw3/blah.c

18 Even more Paths cd Change directory
Will accept both absolute and relative paths example: cd cs252 cd /home/user/cs252

19 Special “Directories”
. Current directory (almost) the same as `pwd` .. “parent” directory ~ “home” directory

20 Special “Directories”, cont.
Examples: cd . Does absolutely nothing cd .. Make parent directory the working directory cd ~ Make home directory the working directory cd ~/cs252 Change directory to /home/user/cs252


Download ppt "Shells, Help, and Paths."

Similar presentations


Ads by Google