UE CS 215 - CS 215 – Fundamentals of Programming I

Unformatted text preview:

CS 215 – Fundamentals of Programming IIFall 2007 (Harlaxton) – Very Basic UNIXThis handout very briefly describes how to use Unix and how to use the Harlaxton Linux server. For more information, ask the instructor, look at the links on the CS 215 course page, or buy a book (Just Enough UNIX by Anderson and Unix for Dummies are fairly good ones). Basic UNIX functionality UNIX is a command-line oriented operating system. This means that you interact with a computer through a interactive shell and programs are run by typing commands and their arguments at the shell prompt. (It is similar to DOS in this way.) The basic syntax of running any program is: command options arg1 arg2 arg3 ...where command is the name of the program and the options and arguments are whatever else it needs to run. Options are things that change the way a program behaves. Arguments are things that the program will operate on, typically file and directory (folder) names. Note that UNIX is case-sensitive. Conventionally, most UNIX commands and file/directory names are in all lower case. The UNIX file system is hierarchical. The root directory/folder of the file system is called / ("slash"). Under the root are various subdirectories. Each user has a home directory under /home, e.g. /home/hwang. When you log in, you are put into your home directory where only you have access to read and write files initially. The default shell on the Harlaxton Linux server is bash. This shell supports, among other things, using the up and down arrow keys to access previously typed commands, line editing using emacs style commands, and command completion using the TAB key. (The shell can be changed using the command chsh, if another is preferred.) Files and directories are named using either absolute or relative pathnames. An absolute pathname starts with /, the root directory. A relative pathname is relative to the current directory and can start with a subdirectory name, .. (parent directory), . (current directory) or ~ (home directory). Most commands will also take wild cards in pathnames. The most common ones used are: * (match 0 or more of any character) and ? (match exactly one character). For example, project1.* will match all files starting with project1. and having any extension (e.g., project1.cpp, project1.o, etc.). Likewise, project?.cpp will match any .cpp file that has the name project and one character (e.g., project1.cpp, project2.cpp, etc.). Basic UNIX commands Here is a very brief list of the most commonly used UNIX commands (more or less in the order presented in class) with the most commonly used options and arguments that you will need to know to get started. passwd Change password. The program will ask you for your current password, a new password, and then your new password again to confirm. mkdir subdir1 subdir2 ... Create subdirectories in the current directory. ls options directory List a directory. Default is in alphabetical order ignoring hidden files (those starting with a dot). Options include -l (long listing format showing permission modes and sizes), -a (including hidden dot files), -d (directory only). Options can be combined, e.g., ls -la will list all files, including hidden files, in long format. 08/26/07 1 of 3chmod newmode name1 name2 ... Change permission mode. Permissions to access files and directories are granted in three groups (owner, group, world) of three rights (read, write, execute). These permissions can be represented as a 3-digit octal (base 8) number where each right granted is a bit set in the number. E.g., 777 would be all rights to all users, whereas 754 would be all access for the owner, read and execute access for the group, and read-only access for everyone else. By default, your home directory is open for all access to you and closed to all others (i.e., mode 700). All other directories and files are created with all access to you and read-only access for everyone (i.e., mode 755 or 644 for directories and files, respectively), so you might want to change the permission mode of your course directories to 700. man command Show the manual page for command. Most command have man pages. For example, if you wanted to know what other options there are for the ls command, you could type: man ls. cd directory Change to directory. If run without an argument, it changes to the user's home directory. (I.e., equivalent to cd ~) emacs filename or vi filename Text editors. The majority of programmers use one of these text editors for creating program source files. Both have vociferous adherents who intensely dislike the other editor. Choose one and learn it well. The two things that everyone needs to know about each is how to save files (Ctrl-x Ctrl-s in emacs, :w<Enter> in vi) and how to quit the editor (Ctrl-x Ctrl-c in emacs, :q<Enter> in vi). Both editors have built-in tutorials (Ctrl-h t from within emacs, vimtutor on the command line for vi). Links to several on-line tutorials and reference cards are available for each on the course webpage. cp name1 name2 or cp namelist directory Copy a file or directory. The first version copies one item and possibly renames the copy. The second version all items in namelist are copied into directory with the same names. A common idiom is to copy all items into the current directory which can be indicated by using '.' (dot). For example, cp /home/hwang/cs215/examples/*.* . will copy all the files in /home/hwang/cs215/examples to the current directory. more filename Display file to screen a page at a time. Typing space will advance to the next page, typing 'b' will go back to previous page, typing 'q' quits the program. g++ options filenames GNU C++ compiler. See separate submission handout regarding use of the compiler. mv name1 name2 or mv namelist directory Move a file or directory. The first version moves one item and can be used to rename it. In the second version, namelist is a list of items to be moved to directory. make options target Generate target from a makefile. See separate handout regarding use of make. touch file1 file2 08/26/07 2 of 3Changes the last modified date of a file. Useful for forcing make to recreate a target by touching a source file. rm file1 file2 Delete files. Can also be used with -rf options to delete non-empty directories. (The rmdir command will delete empty directories only.) tar options filenames An archive facility that combines multiple files into


View Full Document

UE CS 215 - CS 215 – Fundamentals of Programming I

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download CS 215 – Fundamentals of Programming I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 215 – Fundamentals of Programming I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 215 – Fundamentals of Programming I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?