Command Line Study Guide

From Code Self Study Wiki
Jump to: navigation, search

Basic GNU/Linux terminal commands to know as a minimum. Use the man to read the documentation for any command. Example: to read the documentation for the ls command, type man ls in a terminal. Also search Google.

  • ls -- list directory contents. Also ls -l, ls -R, and ls -al.
  • cd -- change directory
  • cp -- copy files
  • mv -- move a file or directory. Also for renaming things
  • mkdir -- make a directory
  • rm -- remove a file. Also rm -rf, but very dangerous. See this story for a warning on how dangerous it can be.
  • rmdir --- remove a directory
  • touch -- create a new empty file
  • pushd -- move to another directory with a bookmark (actually a stack of directories you've jumped from, so you can use it multiple times)
  • popd -- jump back to the place where you pushd'd from
  • pwd -- show current location
  • clear -- clear the terminal. Also ctrl-l
  • less -- display output with pagination
  • vim -- type vimtutor and see Vim
  • nano -- simple console editor
  • cat -- display a file and/or concatenate it
  • top -- show processes. If you like that, install htop.
  • man -- read the built-in documentation
  • locate -- find files. E.g., sudo updatedb; locate *.desktop
  • find -- find files. E.g., find / -name '*.desktop'
  • grep -- search files and directories
  • tree -- e.g., tree -d >> outputfile.txt. You may need to install it first.
  • tar, zip, gzip -- manage archives
  • wc -- count things: lines, bytes, characters, words, etc. Example: wc -l filename.txt will count the lines in a file.
  • tee -- redirect the output to a file and the screen at the same time. E.g., ls -1 *.py | wc -l | tee count.txt which counts the number of Python files in your directory, writes it to the screen, and saves it to a file.
  • kill --
  • ps --
  • locate --
  • find --
  • shutdown --
  • reboot --
  • uptime --
  • chmod --
  • chown --
  • du --
  • df --
  • head --
  • tail --
  • diff --
  • date --
  • df --
  • sleep --
  • which --
  • apropos -- can't remember a command? Use this to find commands about a keyword, like: apropos wireless
  • ping --
  • dig --
  • traceroute --

Also:

  • tab completion
  • pipes (|), >, and >>
  • aliases
  • ctrl-r -- reverse search
  • keyboard shortcuts: ctrl-u, ctrl-k, ctrl-a, ctrl-e, alt-f, alt-v, ctrl-d, alt-d (from Emacs)

And Tmux.

Additional Utilities

Some of these may need to be installed.

  • sort -- sorts items
  • uniq -- gets only unique items
  • mc -- Midnight Commander file browser
  • tr -- translate
  • fold -- wrap lines to a specified width
  • jq -- tools for JSON
  • curl -- do stuff with URLs
  • wget -- download pages and sites
  • sql2csv (npm install -g sql2csv)
  • csvkit (pip install csvkit)
  • xml2json (git clone it and add to path)
  • ImageMagick -- process and view images, e.g., display cat_pic.jpg, convert --resize 200x200 giant_hubble_photo.jpg hubble_photo_thumb.jpg
  • rename -- bulk rename files with regular expressions. Example: rename all files with the extension .GIF to .gif: rename -v 's/\.GIF$/\.gif/' *.GIF
  • lynx -- a browser in your terminal.

You will occasionally come across these:

  • sed -- stream editor for filtering and transforming text
  • awk -- pattern scanning and processing language
  • Perl one line scripts

See also 7 command-line tools for data science.

See also GNU Coreutils Manual