470 likes | 713 Views
CSI 135. Big Review. Why Review?. Some students in this class are still struggling with basic issues and with understanding the context in which we are working So we need to review what we’ve done so far in class and how it all fits together. Basic Unix Commands. $ ls $ pwd $ cd
E N D
CSI 135 Big Review
Why Review? • Some students in this class are still struggling with basic issues and with understanding the context in which we are working • So we need to review what we’ve done so far in class and how it all fits together
Basic Unix Commands $ ls $ pwd $ cd $ touch $ mkdir $ rmdir $ rm $ who $ cp $ mv $ date $ cal $ echo $ history $ env $ sort
Basic Unix Commands $ ls $ pwd $ cd $ touch $ mkdir $ rmdir $ rm $ who List files Show current directory Change directory Create file or update timestamp Make directory Remove directory (if emtpy) Remove Show who is logged in
Basic Unix Commands $ cp $ mv $ date $ cal $ echo $ history $ env $ sort Copy Move (or rename) Show date & time Show calendar Repeat typed text Show previous commands Show user environment Sort lines of characters
Basic Unix Commands $ cat $ more $ head $ tail $ wc $ ps Display contents of a file Show file screen at a time Show top of file Show bottom of file Count characters, words and lines Show the running processes
Basic Unix Commands $ ls –l -rw------- 1 shsstaff 8876 May 30 2008 my.txt drwx------ 2 shsstaff 512 Mar 13 2006 mydir
Basic Unix Commands $ ls -l /usr/bin | egrep 'date|who' -r-xr-xr-x 1 root bin 8552 Jan 5 2000 date -r-xr-xr-x 1 root bin 6240 Jan 5 2000 rdate -r-xr-xr-x 1 root bin 6280 Jan 5 2000 rwho -r-xr-xr-x 1 root bin 13088 Apr 3 2001 who
Basic Unix Commands $ ls -ld local lrwxrwxrwx 1 shs staff 14 Nov 3 16:25 local -> /usr/local/bin
Basic Unix Commands $ ls –ld .
Basic Unix Commands $ ls –ld . drwx------ 61 shsstaff 3584 Nov 3 16:25 .
Basic Syntax $ command [options] [arguments] Examples: $ ls–l myfile $ cd/tmp $ cal 10 2011 $ sort –n nums Notice that options are prefaced with hyphens Also, options are optional (thus, their name!)
Getting Help $ man <command> $ apropos <word> Examples: $ man ls $ apropos logout
Regular Expressions ? Stands for a single character in commands such as ls * Stands for zero or more characters Examples: $ ls ? List all one-character filenames $ ls a* List all files that start with “a”
Regular Expressions [abc] stands for any single letter in the list shown (in this case, a, b or c) [a-z] stands for any single lowercase letter [A-Z] stands for any single uppercase letter [a-zA-Z] stands for any single letter
Variables $ myvar=11 $ echo $myvar 11 $ favcolor= ”green” $ echo $favcolor green
Environment • The env command will show you a list of variables used to create your working environment and their values • For example: USER=csi135b11 HOME=/u/students/csi135/b11
Your “dot files” • Files such as the .bashrc_profile and .bashrc files in your home directory on vader are read when you log in and set up your user environment. • Before your dot files are read, however, a system file, /etc/profile, is read first. This file is read by the shell when any user logs in.
Your dot files /etc/profile .bash_profile .bashrc
The Unix Filesystem jdoe etc msmith bin home / local The Unix filesystem has one root (base) called / usr bin var
The Unix Filesystem /home might be a separate file system jdoe etc msmith bin home / local The Unix filesystem may be comprised of multiple file systems mounted into one tree-like structure usr bin var
The Unix Filesystem jdoe etc msmith bin home / local /usr/local/bin usr bin Absolute pathname var
The Unix Filesystem jdoe etc msmith bin home / local /home/msmith usr bin var Absolute pathname
The Unix Filesystem jdoe etc msmith bin home / local local/bin usr bin Relative pathname var
The Unix Filesystem jdoe etc msmith bin home / local ../msmith usr bin var Absolute pathname
More Advanced Commands • grep match content • awk select fields • cut select characters or fields
More Advanced Commands • grepgrep word textfile • awkawk ’{print $2}’ textfile • cut cut –c1-3 textfile
Pipes • Using a | to send the output of one command to be the input of another command $ tail myfile | sort $ head myfile | wc –w $ ls | tail -3
Redirection • Sending the output of commands to files or to the bit bucket $ tail myfile > newfile $ head myfile >> logfile $ cat dumfile 2> /dev/null
Quotes $ echo ”hello, $USER” hello, csi135b11 $ echo ’hello, $USER’ hello, $USER
Backticks • Putting text within backticks makes the shell try to interpret the text as a Unix command and execute it $ echo Today is `date`
Scripts • Putting Unix commands in a file and making the file executable makes it a script $ echo date > showdate $ chmod 755 showdate
Scripts #!/bin/bash echo Hello, $USER echo Today is `date +%A`
Arguments $0 name of script $1 first argument $2 second argument $3 third argument $* list of arguments
More Advanced Scripts • if/then/else statements • for loops • while loops
if/then if test condition then commands fi if [ condition ]; then commands fi
if/then/else if test condition then commands else commands fi
if/then/else if [ condition ]; then commands else commands fi
For loops for number in 1 2 3 do echo $number is a number done
While loops while true do commands sleep 5 done
Case statements case month in Jan) tail -5 jan.log;; Feb) tail -5 feb.log;; *) echo ”No log available for $month”;; esac
File Systems partitions
File Systems partitions data blocks
File Systems partitions data blocks meta-data (owner, permissions, etc.)
File Systems partitions data blocks meta-data (owner, permissions, etc.)
File Systems partitions log kjones msmith jdoe var home /
File systems • The df command displays a list of the file systems on a Unix system, including how full they are and where they are mounted (i.e., attached to the Unix file system tree) • As a Unix user, you might want to know this if you can’t save a file (no space left on device) • As a Unix systems administrator, you would need to clean up the file system so users can work