Posts

Showing posts from May, 2008

How to use diff in UNIX

The following were taken from http://www.unixtutorial.org/2008/02/compare-text-files-using-diff/. All credits goes to them. If you need to compare two text files in Unix, you're mostly likely to use the diff command. Today I'll talk about the simplest scenario: you want to compare two files and understand if there are any differences. Suppose you have two files in /tmp directory: /tmp/1.txt: aaa bbb ccc ddd eee fff ggg and /tmp/2.txt: bbb c c ddd eee fff ggg hhh I have deliberately created them so short and simple - this way it's easier to explain how the comparison works. If there are no differences between the files, you will see no output, but if two text files are indeed different, all the text mismatches will be highlighted using the standard diff output: $ diff /tmp/1.txt /tmp/2.txt 1d0 <> c c 7a7 > hhh Lines like "1d0" and "3c2" are the coordinates and types of the differences between the two compared files, while lines like "<>

Finding files in UNIX

The following guide is a direct rip-off from this website: http://www.hccfl.edu/pollock/Unix/FindCmd.htm All credits goes to him. The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files that match the supplied search criteria . You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories too. The syntax looks like this: find where-to-look criteria what-to-do All arguments to find are optional, and there are defaults for all parts. (This may depend on which version of find is used. Here we discuss the freely available GNU version of find , which is the version available on YborStudent .) For example where-to-look defaults to . (that is, the current working directory), criteria defaults to none (that is, show all files), and what-to-do (known as the find action ) defaults to -print (that is, displa