Teaching myself Command Line

So main thing I want to do here is to re-enforce for myself what each of the various commands do that Makers have listed as priority to learn.

  • date — prints the current dat, time and time zone
  • ls — list everything in active directory. ls -lA lists all hidden files as well, in long format (combined ls -l and ls -A commands)
  • pwd — “print working directory”, prints the full path to the active directory
  • cd — change directory, cd .. changes to one directory up
  • touch — create a new file in active directory
  • mkdir — “make directory”, create a new directory under active directory
  • rmdir — “remove directory”, remove target directory
  • rm — “remove”, remove target file. Needed to remove directory with files inside using rm -r somedir (recursively removes files from within the directory). rm -i prompts you for each file and rm -f force removes each file even if “write protected”
  • cp — “copy”, format is cp originFile newFile
  • mv — “move”, format is mv originFile endPath
  • cat — “concatenate”, main function is to combine files, but can be used to write data to files and view them in command line
  • less — allows you to view larger documents in the command line, allowing you to scroll up and down using the keyboard to view the entire document. When finished use q to escape
  • head — lets you view purely the top x lines of a document (specified in the format head -x fileName, default to 10)
  • tail — lets you view the last x lines of a document (specified in the format tail -x fileName, default to 10)
  • man — “manual” format of man function, gives you information about a different command
  • find — search command, format of find (location such as .) -name “fileName” -print , will search through all sub-directories of specified location
  • grep — searches inside files, format of grep regex files (can be wildcarded)
  • wc — “word count”, outputs 3 numbers — lines, words, characters
  • whoami — find out what your name is on the computer
  • chmod — allows you to change file permissions, format chmod (group)(+/- )(permissions) fileName — so chmod a-rx readme.txt would remove read and execute priviledges from all users
  • sudo — execute a command with root access
  • echo — view any single environment variable
  • export — Allows you to modify PATH, adding environmental variables as necessary
  • ps — lists all the processes launched
  • env — lists all environment variables
  • ruby — execute Ruby program
  • pgrep — search through active processes which match all the selection criteria (pgrep -u root ssh will only match processes called ssh and are owned by root)

Pipes and Redirection

This is taking a bit to sink into my head currently, so I am just going to ramble for a bit to help it sink in.

The way that pipes ( | ) appear to work is to allow commands to become inputs, the example given was “ cat combined | less” — which should output the file combined in less format instead, allowing you to move around the file as if it were a normal file.

You appear to be able to redirect file outputs using the greater-than symbol (>) allowing you to specify the output stream of a command.


Using the * symbol, you can specify which files will appear for various commands (such as ls or find)


(NB this is focusing on permissions in UNIX — if you are using a different system your mileage may vary)

From what I have read, there are three classes of user, and three permissions that can apply to each.


  • “User” — defines permissions belonging to the owner
  • “Group” — defines permissions that apply toe a group of users
  • “Others” — Any that do not fit into first two classes


  • Read — allows the file to be read / the directory’s contents to be listed
  • Write — allows a user to write to a file / or create, delete and rename files in a directory
  • Execute — allows a user to execute a file.

These are shown in the “long” directory format (ls -l) with a 10 character string at the start of a line e.g. -rwxrw-r- -. Looking at the structure above this can be read as follows:

First character is either blank or d, denoting if it is a file or a directory. The next three relate to the “User” class — in the example granting read, write and execute. Then follows three characters for the “Groups” class — granting read and write, and finally the three for the “Others” class.