120 likes | 282 Views
SEEM3460 Tutorial. Unix Introduction. Introduction. What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software Ever Written!! http://www.informationweek.com/shared/printableArticle.jhtml?articleID=191901844
E N D
SEEM3460 Tutorial Unix Introduction
Introduction • What is Unix? • An operation system (OS), similar to Windows, MacOS X • Why learn Unix? • Greatest Software Ever Written!!http://www.informationweek.com/shared/printableArticle.jhtml?articleID=191901844 • Freely available clone/distributions are under rapid development (e.g. Linux & FreeBSD)
Using Unix • Shell: a program that acts as a middleman between you and the UNIX OS • Terms similar to shell: • Terminal / virtual terminal • Console • A shell allows users to • Run programs • Manage I/O of processes easily • A Unix shell interprets a programming language (sometimes called the shell script)
A shell command • ls -lp ~ • ls: program name • “ls” is the utility to list files • -lp: options/switches, starting with a hyphen • “l” means list in long format • “p” means putting a slash after directory names • ~: remaining parameters • actual meaning depends on the program used • for ls, the remaining parameters are the files or directories to be listed • “~” means the home directory of the current user
Utilities • Unix utilities are the basic programs supporting the user to control the system • Examples: • date: shows the system date • man -s 1 ls: shows help on ls from the built-in manual section 1 • pwd: prints the working directory • echo: prints a message
Unix file system in brief • A hierarchy of directories • To locate a file in the system, a pathname is needed • Command: pwd • print your current working directory • Pathnames • Absolute pathnames • Starting from the root (with a beginning “/”) • Relative pathnames • Starting from the current working directory
Managing Files on Unix (1) • Creating an empty file • touch <newFileName> • Creating (making) a directory • mkdir <newDirName> • Moving (renaming) a file • mv <aFileName> <aDirectoryName> • mv <oldFileName> <newFileName>
Managing Files on Unix (2) • Change working directory • cd <aDirName> • List files in a directory or fits the pattern • ls <directories/filename patterns> • View the content of a file • cat <file paths> • more <file paths> • less <file paths> • head <file path> • tail <file path>
Managing Files on Unix (3) • Copying a file • cp <oldFileName> <newFileName> • Remove a file • rm <aFileName> • Remove a non-empty directory • rm –r <aDirName> • Remove a whole directory without prompt • rm –rf <aDirName>
Editing a file • nano • Adv: simple, easy to learn and use • Dis: no GUI • emacs • Adv: has GUI, easy for beginners • Dis: relatively slow • vi/vim (vim stands for Vi Improved) • Adv: fast for advance users • Dis: text-version is quite difficult to learn • GUI version: gvim, rgvim • To learn, type “vitutor” in console Check their “man” page for detail usages
Compiling C programs in Unix • Compiler: • cc – the native C compiler under Unix • gcc – C compiler under GNU project • Usage is the same, gcc is more popular • To compile a C source code file, say example.c, type in: • cc example.c • gcc example.c • The output of both compilers (i.e. the executable) would be “a.out” by default • To override the default executable name, use “-o” flag • cc example.c –o example • gcc example.c –o example • You can name the executable as .exe or .bin file to remind yourself the nature of the file • One more tip, use “-Wall” to get some warning messages • Warning message usually indicate hidden bugs • Try to understand the error messages and warning messages. • For other flags, “man cc” or “man gcc”
Compiling C programs in Unix • If there are so many compilation errors that it cannot fit into one screen. One way is to compile by the following command: • cc example.c |& more • It means that the compilation errors will be displayed screen by screen. • That is, it will display the first screen of errors and wait. • After the user examines the errors, he/she can choose to display the next screen of errors by hitting RETURN or quit by hitting Control-C. Then, the user can go back to modify the source code.