Unix Basics
Unix Basics
1
Logging In
• Which server you use (almost) doesn’t matter – all four
allows access to your files
• Although your Windows and Unix usernames (and
passwords) are the same, they are two separate
accounts
– Your z: drive is not your Unix account
• Connecting:
– We’ll connect to the Unix machines via ssh
– After connection, you are presented with a login prompt
– After logging in, you’re placed in your home directory
(where your personal files are located)
2
Two Basic Commands
• The most useful commands you’ll ever learn:
– man (short for “manual”)
– info
• They help you find information about other commands
– man <cmd> or info <cmd> retrieves detailed information
about <cmd>
– man –k <keyword> searches the man page summaries
(faster, and will probably give better results)
– man –K <keyword> searches the full text of the man pages
Directories
• In Unix, files are grouped together in other files called
directories, which are analogous to folders in Windows
• Directory paths are separated by a forward slash: /
– Example: /u10/hctang/classes/cse326
• The hierarchical structure of directories (the directory
tree) begins at a special directory called the root, or /
– Absolute paths start at /
• Example: /u10/hctang/classes/cse326
– Relative paths start in the current directory
• Example: classes/cse326 (if you’re currently in /u10/hctang)
• Your home directory is where your personal files are
located, and where you start when you log in.
– Example: /u10/hctang
3
Directories (cont’d)
• Handy directories to know
~ Your home directory
.. The parent directory
. The current directory
• ls
– LiSts the contents of a specified files or directories
(or the current directory if no files are specified)
– Syntax: ls [<file> … ]
– Example: ls backups
• pwd
– Print Working Directory
4
Files
• In Unix, unlike Windows,, file types (e.g. “executable
files, ” “data files,” “text files”) are not determined by
file extension (e.g. “foo.exe”, “foo.dat”, “foo.txt”)
• Thus, the file-manipulation commands are few and
simple …
• rm
– ReMoves a file, without a possibility of “undelete!”
– Syntax: rm <file(s)>
– Example: rm tutorial.txt backups/old.txt
Files (cont’d)
• cp
– CoPies a file, preserving the original
– Syntax: cp <sources> <destination>
– Example: cp tutorial.txt tutorial.txt.bak
• mv
– MoVes or renames a file, destroying the original
– Syntax: mv <sources> <destination>
– Examples:
• mv tutorial.txt tutorial.txt.bak
• mv tutorial.txt tutorial-slides.ppt backups/
5
Shell Shortcuts
• Tab completion
– Type part of a file/directory name, hit <tab>, and the shell will finish as
much of the name as it can
– Works if you’re running tcsh or bash
• Command history
– Don’t re-type previous commands – use the up-arrow to access them
• Wildcards
– Special character(s) which can be expanded to match other file/directory
names
* Zero or more characters
? Zero or one character
– Examples:
• ls *.txt
• rm may-?-notes.txt
Editing Text
• Which text editor is “the best” is a holy war. Pick one and
get comfortable with it.
• Three text editors you should be aware of:
– pico – Comes with pine (Dante’s email program)
– emacs/xemacs – A heavily-featured editor commonly
used in programming
– vim/vi – A lighter editor, also used in programming
6
Printing
• Printing:
– Use lpr to print
• Use –h (no header) and –Zduplex (double-sided) to save paper
– Check the print queue (including Windows print jobs!) with lpq
– lprm to remove print jobs (including Windows print jobs)
– For the above commands, you’ll need to specify the printer with
–P<printer name>
• Check out enscript (quizlet: how do you find information about
commands?) to print text files nicely!
– WARNING: Do NOT use enscript with postscript files!