160 likes | 256 Views
Introduction to UNIX. Dana Schaa. Brief History of UNIX. Developed at Bell Labs by Thompson, Kernighan, Ritchie and others Designed to be a multi-task, multi-user system Designed to be modular EVERYTHING is a file in UNIX accessed using read, write, execute operations. UNIX File Structure.
E N D
Introduction to UNIX Dana Schaa
Brief History of UNIX • Developed at Bell Labs by Thompson, Kernighan, Ritchie and others • Designed to be a multi-task, multi-user system • Designed to be modular • EVERYTHING is a file in UNIX • accessed using read, write, execute operations
UNIX File Structure • Files treated as a hierarchy • Absolute paths begin at root (/) and access the same location regardless of current directory • Relative paths begin in the current directory
File Permissions • All files are owned by someone • Permissions are represented by 9 bits • 3 octal numbers • allow user (u), group (g), and others (o) to read (r), write (w), and execute (x)
File Permissions (2) • Permissions required to perform certain operations in a directory • Read: list files in the directory • Write: create, rename, or delete files in the dir • Execute: read a file, write to a file, execute a file or script
File Permissions (3) • Example: • >> chmod 0755 file.txt • 755 111 101 101 rwxr-xr-x • Can also modify 1 permission at a time • chmod +r file <-- allow everyone to read file • chmod u+x file <-- allows user to execute file • chmod go-w file <-- don't allow group or others to write to file
Hidden Files! • Any file or directory that begins with a dot is “hidden” • Hidden files are those that don’t show up when a directory is read (using ls) • Hidden files must be asked for explicitly via “ls –a” • Configuration files are usually hidden because there are typically many of them in your home directory that you don’t need to access often
Current and Parent Directories • Every directory contains at least two files: • Current ‘.’ • Parent ‘..’ • Examples: • >> cd . # remains in the same directory • >> cd .. # go up a level (unless in root dir) • The dot (.) is allowed in naming files and directories • a leading dot makes the file hidden
Shells • A shell provides an interface to the UNIX kernel • “shell” is interchangeable with “command line” • Gnome and KDE are examples of graphical shells • The main purpose of the shell is abstraction • Example: • >> ls -l | sort > out • The shell handles • the parsing of your input • the fork/exec calls • the inter-process communication • the file redirection
Shells (3) • Some popular shells • sh: bourne shell (used by root during boot) • bash: bourne again shell • csh: C shell • tcsh: enhanced csh • zsh: Z shell • All have slight variations but are similar • Variations include: • Command completion • History • Etc
SSH – secure shell • Provides secure connections to remote machines • Encrypts passwords and data sent over internet >> ssh dschaa@ece.neu.edu >> ssh -X dschaa@ece.neu.edu <-- allows GUIs to be tunnelled through SSH • SFTP and SCP are equivalently used for file transfers • Use ‘man’ for more details
man – man’s best friend • Extremely useful tool • man is an interface to reference manuals for UNIX commands and C system calls • Commands: • describes functionality • explains parameters • provides usage examples • System Calls: • lists required header files, • explains parameters, return value(s), and error values, • describes functionality, • provides usage examples
UNIX Editors • The goal of every programmer should be that their hands never need to leave the keyboard • Available editors in UNIX: • Pico • A simple editor that is good for beginners • Don’t need to rely on your memory as much to use effectively • VI • Standard UNIX editor • VIM (vi-improved) • vi with more bells and whistles • EMACS • Endlessly customizable. Many bells and whistles • See “Editor war” in wikipedia for more details
UNIX Editors (2) – VI vs EMACS • VI • is present in all Unix based operating systems as guaranteed by the POSIX standard • conforms with Unix design and philosophy, "do one thing, and do it well" • commands largely avoid the use of modifier keys such as Ctrl & Alt • EMACS • has a much larger set of built-in commands • can be used as a shell itself • available in GUI form • has a large number of customizations and other enhancements available