2 The Filesystem Partitions / - The root partition: essential system binaries & configuration files/bin contains shells, ls, mkdir, etc./usr – Operating system binaries & source code/usr/include contains c header files ie: stdio.h/usr/bin contains executables ie: gcc, g++, locate, where, passwd, etc./usr/local – Administrator installed programsie: apache web server, samba file server, etc./tmp – Temporary files
3 Partitions Continued … /var – Files that change regularlyie: mail spools, printer spools/dev – Device filesProvides access to all hard drives, ports, tape drives, floppy drive & cdrom drive./users – User home directoriesSome UNIX servers use /home insteadOn Turing, all of your student accounts are in /users/student ie: /users/student/lbburford
4 Moving Around the Filesystem cd – change directoryAbsolute paths – specify the full path from the root directory (/)ie: cd /usr/includeAbsolute paths always have a leading slashRelative paths – specify the path from the present working directoryRelative paths never have a leading slashFor example, let’s assume I’m currently in the /usr directoryThe command cd bin would take me to /usr/bin not to /bin
5 Moving Continued Special characters . – current directory .. – parent directoryie: from the /usr/bin directory, cd .. would take you to the /usr directory.~ - home directorycd ~ will take you to your home directorycd ~user will take you to user’s home directory
6 You’ve changed directories, how do you find out what’s in there? ls – Directory listingls -a - list all files in the current directory. Files beginning with a ‘.’ are hidden. Using the -a flag will show those files.ls -l - list all files in the current directory with permissions, user and group information, size, and last modified datels -al - lists extended information about all files in the current directorypwd – Present working directoryIf you forget which directory you’re currently working in, the pwd command will show you.
7 Working with Files & Directories cp – copy file(s)cp source destinationmv – move & rename filesmv source destinationrm – delete a file or directoryrm filenamerm -R directoryrecursively deletes all files in the specified directory, then deletes the directory itself.mkdir – make directorymkdir directory
8 File PermissionsThere are 3 different types of permissions for files & directories on UNIX systemsReadOn files, allows the file to be openedOn directories, allows a file listing (ls) inside the directoryWriteOn files, allows the file to be modified/deletedOn directories, allows the creation of files in the directoryExecuteOn files, allows the file to be executed (run as a program)On directories, allows traversal inside the directory (lets you cd into the directory)
9 File PermissionsThere are 3 different sets of users for which permissions are set on a file.Owner – the person who owns the fileGroup – The group that owns the fileWorld – Everyone elseWhen you do an ls –l in a directory, you’ll see each file has a permission entry like this:rwxr-xr-xThis type of entry is read left to right, the first 3 letters are for the user, the second 3 letters are for the group, and the third three letters are for the world. A hyphen indicates no permission.This particular entry means that the user has read, write, and execute permissions, while the group and the world have read and execute permission on it.
10 File Permissions Continued The chmod command is used to modify file and directory permissionschmod permission filepermission in the above command is a 3 digit number. The first digit represents the owner permission, the second represents the group permission, and the third represents the world permission.Read = 4Write = 2Execute = 1Add the numbers of the permissions you wish to assign togetherie: read and write = = 6Apply the same principle for each set of users
11 File Permissions Exercise Let’s assume we have a file called test.shWe want to allow the owner to have all permissions, the group to have read and write permissions, and the world to have only execute permission. What is the 3 digit number representing the permissions we want?Let’s start with the owner: read + write + execute = permission= 7Group = read + write4 + 2 = 6World = execute1Now put it all togetherPermission = 761The final command is: chmod 761 test.sh
12 Getting Help man – Display manual pages aka: man pages man command If when you run man on a particular command, you get the “builtin” man page, it means the command you specified is provided directly by the shell and not as an external program. In this case, you need to look up the man page for the shell you are using to find information about the command.man also works for C functions provided by the system.ie: man printf
13 Editing Text There are several options for text editors pico – easy to use editor with on screen menus.ee – similar to pico, menus not quite as intuitive.vi – the most powerful text editor. No on screen menus, high learning curve. The only editor guaranteed to be on any UNIX system you encounter.Textpad – while not a UNIX application, it is probably the best available choice for a Windows text editor with C syntax highlighting. Available for use on all CS computers, allows you to work on your programs through a mapped network drive.
14 Other Useful Commands pine – email client with on screen menus lpr – print a filelpr –P prlaser myfile.cavailable printers on Turing: prlaser, syslaser, memlj, mem2lj, advlasergrep – search for specific textless & more – show the contents of a file, or page output of a commandps – show all of your currently running processeskill – allows you to send signals to your processeskill -TERM pidTERM, HUP, & 9 are the most common signals you’ll need to send
15 Hints to make your life easier ./ - UNIX only knows about commands in your path. To run a program/script not in your path, you must either specify the whole path to the executable, or if you’re in the same directory as the executable, then type ./name_of_executable./a.outtab – auto complete file names & paths| - pipe operator, allows you to redirect the output of one command to the input of anotherls | grep .cls -l | lpr -P prlaserls | more> - output redirection operator./a.out > output.txtup arrow – allows you to scroll through your command history instead of retyping a command