CIS 118 Intr t LINUX Class Exercise Week 3 UNIX/LINUX filesystem (see Filesystem Hierarchy Standard): / +----+-----+----+----+-----+----+-----+-----+----+----+----+ bin bt dev etc hme lib mnt prc sbin tmp usr var +---+---+ bin lib sbin /bin - stres essential binaries (prgrams) needed when bting the system r wrking in single user mde t maintain the system /bt - stres kernel images and bt cnfiguratin files /dev - stres device special files used t access hardware devices /etc - stres system cnfiguratin files /hme - stres the hme directries fr the individual users /lib - stres library mdules used by the cmmands /mnt - a munt pint fr ther strage devices /prc - a pseud filesystem fr cnveying data abut prcesses /sbin - stres cmmands required t administer the system /tmp - used fr temprary files /usr - used fr prgrams, libraries, dcumentatin, etc used by nrmal users /var - stred system data that varies r changes frequently such as system lgs, mail and print spl files Path: An abslute path is the exact lcatin f a file r directry starting frm the rt directry. Fr example: / +-----+-----+------+-----+ bin etc hme usr var +---------+ <userid1> <userid2> CIS118 A relative path gives the lcatin f a file r directry relative t the current directry../cis118. the abslute path t the ntes directry is /hme/<useridx>/cis118. An abslute path always starts with / Sme special symbls may be used in relative paths.. the current directry.. the parent directry ~ yur wn hme directry
Directry Cmmands: pwd - This cmmand prints the wrking directry. cd - This cmmand changes t a specified directry ls list directry cntents mkdir - creates a new directry: rmdir - remves an existing directry. ls cmmand examples 1. ls List the cntents f the current directry 2. ls /etc List the cntents f the /etc directry 3. ls -a Display all entries in the current directry HIDDEN files beginning with a perid.. 4. ls -l Display a lng r detailed listing f the current directry. 5. ls -al /etc Display a lng listing f the /etc directry including "hidden" files r subdirectries See als cmmands stat and file directry listing entry: There are a number f things that appear in a unix directry listing: 1. Permissins: read(r) write (w) execute(x) fr wner, grup, ther 2. Links: links t existing files. 3. Owner and grup: Unix is a multi-user perating system. Fr each file and directry, the filesystem keeps track f the file wner and grup. 4. Size in bytes: 5. Date: unix filesystem maintains 3 dates fr each file: - the last access date, - the last mdificatin date - the last change date The date that appears in a standard directry entry is the last mdificatin date (see tuch). 6. Filename: A sample directry entry: -rwxrw-r-- 1 xyz staff 12 Mar 7 12:35 runme - This is an rdinary file rwx The permissins fr the wner (xyz): read, write, execute rw- The permissins fr the grup (staff): read, write, nt execute r-- The permissins fr thers: read, nt write, nt execute 1 The number f links t the file xyz The wner staff The grup 12 The size (in bytes) Mar 7 12:35 The last time that the file was mdified runme The name f the file
1) Yur default directry is /hme/<cis r csc>/<userid> 2) cd What is yur current directry nw? cd ~ What is yur current directry nw? 3) cd. What is yur current directry nw? 4) cd.. What is yur current directry nw? ls -al 5) cd ~/CIS118 What is yur current directry nw? 6) cd /usr; cd bin What is yur current directry nw? 7) cd /bin What is yur current directry nw? 8) cd /usr/bin What is yur current directry nw? 9) cd../.. What is yur current directry nw? 10) cd /var/spl/mail. What is yur current directry nw? 11) cd.. What is yur current directry nw? 12) mkdir CIS118 13) cd CIS118 14) tuch this chmd 755 this ls al this tuch this ls al this 15) tuch that chmd u+rwx that; ls l that chmd g+rwx that; ls l that chmd +rwx that; ls l that chmd a-x that; ls l that ls al that ech Hi there > that; ls al that; cat that ech Hi there > that; ls al that; cat that ech Hi there >> that; ls al that; cat that 16) mkdir p week2/this/that cd week2 mkdir xx ls al umask 17) mkdir New.dir rmdir New.dir cd ~/week2 18) Shw lng directry listing under /. Under the fllwing directries: bin, bt, dev, etc, hme, lib, mnt, prc, sbin, tmp, usr, var using abslute path using the fllwing cmmands: ls al /<directry> mre hit ENTER, hit Spacebar. Type q and Enter: ls al /<directry> less hit ENTER, hit Spacebar. Type q and Enter: 19) Run the cmmands: ls -F /hme ls -F /bin What symbl des the -F ptin use t identify directries? What symbl des the -F ptin use t identify executable files? What is the purpse f the -F ptin f the ls cmmand..
File cmmands: mre - display file cntents ne screen at a time. On lder systems this cmmand was called page. ls al / mre [SpaceBar] - display the next screen [Enter] - advance 1 line b - g backwards /xyz - search fr the string xyz q quit less - a mre pwerful versin f mre ls al less head - display lines frm the beginning f a file. ls al head tail - display lines frm the end f a file cp - cpies a file r files cd ~ cd CIS118./hell.sh > ldfile cp ldfile newfile mkdir newdir cp ldfile newdir cp h* newdir: cpies all files with a filename beginning with the letter h t the directry newdir; if newdir is nt a directry, this cncatenates all files beginning with the letter f int a single file called newdir cp h? newdir cpies all files with tw letter filenames where the first letter is h t the directry newdir cp b[aeiu]t newdir cpies the files bat, bet, bit and but t the directry newdir mv - Mves instead f cpies, same syntax as cp. Als renames a file. mv newfile newdir rm - This cmmand deletes a file. rm file1 delete file1 rm * delete all files in the current wrking directry rm -i * prmpt t cnfirm befre deleting each file tuch - Changes the access and mdificatin time f a file t the current time. If the file des nt exist, tuch will create an empty file using that name. tuch ldfile2 find lcate files by name r ther attributes (see als lcate) fine name cre print exec rm {}; ln - create a link t an existing file.: ln -s filename linkname creates a link r a pinter. The link will be called linkname and it will pint t filename.
1. List all hidden files (filename begins with. ) yur wn hme directry. 2. Use head r tail t d the fllwing: Display the last 4 lines f the file /etc/passwd. Display the last 4 lines f the file /etc/grup. Display the first 10 lines f the file /etc/lgin.defs. 3. The cpy cmmand: Make a directry in yur HOME called WEEK2. Cpy frm yur hme directry t WEEK2. Make a cpy f.bash_prfile called bprfile. Cpy /etc/issue.net t yur HOME directry Cpy all files files t anther directry: Cpy the readme frm t the /tmp directry t yur HOME directry cp /etc/passwd ~ 4. In yur wn hme directry, use the tuch cmmand t create five files: ne, tw, three, fur and five. Get a directry listing t make sure that the cmmand wrked. 5. Practice making directries. In yur wn hme directry, make /dir1/dir2: dir1 and dir2. Get a directry listing t make sure that the cmmand wrked. In yur HOME directry make a link dir2sub t ~/dir1/dir2. 6. Practice mving files frm yur wn hme directry: Mve the readme file called t the directry dir2 frm abve Use a single cmmand t mve all hidden files in yur hme directry t dir2 frm abve. Rename readme t.readme and repeat abve. 7. Use the mve cmmand t rename files. Use the mve cmmand t change the name f the file called readme2 t readme.new. Create a subdirectry called aaa. Can yu use the mve cmmand t change the name f aaa t dir3? 8. Remving files In yur HOME directry tuch files r1, r2, r3 rm r[12] cp r[12] /tmp 9. tail, head tail /etc/passwd head -20 /etc/passwd 10. ln ech The quick brwn fx jumped ver the lazy dg. > test.txt ech The quick brwn fx jumped ver the lazy dg. >> test.txt 3 times ln s test2.txt test.txt cat test2.txt ls al test3.txt cat test3.txt ech The quick brwn fx jumped ver the lazy dg. > test2.txt cat test.txt, cat test3.txt; ls al test*.txt ech The quick brwn fx jumped ver the lazy dg. > test3.txt cat test.txt, cat test2.txt; ls al test*.txt rm test.txt cat test.txt, cat test2.txt; cat test3.txt; ls al test*.txt
Permissins -rwxrwxrwx Read, Write, Execute fr Owner, Grup, Other fr a file: withut read permissin, a user cannt view the cntents f a file withut write permissin, a user cannt mdify the cntents f the file withut execute permissin, a user cannt execute the file. fr a directry: withut read permissin, a user cannt get a directry listing withut write permissin, a user cannt create new files withut execute permissin, a user cannt cd t the directry, list the directry cntents r save a file in the directry. chmd - change permissins. Read, write and execute permissins are set fr three grups: the wner, the grup and everyne else. chmd 543 myfile wuld set access rights as fllws: wner: 5 = 101 binary = read, nt write, execute grup: 4 = 100 binary = read, nt write, nt execute thers: 3 = 011 binary = nt read, write, execute chmd - versin 2 permissins can als be set using a text representatin u - user r wner g - grup - thers r - read permissin w - write permissin x - execute permissin chmd u+w file1 adds write permissin fr the user chmd +w file1 adds write permissin fr the user, grup and thers chmd g-x file1 deletes execute permissin fr the grup and thers chmd u=r file1 changes the permissins fr the user t be just read permissin (grup and ther permissins are nt changed) umask sets default unmask bits
1. ls al /etc ls al /etc/paswd tuch file1 chmd 444 file1 ls al file1 chmd ug+w file1 ls al file1 mkdir dir1 tuch dir1/test chmd 444 dir1 cd dir1 tuch dir1/test chmd 544 dir1 cd dir1 tuch dir1/test chmd a+x dir1 cd dir1 tuch dir1/test