Command-line interface on Linux/UNIX: Difference between revisions

From csml-wiki.northwestern.edu
Jump to navigation Jump to search
Line 31: Line 31:
diff -w file1 file2
diff -w file1 file2
</pre>
</pre>
To compare two text files in which lines may have been rewrapped, use [http://www.gnu.org/software/wdiff wdiff]
To compare two text files in which lines may have been rewrapped, use [http://www.gnu.org/software/wdiff wdiff] ('word diff')
<pre>
<pre>
wdiff -3 file1.tex file2.tex
wdiff -3 file1.tex file2.tex

Revision as of 07:33, 20 June 2014

This is not a UNIX guide, but just a loose list of tips, hints, etc., that may come in handy when working in a command-line environment.

Bash

  • To use the output of one command as the input for the next command, use back quotes ("inverted commas") around the first command. This is called command substitution.

Useful (and sometimes underappreciated) command-line tools

  • To combine files side-by-side into a single file use
    paste file1 file2 ... > output
    

    If file1, file2, ... contain the same number of lines, output will contain their contents as columns.

  • You may have many entries in your PATH variable, or there may be multiple copies of an executable on a file system. To determine which version of program will be executed, use
    which program
    
  • Comparing text files. To find out if two files are identical except for differences in white space, use
    diff -w file1 file2
    

    To compare two text files in which lines may have been rewrapped, use wdiff ('word diff')

    wdiff -3 file1.tex file2.tex
    
  • To find out which libraries are needed/used by a dynamically linked executable, use
    ldd /path/program
    

    Note that ldd will not use PATH to search for program; just must specify it via an explicit path. However, you can take advantage of which as follows

    ldd `which program`
    

    Note the back quotes. Side note: On OS X, if you have xcode installed the ldd command can be mimicked via otool -L