CS 497C - Introduction to UNIX Lecture 13: - The File System Chin-Chih Chang chang@cs.twsu.edu mv: Moving or Renaming Files * mv renames (moves) files and directories. * It has two functions: - Rename a file (or directory). - Move a group of files to a different directory. * Like cp, a group of files can be moved to a directory. * mv can also be used to rename a directory. * There is a -i (interactive) option available with mv. cat: Displaying and Creating Files * The cat command is the universal file viewer. * cat is normally used for displaying text files only. Executables, when seen with cat, simply display junk. * If you have nonprinting ASCII characters in your input, you can use cat with the -v option to display these characters. * You can also cat to create a file. cat: Displaying and Creating Files * Enter the command cat, follow it with > and the filename foo: $ cat > foo A > symbol following the command means that the output goes to the filename following it. [Ctrl-d] * The [Ctrl-d] is used to end the session of all commands that accept input from keyboard. file: Know the File Types * The file command tells not only the file types (ordinary, directory, and device) but also more information about these files. $ file semaphore.c semaphore.c C program text $ file * lp and cancel: Printing a File * A user has to spool (or line up) a job along with others in a print queue. * The spooling facility in System V is provided by the lp (line printing) command. lp chap01 * The -d (destination) option with the printer name identifies which printer is used. * The -t (title) option prints the title on the first page. lp and cancel: Printing a File * The -m (mail) option is used to notify the user after the file has been printed. * You can print more than one copy by using -n option. lp -dlaser chap01 lp -n3 -m chap01 * Jobs queued by lp are canceled with the cancel command. Printing with lpr, lpq, and lprm * Linux uses Berkeley's printing system which supports the lpr command for printing and lprm for removing jobs. * To know the number of the job, use the lpq command. $ lpr typescript $ lpq $ lprm 17 df: Finding Out the Free Disk Space * The df command finds out the free disk space. * It shows how many blocks (usually 512 bytes) of disk space and inodes (files) are free for use. * The -t (total) option includes the total amount of disk space in each file system. du: Finding Out Your Own Consumption * The du (disk usage) command reports disk usage by a recursive examination of the directory tree. du . * The -s (summary) summarizes the disk usage. Compress, gzip, and zip: Compress Your Files * For disk space conservation or the fast download, files are frequently compressed. * The most frequently used compression programs in UNIX are compress, gzip, and zip. * The compress command produces the file with Z extension. Compress, gzip, and zip: Compress Your Files compress daily.log uncompress daily.log.Z * You can use the zcat command to uncompress a file and see its contents. A compressed gzip file has the extension .gz. * It is decompressed with the gunzip command. gzip sales.dbf gunzip sales.dbf.gz Compress, gzip, and zip: Compress Your Files * gzip today is a standard compression utility on the Internet. * Phil Katz's pkzip program compresses multiple files into an archive (a single file containing a group of files). zip fin *.html * With the -r option, zip can also recursively compress an entire directory. zip -r zipdir docs Compress, gzip, and zip: Compress Your Files * On the Internet, you'll see these extensions: - zip - These are files compressed with zip. - tar - Files archived into a single file with the UNIX tar command. - gz - These are compressed with gzip. - tar.Z - Files archived into a single file with tar and then compressed with compress. - tar.gz - Files archived into a single file with tar and then compressed with gzip.