Another commonly used option is to extract all files from tar file often called

Another commonly used option is to extract all files

This preview shows page 4 - 8 out of 11 pages.

Another commonly used option is to extract all files from tar file (often called tar ball): % mkdir tmp % cd tmp % tar -xvf ~/lab02.tar
Image of page 4
The first command creates a new directory tmp . The second command sets your current directory to tmp . The last command extracts all files in directory tmp . Try the above examples. Try to create archives from other directories and extract the tar files (in a different directory). 6. File Compression and Decompression with gzip and gunzip To compress a file, say lab02.tar , use command % gzip lab02.tar this will create a compressed file named lab02.tar.gz . To uncompress it, just type the command % gunzip lab02.tar.gz Try the two commands on a file Note that on Linux system, compression and uncompression are added to the tar command. For example, you can archive files and then compress the archive in a single command using option z , such as % tar -zcvf ~/lab02.tar.gz ~/lab02 Theory Exercises Stallings (5th edition): Problems 2.1 and 2.4 (page 104). or Stallings (6th edition): Problems 2.1 and 2.4 (pages 103-104). For Problem 2.4 check manual page of system call open (man -s 2 open). C Programming Exercises Note, all exercises must be done via the terminal commands, not GUI tools. Do not use IDE to build your programs. Do not use GUI file managers to manage your directories and files. Also each exercise should be in a separate directory, which itself, is under a directory called lab03 1. Formatted Output with printf Last week, we used the printf function to send output to the standard output. This function allows you to construct complex strings
Image of page 5
consisting of strings, integers, floats, chars, etc, in a very flexible way. For example, the following code constructs the stringToday is 0008 August 2006.from integer variableday, string variablemonthand integeryear:int day = 8;char *month = "August";int year = 2006;printf ("Today is %04d %s %d.\n", day, month, year);In the aboveprintffunction, each "%" starts a conversion specification. For example, the first conversion%04dmeans converting the first variable,day, to a decimal string using at least 4 digits with zero padding. The second conversion%smeans convert the second variable,month, to a string. The third conversion,%d, means converting the third variable,year, into a decimal string without padding.Convert the above code into a complete C program. Run the program to send output to your terminal screen.Use standard output redirection, so that the program sends its output toa file namedfoo.2.Sending Output to a File withfprintfWhat if you want to send output to a specific file, such asfoo2, rather than to the standard output in your program? Well, you can use another
Image of page 6
Cannot open file foo2, terminate program to the standard error. Note that you do not need to open standard error.
Image of page 7
Image of page 8

You've reached the end of your free preview.

Want to read all 11 pages?

  • Fall '15
  • DK
  • command line arguments

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture