File Structure, Operations on Files in Unix
*EXERCISES* Current directory is: /home/cesim/circles/finalver/ - Get a page by page (detailed)listing of all the files(including hidden) in the current directory. - Go to the directory /home/cs352/SUMMER02/ - List the contents of the directory - Create a directory named /home/cs352/SUMMER02/newdir1/newdir2/newdir3 - Check the access permissions of newdir1 - remove newdir1 and all its subdirectories - Create a directory newdir1 in SUMMER02 directory with access permissions user:rwx, group:rw, other:x - Create newdir2 in newdir1 - Change the access permissions of both newdir1 and newdir2 user:rwx, group:empty, other:empty - Copy june3 into newdir1, copy june5 into newdir1/newdir2 - Check the contents of newdir1, Copy all the contents into a directory newdir3 in SUMMER02 - Print the file june5 in newdir2 to the printer lw11 Check if it's printed. Cancel the print job on lw11 for user cesim - Types of files: -Ordinary Files -Directories (inode#,filename) -Symbolic Link (soft-contains pathname of the file) -Special Files (for hardware devices) -pipes (for IPC) - Pathnames -Relative(./newdir/file1 ...) or absolute(/home/cs352/SUMMER02/newdir) - File System Structure -treelike - What is in the file system? - root: / - /bin (executables of Unix commands:cat, chmod, cp,... (usually a symbolic link to /usr/bin) - /dev (device files) - /etc (for system admin: login, passwd, group) - /lib (libraries as archives, usually symb. link to /usr/lib) - /tmp (temporary files) - /home (home directories of users) - /usr (includes /bin & /lin, utilities, tools, man pages...) - /var (/var/mail) - /etc/passwd (login:passwd:uid:gid:info:home:shell) -File Processing -How to see contents of a file? more(one page at a time, more file1 file2, more -n10 file1 ...) cat Ex:cat file1 file2, cat -n file1 ... head Ex:head -20 file1 ... tail Ex:tail -20 file1, tail +5 file1 ... -Redirection&Pipes -Default files(stdin, stdout, stderr) Redirection: -Command can read input from a file rather than keyboard Ex: catnewdir1/june35 Note that appending is done by >>cat -n june35|head -20|sort - -Command can write error to a file rather than screen Ex: cat june7>&caterr -Combining Ex: cat june3 june7>&caterr (cat june3 june7>catres)>&caterr Pipes: Ex: cat june3 june5 | wc -l>>june35 cat -n june35|head -20|sort -r