Command-line interface on Linux/UNIX

From csml-wiki.northwestern.edu
Jump to navigation Jump to search

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