Quick tip: searching your shell history

My boss recently shared a great tip for performing a reverse search of your shell history. The next time you’re trying to remember a command you recently typed in terminal. Try the key stroke combination of Ctrl + r.

Typing Ctrl + r in your terminal will prompt you for a search string, and the first result it matches in your history will be returned. If the match is not correct, you can add more characters to make the search more specific, or type Ctrl + r again, and the next valid match will be displayed.

Note: The filtered search results may include the string in any portion of a history log entry, and are not limited to the beginning characters of each log entry. This also means that if multiple matches exists in a single log entry, Ctrl + r will move the search cursor to the next match in the same entry.

Search and Replace in vi

I frequently edit documents in vi and one task that’s often required is searching and replacing text. To search and replace text, you can use the substitute command :s, which follows the pattern :[range]s/{search-string}/{replacement-string}/[flags].

Example of range values:

  • % – indicates the search should occur with all lines
  • 4 – indicates the search should occur on line 4
  • 2,8 – indicates the search will occur from line 2 to line 8

Examples of flag values:

  • g – make the replacement if the text is found for all instances
  • c – ask for confirmation of a change
  • i – not case sensitive
  • I – case sensitive
  • e – don’t report error messages if no match is found

Usage examples:

Find and replace


Find and replace all instances on the current line


Find and replace all instances from line 5 to line 7 upon confirmation


Find and replace with case sensitivity throughout the entire document


To learn more about the substitute command, open vi and type :help :s

Checking available and used disk space

Two useful terminal commands for checking disk usage in Linux, are the commands df and du.

The first command, df, provides a table of file systems with information on free and used disk space. Note: Using the -h option provides the table in a human readable format.

df -h

The second command, du, can also retrieve disk usage information. Typing du into any directory will provide a list of files and directories at the specified location with their corresponding disk usage. However du may be more useful with the options -s and -h providing a human readable summary of the specified location on disk.

eg. display disk usage for the current working directory

du -hs

or at a specified directory

du -hs directoryname