Intro to UNIX CIS 118 Oakton Community College Beginnings
Getting Started with Unix • Unix and Linux – Unix Linux, – BSD, Mac OS X • Introduction to Shells – An Overview of Shells – Adjusting to Shells – Bash and Tcsh – Logging In • Using the Command Line – Basic Commands – Managing Files – Other Commands • File Systems – File Systems – Files – Working Directory • More on Shells – Running a Program – Manuals and Options – Useful Shell Tips Summary
History of UNIX • Unix was designed by Ken Thompson and Dennis Ritchie in the ’60 -70s at Bell Labs • It is a multi-user operating system that allows several people to use the computer at once • Since then many Unix-compatible OSes have been written • In the past Unix-like OSes predominantly used for servers • There are now several Unix versions in everyday desktop use • Linux and Mac OS X are the most common • Popular in Universities and research institutions • Most Unix versions are available for free in some way • They are also open-source
The UNIX operating system • The UNIX operating system is made up of three parts; the kernel, the shell and programs. • The kernel The kernel of UNIX is the the operating system: it runs the hardware it allocates cpu time and memory to programs and handles the filestore and communications in response to system calls. • The shell The shell is the user interface to the operating systems. Shell commands are used to manipulate files or processes as resources provided by the kernel. • Programs Programs can take the form of English like text commands or compiled binary programs such as the “C” programming
Shells • User command line interface into the OS. • Require memorization of basic commands ls,cd,mv,rm,man,info,find,gcc • The two most common shells are: – BASH: Bourne Again SHell – TCSH: Tenex C SHell • There are many more - zsh,ksh,perl,python,awk • Microsoft shells – command.exe, cmd.exe, Powershell • Still used for greater speed and functionality (versus GUIs)
The Shell • The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt ($ on our systems). • The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have the bash shell by default. • Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again. • History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.
Logging in • You use a shell by opening a terminal program to a computer • In a networked environment computers are named • You log in to a machine in 3 ways - sitting in front of diretly connected keyboard and monitor or telnet/ssh to the computer’s name. Alternative you can use a GUI. • What’s your computer’s name? Run the command uname -a • To log in, point putty to csc.oakton.edu • See who’s logged in to your machine run the command: who
Files and processes • Everything in UNIX is either a file or a process. • A process is an executing program identified by a unique PID (process identifier) shown by the command ps . • A file is a collection of data. They are created by users using text editors, running compilers etc. These are listed with the ls command. • There are several type of files: – Proprietary binary format files (reports databases etc etc.) – Text files, such as a program written in some high-level programming language – Binary instruction files – executables programs from a compiled language. a collection of binary digits (an executable or binary file). – System files such as a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files. Also files that represent hardware to the OS (device files).
File Management • list the files in a directory – ls • create a simple file – $ echo this is a simple file > simple • copy a file – cp simple simple.copy • delete a file – rm simple.copy • Display contents of a text file – cat simple • simple tab completion – type cat sim and hitting the tab key • list the file – $ ls simple • list again (with more information) – $ ls -l simple
Directory Management • A directory is a logical “container” of files – aka a “folder” used to organize data files on disk. It actually does not physically contain files. But the container concept is usefull for GUI’s. • • create a directory – $ mkdir simple • Make a backup directory – $ mkdir backups • move our copy in to the new directory – $ mv simple.copy backups • list again (with more information) – $ ls – l backups • move into directory – $ cd backups • list – $ ls -l • move back to the original directory – $ cd .. (.. move to one directory above)
UNIX Commands • There are hundreds of UNIX commands. • There are also lots of options for every command usually following the command with a dash. Such as “ls –l”. These modify the default action of the command. • LINUX in a Nutshell is a great reference. ind • Note there are also “DOS compatibility” commands in LINUX • Used prior to GUI, more powerful than most desktop commands • Can find equivalent commands using apropos
Manual Pages • Some programs have hundreds of options They are used to give a program flexibility and different behaviours • Check out the options for ls (or any program) by looking in its manual type man and the program name to see that program’s manual try – man ls try – man cat – man yes – man man – man apropos
Filesystem • A formatted area on disk • There are many types of filesystems in all type OSes • All modern file systems are hierarchical • Folders contain files and more folders starting at the top or root of the file system • In Windows, it’s the drive name C: (but you can have several drives) • In Unix, the / directory (called ’root’) is top • Your home directory is not at the root, it is several directories below • File systems organize data on hard disks
File names • Every file has a name and may or may not have an extension. • • Some common extensions – compute.c - a C source file – compute.o - an object code file – assn1.tar.gz - an compressed archive file – report.pdf - a PDF file • Unlike Windows, extensions are not always necessary in Unix (the OS at least), but can be helpful to know what a file is used for. Also some UNIX utilities make use of file extensions
Using wildcards • What if you want to list or remove all the files in a directory You can use the wild card character * • * will match any string characters – ls t* - list all file that begin with a ’t’ try – rm a*c - remove all files that begin with ’a’ and end in ’c’ – What files will ls c*.*t list? • rm * - this will remove all files in the current directory. BE CAREFUL when removing files! - there’s no recycle bin in • The wild card will work with any command line program referencing a filename
Current Working Directory • With a command line, you are always working in a particular directory called the current (present) working directory • To see what it is, run the command: pwd • cd; mkdir tmp • ls tmp - list the contents of tmp under the working directory (relative path) • ls /tmp - lists the contents of tmp under the root directory (fully qualified path) • a single dot (.) refers to the current directory – ls . • a double dot (..) refers to the directory up the hierarchy – ls ..
Managing Directories • All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called "root". • You can make as many directories as you like mkdir is the command to make a directory • rmdir is the command to delete a directory • the directory must be empty before it can be removed unless you use rm – rf ./directory • ls lists the contents of a directory – by default, it lists the working directory – ls and ls . do the same thing • Or you can provide a directory name • ls simple • ls mydir • ls ..
Running Programs • A shell is used to run programs and perform tasks. BASH uses a dollar sign ($) as the prompt • Typically your prompt will look like this [rjtaylor@csc ]$ • To run a program, you type its name and any arguments that go with it: command – flags command-line-parameters . • The first word on a line is the program, everything after is an option or an argument examples – $ ls -l .. – $ gcc compute.c – $ grep -i int compute.c
Recommend
More recommend