790 likes | 812 Views
Introduction to the UNIX Operating System. Lecture Overview. Login and shells The UNIX file system Listing directory contents Getting on-line help Directory and file operations File permissions The history mechanism File name generation and special characters. Logging In.
E N D
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
Logging In • We start by running PuTTY(or any other SSH client) • http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe • Enter the address of the IDC Linux server:linux.idc.ac.il • When a terminal window appears, enter your user-name and password
Logging In – Details • When running putty.exe for the first time,you may get thefollowing message: • Uncheck thecheckbox,and click “Run”
Logging In • First, we createa saved sessionwith all therequired detailsby selecting fromthe categorieson the left panel
Logging In • Click “Connection”and enter thevalue 60 into the“Seconds betweenkeepalives” field
Logging In • Select “Data”and enter youruser name into the“Auto-loginusername” field(optional)
Logging In • Go back to“Session”,and fill in theserver name • Enter a namein the “SavedSessions” field,and click “Save”
Logging In • From now on, you can double-click on any saved session name to login • This dialog will onlyappear in the firsttime you login • Click “Yes”,and continue
Logging In • After PuTTY successfully connects to the server, a terminal window is opened • Type your password, and you're in! • (To log off, type exit)
Accounts and Passwords • Each student has an account similar to his IDC mail : <last_name>.<first_name> • You should change your password as soon as you login (initial: <first_name>2009) • Example: • User: gelman.elad • Password: elad2009 • To change your password, type passwd
Shells • A shell is a command interpreter, which acts as an interface between the user and the operating system • A shell can be used in two modes: • Interactive – the user types in commands one by one, and they are immediately executed • Shell script – commands are entered into a file, which is then run by the shell
Shells • UNIX has several different shells, and each user can select his own default shell • It is common to use more than one shell • For simplicity, we will only use one: tcsh • The advantage of using C shell or TC shell, is that their syntax is very similar to that of the C programming language
Shells • Some common shells:
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
UNIX File System • Files in the UNIX operating system are arranged in a hierarchical structure • Path components are separated by a forward slash – '/', not by a backslash • At the top there is the root directory: '/' • Under it are various system directories • Each user has his own hierarchy of files
User Home Directory • The home directories of users normally reside under /home • The home directory of each user is marked with the special symbol '~', followed by the user name, for example: • This is simply a short-cut for: • Your own home directory is just: '~' ~john.doe /home/john.doe
bin etc home tmp usr File System vs. Physical Disks • The file hierarchy can include several different physical disks / ran john.doe demo
Absolute Paths • Assume that the home directory of user demo is /home/demo • Inside his home directory he hasa sub-directory called solutions,which contains a file called ex1.c • The absolute path to the file ex1.c is: /home/demo/solutions/ex1.c
Relative Paths • The same file can be accessed using a shorter path specification • If the current directory is ~demo, then the relative path to ex1.c will be: • If we are in /home, it will be: solutions/ex1.c demo/solutions/ex1.c
The Current Directory and theParent Directory • There is a special relative pathname for the current directory: . • There is a special relative pathname for the parent directory: ..
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
Listing Directory Contents –ls • The ls command lists the contents of some directory • If the name of a directory is given as a command line argument, then the contentsof that directory will be listed • Otherwise, the contents of the current directory will be listed
Command Line Options • The output format of the ls command can be modified by command line options • The most common ones are: • -l– long format (include file times, owner, group and permissions) • -a– all (also shows hidden files) • -F– include special char to indicate file types
Command Line Options • To use a command line option, precede the option letter with a minus sign: or • More than one option can be given in a single command invocation: ls -a ls -l ls -al
Hidden Files • Normally, ls does not show all of the files in the directory • Files whose name begins with a '.' are called hidden files • These files are not listed by default, and will only appear if the -a command line option is given to ls
General ls command line • The general form for the ls command is: • The options must come before the file name (or names) • More than one file name (or directory name) can be given: ls [options] [names] ls –lF ~demo /usr/bin ex1.c
General Form of Commands • The brackets around options and names in the general form of the ls command mean that something is optional • We will see the general form of many commands described in this manner • Some commands have required parameters, and these will appear without brackets
ls– Examples • The simplest form of ls: • With the –F option: ls backup.tar.gzcreate_backupphone_list temp bin my_documents solutions ls -F backup.tar.gz create_backup* phone_list temp/ bin/ my_documents/ solutions/
ls– Examples • Using –a to list all files, including hidden: • Note that the current and the parent directory are also considered hidden files, since their names start with a '.' ls -a . .history bin phone_list .. .tcshrccreate_backup solutions .exrcbackup.tar.gzmy_documents temp
ls– Examples • The –l option lists the full file information: ls -l -rw------- 1 demo students 317 Oct 19 04:35 backup.tar.gz drwx------ 2 demo students 4096 Oct 19 04:31 bin -rwx------ 1 demo students 35 Oct 19 13:46 create_backup drwx------ 2 demo students 4096 Oct 19 04:30 my_documents -rw------- 1 demo students 17 Oct 19 04:31 phone_list drwx------ 3 demo students 4096 Oct 19 04:32 solutions drwx------ 2 demo students 4096 Oct 19 04:30 temp Permissions User Group Size Date/Time Name
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
Manual Pages –man • The UNIX system has a built-in help mechanism, called the UNIX man pages • The man page for any specific command can be accessed by typing: man command • Since UNIX uses a command interface, which requires memorizing cryptic option names, man pages are used frequently
man– Example man ls NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alpha betically if none of -cftuSUX nor --sort. -a, --all do not hide entries starting with . ...
Viewing man Pages • The following keys can be used to navigate within man pages:
The alias Command • Sometimes we repeatedly use the same command with the same options • The alias command can store short-cuts • For example, we can type: and from that point on, typing list will be equivalent to typing ls -laF alias list ls -laF
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
Changing or Displaying the Current Directory –cd, pwd • The cd command changes the current directory. It's general form is: • With no parameters, cd changes the current directory to your home directory • The pwd command displays the current directory (has no command line options) cd [directory-name]
Copying Files –cp • The cp command copies files • source is the name of the file that you want to copy • dest is the name of the new file • Both source and dest can be relative or absolute paths cp [options] source dest
Copying Files –cp • If you specify a directory as the last argument, cp will assume this form: • cp will put a copy of source inside directory • With this form, source can be a list of files to be copied into directory cp [options] source... directory
cp– Command Line Options • -i– interactive • This option causes cp to prompt the user whenever the copy is about to overwrite an existing file • -r– recursive • Used to copy complete directories, along with all of their files and sub-directories • Applicable only when destination is a directory
Creating or Removing Directories –mkdir, rmdir • The mkdir command is used to create new directories • rmdir removes the given directory • Both accept absolute or relative paths • Both can operate on multiple directories mkdir [options] directory... rmdir [options] directory...
Moving or Renaming Files and Directories –mv • The mv command can be used to rename files or directories • It can also be used to move files or directories to a new location mv [options] source dest mv [options] source... directory
Removing Files –rm • The rm command is used to remove files • Command line options for rm: • -i– interactive (same as for cp) • -r– recursive (same as for cp) • -f– force – the user is never prompted, all problems are ignored (such as trying to remove write-protected or non-existent files) rm [options] file...
Undoing File Removal • The UNIX operating system has no undelete mechanism! • Most systems have a periodical backup (usually once a day to once a week), but all changes since last backup are lost • Therefore, you should be very cautious when using commands such as: rm –rf *
Lecture Overview • Login and shells • The UNIX file system • Listing directory contents • Getting on-line help • Directory and file operations • File permissions • The history mechanism • File name generation and special characters
File Permissions • All possible operations on a file are divided into three types: • Read (abbreviated r) • Write (abbreviated w) • Execute (abbreviated x) • Each file has a separate set of permissions for the file owner, for the group and for any other user
File Permissions • In the listing generated by ls -l, the first field describes the file's permissions: • The first character determines whether this is a plain file (-) or a directory (d) -rwxrwxrwx User Group Other
File Permissions • Files: • r – allowed to read • w – allowed to write • x – allowed to execute • Directories: • r – allowed to see the names of the files • w – allowed to add and remove files • x – allowed to see details of the files