Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Linux Commands Cheat Sheet

Image Removed

Basic linux commands you need to know

...

Here's a copy of the cheat sheet we passed out.

Image Added

File system navigation

  • ls - list the contents of the current directory
  • pwd - print the present working directory - which restaurant am I at right now - the format is something like /home/myID - just like on most computer systems, this represents leaves on the tree of the file system structure, also called a "path".
  • cd <whereto> - change the present working directory to <whereto> - pick up my drive-thru window (shell) and move it so that I'm now looking thru to the directory <whereto>
    • Some special <wheretos>: .. (period, period) means "up one level". ~ (tilde) means "my home directory". ~myfriend (tilde "myfriend) means "myfriend's home directory".

Displaying file contents

...

  • file <file> tells you what kind of file <file> is.
  • mkdir <dirname> and rmdir <dirname> make and remove the directory "dirname". This only removes empty directories - "rm -r <dirname>" will remove everything.
  • rm <file> deletes a file. This is permanent - not a "trash can" deletion.

Displaying file contents

  • head <file> and tail <file> shows you the top or bottom 10 lines of a file <file>
  • more <file> and less <file> both display the contents of <file> in nice ways. Read the bit above about man to figure out how to navigate and search when using less
  • file <file> tells you what kind of file <file> is.
  • cat <file> outputs all the contents of <file> - CAUTION - only use on small files.rm <file> deletes a file. This is permanent - not a "trash can" deletion.

Copying files and directories

  • cp <source> <destination> copies the file source to the location and/or file name destination}. Using . (period) means "here, with the same name". * cp -r <dirname> <destination> will recursively copy the directory dirname and all its contents to the directory destination.
  • scp <user>@<host>:<source> <destination> works just like cp but copies source from the user user's directory on remote machine host to the local file destination
  • mkdir <dirname> and rmdir <dirname> make and remove the directory "dirname". This only removes empty directories - "rm -r <dirname>" will remove everything.
  • wget <url> fetches a file with from a valid URL. It's not that common but we'll use wget to pull data from one of TACC's web-based storage devices.

Miscellaneous commands

df shows you the top level of the directory structure of the system you're working on, along with how much disk space is available

Getting around in the shell

...

  • completing file or directory names up to any ambiguous part
  • it works for commands (like "ls" or "scp") and for completing file or directory names.

...

Up arrow

Use "up arrow" to retrieve any of the last 500 commands you've typed. You can then edit them and hit enter (even in the middle of the command) and the shell will use that command.

Ctrl-a, Ctrl-e

You can use control-a (holding down the "control" key and "a") to jump the cursor right to the beginning of the line. The omega to that alpha is control-e, which jumps the cursor to the end of the line. Arrow keys work, and control-arrow will skip by word forward and backward.

Advanced topic: command line editors.

Exercise:

...

Wildcards and special file names

The shell has shorthand to refer to groups of files by allowing wildcards in file names. * (asterisk) is the most common; it is a wildcard meaning "any length of any characters". Other useful ones are [] to allow for any character in the set <characters>> and {{[] for a range of characters.

For example: ls *.bam lists all files in the current directory that end in .bam; ls [A-Za-z]*.bam does the same, but only if the first character of the file is a capital letter.

Three special file names:

  1. . (single period) means "this directory".
  2. .. (two periods) means "directory above current." So ls -l .. means "list contents of the parent directory."
  3. ~ (tilde) means "my home directory".

 

Environment variables

...

Environment variables are just like variables in a programming language (in fact bash is a complete programming language), they are "pointers" that reference data assigned to them. In bash, you assign an environment variable like this:

...

Man pages - linux has had built-in help files since the mid-1500's, way before Macs or PCs thought of such things. In linux they're called man pages - short for "manual"; it's not a gender thing (I assume). man intro will give you an introduction to all user commands.

Exercise:

Try "man grep", or "man du", or "man sort" - you'll want these sometime.

Tip: Type the letter q to quit man, j and k/<CR> to move up and down by line, b or spacebar up/down by page. Want to search? Just hit the slash key /, enter the search word and hit enter. These are actually the tools of the less command which man is using.

Wildcards and special file names.

The shell has shorthand to refer to groups of files by allowing wildcards in file names. * (asterisk) is the most common; it is a wildcard meaning "any length of any characters". Other useful ones are [] to allow for any character in the set <characters>> and {{[] for a range of characters.

For example: ls *.bam lists all files in the current directory that end in .bam; ls [A-Za-z]*.bam does the same, but only if the first character of the file is a capital letter.

Three special file names:

...

 

Exercises:

Scavenger hunt practice; on Lonestar issue the following commands:

...