Title: Computer Science 1 Cheryl Dugas, PhD cadcs'rit'edu Unix Survival
1Computer Science 1Cheryl Dugas, PhD
cad_at_cs.rit.eduUnix Survival
- Haiku of the day
- Powerful Unix
- ls, cd, lpr
- Why are you so terse?!
2ESSENTIAL UNIX COMMANDS
- pwd print working directory
- ls list contents of a directory
- cd change directory
- mkdir make directory
- rmdir remove directory
- touch create a 0 length file
- cp copy file from one location to another
- rm remove file
- mv move file from one location to another
- cat concatenate files and print to standard
output - quota show disk quota
- lpr submit print request
- logout exit from a login session
- man manual pages
3man - MANUAL PAGES
- man - manual pages
- To find help on the usage of any UNIX command,
use man - man lpr
- SunOS/BSD Compatibility Package Commands
lpr(1B) - NAME
- lpr - submit print requests
- SYNOPSIS
- /usr/ucb/lpr -P destination - number
-C class -J job -T title -i
indent -1 -2 -3 -4 font-w cols -m
-h -s -filter_option file... -
- Hit space bar for next screenfull of info
- To exit man
- c-c (ctrl c)
4DIRECTORIES AND FILES, pwd
cad0000
- directory - like a folder for PC or Mac
Classlist
labs
Notes
lab1
Week1
Schedule
/
root directory
- pwd print working directory
- logged in as user cad0000
- pwd
- /home/stu15/s10/cad0000
home
stu15
s10
my home directory
cad0000
5ls COMMAND - list contents of directory
- ls
- Classlist Notes labs
- ls -F
- Classlist Notes/ labs/
- ls -a
- . .. Classlist Notes labs
- ls -l
- total 2
- -rw------- 1 cad0000 ugrad 0 Aug 27 1038
Classlist - drwx------ 3 cad0000 ugrad 512 Aug 27 1039
Notes - drwx------ 2 cad0000 ugrad 512 Aug 27 1038 labs
- ls -alF
- total 4
- drwx------ 4 cad0000 ugrad 512 Aug 27 1038 ./
- drwx-----x 23 cad0000 ugrad 1024 Aug 27 1038
../
6MORE ON ls COMMAND
ls Notes Schedule Week1 ls -F
Notes Schedule Week1/
- ls -alF
- total 4
- drwx------ 4 cad0000 ugrad 512 Aug 27
1038 ./ - drwx-----x 23 cad0000 ugrad 1024 Aug 27
1038 ../ - -rw------- 1 cad0000 ugrad 0 Aug
27 1038 Classlist - drwx------ 3 cad0000 ugrad 512 Aug 27
1039 Notes/ - drwx------ 2 cad0000 ugrad 512 Aug 27
1038 labs/
permissions
owner
group
size
mod date
filename
file type
7CHANGE DIRECTORY cd COMMAND
cd return to home directory cd Notes Change
working directory to Notes cd .. Change
working directory to parent(go up one level)
8More on CHANGE DIRECTORY cd COMMAND
- cd change directory
- Absolute paths
- cd /
- cd /home
- cd /home/stu4/
- cd /home/stu4/s3/chr000
- cd
- cd
- Relative paths
- cd ..
- cd ../..
- cd stu4/../../home
- cd .
- cd /..
/
home
stu4
s3
chr000
9WORKING WITH DIRECTORIES - mkdir and rmdir
To create the first level mkdir dir1 mkdir
dir2 mkdir dir5 To create a lower level mkdir
dir1/dir2 Or cd dir5 mkdir dir6
rmdir removes a directory For example rmdir
dir2 removes dir2 rmdir dir5 will
fail unless all under it (dir6) is removed
first
10Setting Up Your CS1 Directories
- In class activity
- Create the following directory structure for use
this quarter
HOME
cs1
labs
proj
lec
01
02
10
01
02
10
11CREATING FILES WITH touch
- touch - create a 0 length file (or update mod
time) - cd
- touch README
- ls l README
- -rw------- 1 chr000 ugrad 0 Aug 31 0957 README
- touch README ls l README
- -rw------- 1 chr000 ugrad 0 Aug 31 0958 README
- (just changed mod date/time)
- touch dir1/foo
- ls l dir1
- -rw------- 1 chr000 ugrad 0 Aug 31 0959 foo
chr000
dir1
README
foo
12COPYING FILES WITH cp
- cp - copy file from one location to another
- Show the resulting file system structure after
performing the following operations (note -r
means recursive) - cd
- cp README README1
- cp README1 dir1
- cp README1 dir1/README2
- cp dir1/README2 .
- cd dir1
- cp foo ..
- cd ..
- cp r dir1 dir2
chr000
dir1
README
foo
13REMOVING FILES WITH rm
- rm - remove file
- rm README1
- rm /README2
- rm foo
- rm dir1/README1
- rm dir2/
- rmdir dir2
- To force remove a nested directory structure and
all its files and subfolders, use the flags -fr - mkdir p dir3/dir4/dir5
- touch dir3/foo touch dir3/dir4/foo touch
dir3/dir4/dir5/foo - rm fr dir3
14MOVING FILES WITH mv
- mv - move file from one location to another
- What is the result for each operation?
- cd
- mv README dir1
- mv dir1/README ..
- mv dir1/foo .
- mv foo README
- touch dir1/foo1 touch dir1/foo2
- mv dir1 dir2
- mv dir2/ ..
chr000
dir1
README
foo
15CONCATENATE/OUTPUT FILES WITH cat
- cat - concatenate files and print to standard
output - rm foo remove any foo files
- cat -gt foo1 create foo1 and accept intput
- this is foo1 type any number of lines
- D D is end-of-input
- cat foo1 cat will print to standard output
(screen) - this is foo1
- cat -gt foo2
- this is foo2
- D create and check foo2
- cat foo2
- this is foo2
-
16USING gt and gtgt WITH cat
cat foo1 foo2 gt foo3 creates foo3 from foo1 and
foo2 cat foo3 this is foo1 this is foo2
cat foo1 gtgt foo3 appends foo1 to foo3 cat
foo3 this is foo1 this is foo2 this is foo1
cat foo1 gt foo3 replaces contents of foo3 with
foo1 cat foo3 this is foo1 (Be careful how
you use these!)
17SHOW DISK QUOTA WITH quota
- quota - show disk quota
- If you exceed your disk quota, you will not be
able to log in after a warning period - quota v
- Disk quotas for chr000 (uid 4384)
- Filesystem usage quota limit timeleft
files - /home/stu4 5791 40960 40960
253 - /usr/sbin/mkfile 35170k foo
- Error encountered when closing foo Disc quota
exceeded - Use findhog to show your 20 largest files
- findhog
18SUBMIT A PRINT REQUEST WITH lpr
- lpr - submit print request
- lpr Pprinter_name files
- lpr Pcsl_lw1 .java
- When omitting P, the environment variable
PRINTER is used - env grep PRINTER
- PRINTER csl_lw1
- So
- lpr StopWatch.java
- Prints to csl_lw1
19FILE PERMISSIONS
- The three important file permissions
- r read
- w write
- x executable
- Directories must be executable in order to cd
into them - The four access groups
- u user who owns it
- g other users in files group
- o other users not in files group
- a all users
- -rw------- 1 chr000 ugrad 0 Aug 31 0959 foo
-
a
o
u
g
20CHANGING FILE PERMISSIONS WITH chmod
- Use chmod to alter file permissions
- chmod ar foo ls -l foo
- -rw-r--r-- 1 sps fac 0 Aug 31 1257 foo
- chmod o-r foo ls -l foo
- -rw-r----- 1 sps fac 0 Aug 31 1257
foo - chmod ux foo ls -l foo
- -rwxr----- 1 sps fac 0 Aug 31 1257
foo - In class activity
- What are the file permissions on your home
directory? - What are the file permissions on your
/public_html directory? - Create a file in your home directory with some
data and the following permissions -rw-r--r-- - Make sure a classmate can successfully read it,
but not delete it
21TEXT EDITORS
- There are several editors available for use on
our systems - vi / vim / gvim
- http//www.vim.org/
- emacs
- http//www.emacs.org
- nedit
- http//www.nedit.org/
- pico a simple UNIX text editor
- Emacs tutorial
- http//www.lib.uchicago.edu/keith/tcl-course/emacs
-tutorial.html
22USING EMACS
- To launch emacs
- emacs filename
- Or
- emacs
- Then select filename
- Save the edit buffer to a file using
- File-gtSave (current buffer) (C-x C-s)
- File-gtSave Buffer As (C-x C-w)
- The Edit menu is used to manipulate text
selections - Edit-gtUndo
- Edit-gtCut (C-w)
- Edit-gtCopy (M-w)
- Edit-gtPaste (C-y)
23USING EMACS
- To switch between multiple opened files, select
using the Buffers menu - To open a file
- File-gtOpen File (C-x C-f)
- To get a directory listing
- File-gtOpen Directory (C-x d)
- To quit emacs
- File-gtExit Emacs (C-x C-c)
24BROWSER
- To launch a web browser from UNIX
- mozilla the opens
it in a new window - In class activity
- Find the CS Department home page
- Find the CS Department FAQ
- Find the instructors home page and bookmark this
sections homepage - Find the home page for this course and set it as
your homepage - Navigate to your CS home page
- Put your name into /public_html/index.html
- Verify you can see the changes in your browser
(use Reload button)