Introduction to Unix
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Unix Editing with emacs Compiling with gcc What is Unix? q UNIX is an operating system first developed in the 1960s - by operating system, we mean the suite of programs that make the computer work q There are many different versions of UNIX, although they share common similarities - the most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X q The UNIX operating system is made up of three parts: - the kernel, the shell and the programs Files and Processes q Everything in UNIX is either a file or a process: - A process is an executing program identified by a unique process identifier - a file is a collection of data created by users using text editors, running compilers, etc. q All the files are grouped together in the directory structure - The file-system is arranged in a hierarchical structure, like an inverted tree Tree Directory Structure root directory home directory current directory Concepts q Root directory q Current directory q Home directory q Parent directory q Absolute path q Relative path Tree Directory Structure Unix command: root ls directory Output: Sub a b c Unix command: home ls /home/jane/data directory current Output: directory Sub a b c Unix command: ls ~/data Output: Sub a b c Tree Directory Structure Unix command: root ls ~ directory Output: data setup Unix command: home ls .. directory Output: current directory data setup Unix command: ls ./../.. Output: jim jane Unix command: ls ./../../jim Output: calendar Tree Directory Structure Unix commands: root cd ./../../../work directory current ls directory Output: setups bkup home Unix command: directory ls ./.. Output: home work Unix command: ls / Output: home work Unix command: ls /home Output: jim jane Tree Directory Structure Unix commands: root ls ~/.. directory current Output: directory jim jane Unix command: home ls ~/../.. directory Output: home work Unix command: ls setups Output: generic Unix file security q Each file has owner and group q Permissions set by owner - Read, write, execute - Owner, group, other q Only owner, root can change permissions - This privilege cannot be delegated or shared A Sample UNIX Directory Listing Changing Access Rights q Use the command chmod For example, to remove read write and execute permissions on the file biglist for the group and others, type chmod go-rwx biglist This will leave the owner’s permissions unaffected. To give read and write permissions on the file biglist to all, chmod o+rw biglist Basic Unix Commands (1) ls list files and directories ls -a list all files and directories cd name change to named directory cd change to home directory cd ~ change to home directory cd .. change to parent directory mkdir name make a directory pwd display current directory path Tree Directory Structure Unix command: root directory mkdir ./bkup/zzz current directory Unix command: pwd Output: home /work directory zzz Basic Unix Commands (2) cp file1 file2 make a copy of file1 into file2 cp -r dir1 dir2 make a copy of directory dir1 into dir2 mv file1 file2 move or rename file1 to file2 rm file remove a file rm –r directory remove a directory cat file display a file less file display a file a page at a time who list users currently logged in * match any number of characters ? match one character man read online manual for a command Unix command: cp ~/data/a . root directory current directory home a directory zzz Unix command: cp –r /home/jim/calendar ./bkup/zzz root directory current directory home a directory zzz Unix command: cp –r /home/jim/calendar/* ./bkup/zzz root directory current directory home a directory zzz Unix command: rm –r /home/jim/calendar/* root directory current directory home a directory zzz Unix command: rm –r /home/jim/calendar/* root directory current directory home a directory zzz Unix command: mv ./bkup/zzz ./bkup/www root directory current directory home a directory zzz www Basic Unix Commands (3) command > file redirect standard output to a file command >> file append standard output to a file command < file redirect standard input from a file grep keyword file search a file for keywords wc file count number of words in file sort sort data (numerically or alphabetically Text editor EMACS Text Editor emacs q Configurable, extensible text editor q To start emacs just “call it” emacs q Basic editing in emacs is somewhat intuitive - use arrows, “PG UP”and “PG DOWN”to move cursor - use DEL key to delete - typing inserts text at the cursor position q To edit an existing file type emacs filename Using emacs: keyboard commands q We use the following abreviations “C” is the “Control” key “-” between two letters mean both have to be pressed simultaneously q Basic commands C-x, C-s to save the file C-x, C-c to exit Emacs C-g to get out of trouble Basic emacs Commands q Cursor movement q Copy - C-a (begin of line) C-c - C-e (end of line) q Paste C-v - C-v (page up) q Undo - alt-v (page down) C-x u q Delete q Save/Quit C-k (delete line) - C-x C-c (quit w/out saving) q Cancel - C-x C-s (save) - C-x C-w (write to a new file) C-g q Load file - C-x C-f (delete line) Searching in Emacs q C-s : search for a string – this search is incremental and goes as you search – typing C-s again will search for the next occurrence of the same string – to go back to the editing, just press any arrow key – after you go back, typing C-s twice resumes the search GCC Compiler What is gcc? q Stands for GNU C/C++ Compiler q Popular console-based compiler for Unix platforms q Compile and link C programs: gcc filename.c output is an executable called a.out q Another option (we will be using this one): gcc filename.c –o xfilename output is an executable called xfilename q If you want to learn more, use the manual man gcc.