DOC PREVIEW
FSU COP 3353 - Lecture 5 Additional Useful Commands

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 111Lecture 5Additional useful commandsCOP 3353 Introduction to UNIX2diff•diff compares two text files ( can also be used on directories) and prints the lines for which the files differ. The format is as follows:diff [options] <original file> <newfile>•Some options–[-b] Treats groups of spaces as one–[-i] Ignores case–[-r] Includes directories in comparison–[-w] Ignores all spaces and tabs –<original file> - Specifies one file to compare–<newfile> - Specifies other file to compareExample:diff -w testprog1.c testprog2.c3Example files (from Wikipedia)(original file)This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress the size of the changes. This paragraph contains text that is outdated. It will be deleted in the near future. It is important to spell check this dokument. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. (new file)This is an important notice! It should therefore be located at the beginning of this document! This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress anything. It is important to spell check this document. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. This paragraph contains important new additions to this document.4Result of diff (from Wikipedia)0a1,6 > This is an important > notice! It should > therefore be located at > the beginning of this > document! > 8,14c14 < compress the size of the < changes. < < This paragraph contains < text that is outdated. < It will be deleted in the < near future. --- > compress anything. 17c17 < check this dokument. On --- > check this document. On 24a25,28 > > This paragraph contains > important new additions > to this document. In this traditional output format, a stands for added, d for deleted and c for changed. Line numbers of the original file appear before a/d/c and those of the modified file appear after. Angle brackets appear at the beginning of lines that are added, deleted or changed. Addition lines are added to the original file to appear in the new file. Deletion lines are deleted from the original file to be missing in the new file.By default, lines common to both files are not shown. Lines that have moved will show up as added on their new location and as deleted on their old location.5cmp and gzip•cmp–Compares two files byte by byte and tells you where they differ. Generally used for binary and executable files.–usage: cmp myfile1.o myfile2.o•gzip / gunzip–this is one of the compression utilities that reduces the size of a file to take up less space on your drive. It should be used with some care. There are a lot of options available.–Examples to compress and restore a file called bigfile: •gzip bigfile (compresses file, flag -v can be used for verbose mode to give information; note: original file is gone! The compressed file has an extension of .gz•gzip -d bigfile.gz (this restores a .gz file)•gunzip bigfle.gz (same as line above)–When you experiment with this use copies of files rather than the originals until you are comfortable with how gzip works!6grep•grep is a very useful utility that searches files for a particular pattern. The pattern can be a word, a string enclosed in single quotes, or a regular expression.•usage–grep int *.c (find all occurences of the pattern ‘int’ in all files with a .c extenstion)–grep ‘main()’ testprog1.c (enclosing the pattern in quotes is useful when using special characters)–grep ‘m.*n’ myfile (the . matches a single character, the .* matches any number of characters; this finds anything starting with an m and ending with an n)•The way that regular expressions can be described is somewhat complex in grep: see the following tutorial for more help: http://www.panix.com/~elflord/unix/grep.html •grep has many options; a few are noted below-i ignore case-n display the line numbers-l display only names of files and not actual lines-P pattern is a Perl regular expressionSome grep patterns•Bracketed expressions[1357] matches 1 or 3 or 5 or 7[^1357] with a beginning ^ matches not (1,3,5,7)•Range expressions[b-g] matches b, c, d, e, f, g•Named classes of expressions[:digit:], [:alnum:]•Special symbols? The preceding item is optional and matched at most once.* The preceding item will be matched zero or more times.+ The preceding item will be matched one or more times.. This matches any single character7Some grep patterns continued•Matching at the beginning and end^ matches the beginning of the line, thus ^#include would math any lines with a #include at the beginning of the line.$ matches the end of line\< matches the beginning of a word\> matches the end of a word•| the or operatorgrep dog | cat •egrep and fgrep are extended versions89tar•Tar is a utility for creating and extracting archives. It is very useful for archiving files on disk, sending a set of files over the network, and for compactly making backups•General form:tar options filenames•Commonly used Options-c insert files into a tar file-f use the name of the tar file that is specified-v output the name of each file as it is inserted into or extracted from a tar file-x extract the files from a tar file-t list contents of an archive-z will gzip / gunzip if necessary10Creating an Archive with Tar•The typical command used to create an archive from a set of files is illustrated below. Not that each specified filename can also be a directory. Tar will insert all files in that directory and any subdirectories. The f flag is used to create an archive file with a specific name (usually named with an extension of .tar).•Examplestar -cvf proj.tar proj •If proj is a directory this will insert the directory and all files and subdirectories (recursively) with the name of the archive being proj.tar Note that if proj.tar already existed it will simply be overwritten; previous information will be lost.tar -cvf prog.tar *.c *.h•All files ending in .c or .h will be archived in prog.tar11Extracting files


View Full Document

FSU COP 3353 - Lecture 5 Additional Useful Commands

Download Lecture 5 Additional Useful Commands
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 5 Additional Useful Commands and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 5 Additional Useful Commands 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?