Review of File System - The hierarchical file system used by UNIX is copied by all the major OS. We start at root dorectory called /. Each directory can contain files or directories. The files can exist in more than one directory using the command ln - Because of linking by the ln command UNIX tree structure is destroyed at the bottom most level. - Links cannot be made to other directories nor to files on other file systems. - UNIX can contain several file systems: these are either different partitions of the same disk, different disks, or disks on different computers. - The command df will allow you to look at the file systems on your machine. More later. - Soft links created by ln -s can be used to creat pseudo links to directories or links to files in other file systems. But they can be used to link to files in the same file system as well. wascana/extra/pawan/test 4 >ls -al total 12 drwx------ 2 pawan ta 1024 Jun 16 11:05 . drwxr-xr-x 29 pawan 0 2048 Jun 16 10:57 .. lrwxrwxrwx 1 pawan ta 9 Jun 16 11:05 .cshrc -> ../.cshrc -rw------- 2 pawan 0 8281 Mar 26 13:47 a_net lrwxrwxrwx 1 pawan ta 8 Jun 16 11:01 bin -> /usr/bin wascana/extra/pawan/test 5 > - Here we have three files. .cshrc is soft linked to a file by the same name in parent directory. a_net is also linked to another file but we cannot tell which other directory has a link to that file. bin is soft linked to the directory /usr/bin - soft links are identified by l in the first column of long dir listing - hard links can be inferred by looking at the number of links in the second field of the long dir listing. - cp and mv can be unforgiving by default, i.e. they will delete an existing file by the same name. You can use the -i option to make interactive overwrite. We will also look at making -i a default option by aliasing the mv/cp command. - Typical file structure - /bin stores many of the programs that are used - shell has certain commands built in. The remaining commands are just programs. - There are various other standard directories. A photocopy of the the table listing these will be provided. - It is probably not wrong to say that every thing in UNIX is treated as a file. That includes devices and directories. - A normal file is just a sequence of bytes. It can be anything your program wants it to be. Although there is a utility called file that makes an educated guess as to what that file contains by looking at first few hunderd bytes. wascana/extra/pawan 19 >file *net orig.net: ascii text soonet: directory trained_orig.net: ascii text FILE PERMISSIONS - File permissions are set according to owner, group and world - If you belong to a group called city, you can change group for a file to that group "city" using the command: chgrp wascana/extra/pawan 22 >file a2_p2.cpp a2_p2.cpp: c program text wascana/extra/pawan 23 >chgrp a2_p2.cpp city chgrp: invalid group `a2_p2.cpp' wascana/extra/pawan 24 >chgrp city a2_p2.cpp chgrp: you are not a member of group `city': Operation not permitted wascana/extra/pawan 25 >chgrp traffic a2_p2.cpp wascana/extra/pawan 26 >ls -l a2_p2.cpp -rw-rw-r-- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp - First field consists of 10 bits. First bit tells the type of the file: d for directory, l for soft link. - Next three bits give you permissions for the owner first bit is for read, second for write and third for execute Similarly next three bits are for group and the last three bits are for the world. Here world means everyone in the system. - chmod allows you to change the permissions. - chmod +x makes the file executable for the owner wascana/extra/pawan 27 >chmod +x a2_p2.cpp wascana/extra/pawan 28 >ls -l a2_p2.cpp -rwxrw-r-- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp wascana/extra/pawan 29 >chmod -r a2_p2.cpp wascana/extra/pawan 30 >ls -l a2_p2.cpp --wxrw-r-- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp wascana/extra/pawan 31 >chmod g+x a2_p2.cpp wascana/extra/pawan 32 >ls -l a2_p2.cpp --wxrwxr-- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp - Octal number is another way of specifying the permission - Each three bits correspond to an octal digit 000 = 0 --- 001 = 1 --x 010 = 2 -w- 011 = 3 -wx 100 = 4 r-- 101 = 5 r-x 110 = 6 rw- 111 = 7 rwx wascana/extra/pawan 35 >chmod 000 a2_p2.cpp wascana/extra/pawan 36 >ls -l a2_p2.cpp ---------- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp wascana/extra/pawan 37 >chmod 440 a2_p2.cpp wascana/extra/pawan 38 >ls -l a2_p2.cpp -r--r----- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp wascana/extra/pawan 39 >chmod 640 a2_p2.cpp wascana/extra/pawan 40 >ls -l a2_p2.cpp -rw-r----- 1 pawan traffic 670 Apr 23 13:46 a2_p2.cpp - chown allows you to change the ownership - chown username filenames - chown can only be used by the su - -R option is extremely important in chmod,chgrp,chown - Generally, if you are changing the mode, group or owner, for a directory, you want the change to be effective to all the subdirectories underneath - cp, rm, and mv also have a recursive option called -r - Note that the recursive option for the latter commands is in lower case. - UNIX is very case-sensitive. SOmething that should be aware of when you transfer files from DOS. - rm -r is a beter way of deleting a dir than rmdir, because rmdir can only delete empty dir. - uuencode can be used to encode file to ASCII format wascana/extra/pawan 16 >uuencode /bin/cp cp > cp.enc cp.enc: File exists. wascana/extra/pawan 17 >rm cp.enc /bin/rm: remove `cp.enc'? y wascana/extra/pawan 18 >uuencode /bin/cp cp > cp.enc wascana/extra/pawan 19 >uuencode /bin/cp cp cp.enc Try `uuencode --help' for more information. wascana/extra/pawan 20 >more cp.enc begin 755 cp M?T5,1@$!`0````````````(``P`!````H`\`"#0```"D20```````#0`(``% M`"@`%``3``8````T````-```"`````"@````H`````4````$`````P```-0` M``#4```(`````!,````3````!`````$````!``````````````@`````%4`"``````(`@``=0,```8`````$``` M`@```/!&``#P5@`(`````)````"0````!@````0````O;&EB+VQD+6QI;G5X - uuencode filename nam-of_the-file-after-decoding - the output was redirected to a file called cp.enc - as you can see the file cp.enc is an ASCII file wascana/extra/pawan 21 >ls cp /bin/ls: cp: No such file or directory wascana/extra/pawan 22 >uudecode cp.enc wascana/extra/pawan 23 >ls cp cp wascana/extra/pawan 24 >cmp cp /bin/cp - uudecode cp.enc created the file cp with permissions 755 - as can be seen it is identical to the file /bin/cp - compress will compress a file and uncompress will uncompress it wascana/extra/pawan 1 >ls -l orig.net -rwx------ 1 pawan ta 8258 Mar 26 13:47 orig.net wascana/extra/pawan 2 >compress orig.net wascana/extra/pawan 3 >ls -l orig.net ls: orig.net: No such file or directory wascana/extra/pawan 4 >ls -l orig.net* -rwx------ 1 pawan ta 1899 Mar 26 13:47 orig.net.Z wascana/extra/pawan 5 >uncompress orig.net wascana/extra/pawan 6 >ls -l orig.net* -rwx------ 1 pawan ta 8258 Mar 26 13:47 orig.net - If you are using csh, you should have a file called .cshrc in your home directory. There is also a global file called csh.cshrc in /etc directory - csh.cshrc and .cshrc are executed every time you start a new csh - csh.login and .login are executed every time you login - .login and .cshrc in your home directory are used for customizing your login and csh sessions - It is possible to login once and have several csh sessions going. - You can set variables in .cshrc, you can set aliases