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

From csml-wiki.northwestern.edu
Jump to navigation Jump to search
(Created page with "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 === <ul> <li><span id="inv...")
 
Line 35: Line 35:
ldd `which program`
ldd `which program`
</pre>
</pre>
Note the <tt>[[#inverted-quotes|back quotes]]</tt>. Side note: On OS X, if you have <tt>xcode</tt> installed the <tt>ldd</tt> command can be mimicked via <tt>otool -L</tt>.
Note the <tt>[[#inverted-quotes|back quotes]]</tt>. Side note: On OS X, if you have <tt>xcode</tt> installed the <tt>ldd</tt> command can be mimicked via <tt>otool -L</tt>
</li>
</li>



Revision as of 09:14, 28 May 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
    
  • 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