Linux Tips and Tricks

Unix/Linux Commands to Know and Cherish (with many thanks to Steve Lantz, CAC)

  • Shell: bash or tcsh
    • The shell defines many of the commands you enter at the command line
    • The Bourne Again Shell is an update to the original Bourne shell (sh)
    • Similarly tcsh is an update to csh, the C Shell (up-arrow to get last command)
  • Getting help: man
    • man = "manual" = the way you get help, e.g., man ls
  • Working with directories: cd, pwd, ls, mkdir, rmdir
    • cd = change directory (popd, pushd to use directory stack); cd .. = up one level
    • pwd = print working directory = print your current location (also known as .)
    • ls -l gives you complete directory listing, ls -a lets you see .prefix-files
    • mkdir to create a new directory, rmdir to remove an existing one
  • Environment variables: export (bash, sh) or setenv (tcsh, csh)
    • Variables that are local to the shell are defined with set
    • Env variables are inherited by shells started in the parent shell
    • Type set to see locals, env to see environment
  • To view an environment variable: echo $varname
    • PATH - list of directories to search when you ask the shell to run a program
    • LD_LIBRARY_PATH - list to search for shared libraries
  • To add a directory to the path: export PATH=$PATH:/opt/intel/bin
  • Move, copy, remove files: mv, cp, rm
  • To view the contents of a file: cat filename
    • cat = “concatenate to standard output”, stdout is the terminal by default
  • Redirect stdout using symbols
    • cat file1 > file2 replaces (clobbers) file2 with the contents of file1
    • cat file1 >> file2 appends file2 with the contents of file1
    • cmd1 | cmd2 to pipe stdout of cmd1 to stdin of cmd2
  • Text editors: nano, vi, emacs
    • Terminal window becomes plain text editor
    • No graphical interface, all editing done via special key sequences
  • Controlling processes
    • control sequences: ctrl-c = kill, ctrl-z = suspend
    • bg to put process in background, fg to bring to foreground, jobs to see bg list
  • For more tips and tricks...