DOC PREVIEW
FSU COP 3353 - Lecture 2 Working with Files and Directories

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Try these examples:Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 191Lecture 2Working with Files and DirectoriesCOP 3353 Introduction to UNIX2Files•Files–A well defined repository of information•Program or component of a program•Arbitrary text•An executable (binary text)–Special files called directories contain or point to other files•Structure of Directories–Hierarchically structured like an inverted tree–/ is the starting directory or “root” •Pathnames–Locating a file by following a sequence of directories until you reach the file–/ is also the separator between the directories and final file3Example set of directories and filesbin home etclisterrimmer krytenHologramshipsGuitar BazookoidStarbug/4More on pathnames•Absolute pathnames start at root–/home/lister/ships/Starbug–/bin•Relative pathnames start at current directory–Suppose current directory is “home”, then:–rimmer/Hologram would refer to the same file as:–/home/rimmer/Hologram•Special symbols for current directory and parent–“..” refers to parent directory (the directory “above”)–“.” is current directory•Referencing user directories–~rimmer is the absolute pathname to the user directory “rimmer” (in the directory “home” in this example)–~/ is shorthand for the absolute path to your own user directoryTry these examples:•Suppose:–your username is “lister”–your current directory is “ships”•Write the absolute pathnames for:–bin–Guitar•Write the relative pathnames for:–Starbug–home–Guitar–rimmer•Where could you use directory references? (~)6UNIX Commands•Commands typically refer to a Unix program located, for example, in /usr/bin–Structure of a command is typically:commandname [flags] [parameters]•Flags–Commands may accept one or more flags–Flags start with “-” and are separated from other flags and parameters by one or more spaces–Individual flags may be combined under a single ‘–’•Parameters–Parameters are often filenames and/or pathnames–Commands accept one or more parameters, separated by spaces7Examplesls –a –lls –alcp /home/albert/cprogram sourcescp ../testfiles/part1 .wc –c –l thatfile8Some file commandsls list filescat view file contentsmore view file contents (pause each screen)touch creates file / updates time stampcp copy file to a new filemv move file to a new directory, rename filerm delete file9Some directory commandspwd display absolute pathname to current directorymkdir create directoryrmdir remove directorycd navigate directories10Some useful commands•pwd–Prints the absolute pathname of the current directory•ls –al–The ls command lists the files in a directory. The a flag displays all the files. The l flag gives detailed information.•touch–The touch commands creates an empty file or updates the timestamp of an existing file•cp–The copy command copies the contents of a file or directory to another file or directory (two parameters). The i flag asks before it replaces an existing file; the r flag recursively copies all subdirectories also.11Useful commands continued•mv–The move command renames a file (it takes two arguments)–mv oldfilename newfilename–If the second argument is a directory it moves it to that directory•wc–Counts the characters, lines, or words in a file–wc –w essay•cd–Changes the current directory to another one–cd assignment1–cd ..–cd ../assignment1•passwd–Run this to change your password12Useful commands continued•man–Man pages, short for manual pages.–All UNIX and unix-like OS have this documentation application.–Similar to help, is self contained for each command.•Command --help–All command have a help menu that can be accessed.–Simple to complex explanation flags and parameters13Characters in filenames•File names can contain any characters except “/”, but it is recommended that you use upper or lower case letters, numbers, and the characters “-” “.”•For example although a file name could contain a space or spaces:confusing namecommands using this would not work correctly unless you tell the shell to not break an argument at the spaces by quoting the filename.rm “confusing name”14File Permissions•3 types of processes can access a file–user or owner: process spawned by user who created file–group: process spawned by members of the same group–other: process spawned by anyone else•Permission types–read: access file or list directory–write: write to / remove file (directory)–execute: run file as a program or enter directory15Example Output•Current permissions can be viewed using ls -l–First line is the number of disk blocks ( 1 block is 512 bytes) taken up by all the files[sudhir@www scop3344]$ ls -altotal 596drwxr-xr-x 3 sudhir fac 4096 Jan 22 17:38 .drwxr-xr-x 11 sudhir fac 4096 Jan 3 18:30 ..-rw-r--r-- 1 sudhir fac 4631 Jan 18 16:10 Assignment1.txtdrwxr-xr-x 3 sudhir fac 4096 Jan 9 17:07 index_files-rw-r--r-- 1 sudhir fac 51693 Jan 22 17:35 index.html-rw-r--r-- 1 sudhir fac 247017 Jan 18 10:51 Lecture1.pdf-rw-r--r-- 1 sudhir fac 92123 Jan 16 09:05 Lecture2.pdf-rw-r--r-- 1 sudhir fac 175410 Jan 22 17:24 Lecture3.pdf[sudhir@www scop3344]$16Columns in the Display•First entry in a line is the mode–The first character is d for directory, else - for a normal file–The remain 9 characters in groups of 3 are r, w, x permissions for user, group and other respectively (- indicates not having that permission)•Second entry indicates number of links to the file (usually 1)•Third entry is the user id of owner and the fourth entry is the group id•Fifth entry is the number of bytes of the file•Sixth entry is the date the file was last modified17Changing Permissions•Using the chmod command to set permissions–Numeric (using octal)•Directly set the permissions for u, g, o using each 3 bit value as an octal value•chmod 754 lecture1.pdf will set to 111 101 100 or rwx r-x r--•chmod 700 lecture1.pdfwill set to 111 000 000 or rwx --- ---•chmod 644 lecture1.pdfwill set to 110 100 100 or rw- r-- r--18Changing Permissions (cont)–Symbolic•Format: chmod [who] [operation] [permissions] <filename>•who is one or more of u, g, o•operation is + (add), - (remove), = (set)•Permissions are one or more of r, w, x•Exampleschmod


View Full Document

FSU COP 3353 - Lecture 2 Working with Files and Directories

Download Lecture 2 Working with Files and Directories
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 Lecture 2 Working with Files and Directories 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 Lecture 2 Working with Files and Directories 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?