Common Linux Commands

For more information on any of the below commands, use ‘man‘ plus the command
NOTE:  man is a program and may need to be installed before its use.

history | xargs | find | cat | tac | join | paste | expand | od | sort | split | tr | unexpand | uniq | fmt | nl | pr | head | tail | more | less | cut | wc | grep | sed


  • history — displays a numbered account of the latest commands but the user
    • [ Ctrl+R ] begin a backward (reverse) search
    • [ Ctrl+S ] searches forward, after you’ve used the backward search
    • [ Ctrl+G ] — terminates the search
    • history commands are stored in the .bash_history file in the home directory
    • typing ‘history’ shows the latest 500 commands
    • you can execute a command from history by typing ‘!’ and the number (ex. !258)
    • typing ‘history -c’ clears the history file
  • xargs — builds a command from its Standard Input (stdin).
    • Used with a ‘pipe’ and a command before ‘xargs’
  • find — searches the given directory for a given sequence of characters
  • cat — a tool for combining files (usually through a redirect of ‘>’)
    • commonly used to view the contents of a file
    • [ -E ] used to see where lines end by placing a dollar sign ‘$’ at the end of each line
    • [ -n ] used to add line numbers to the beginning of each line
    • [ -b ] similar to -n but only adds numbers to lines that contain text
    • [ -s ] compresses groups of blank lines down to a single blank line (referred to as a squeeze)
    • [ -T ] will display tab characters as ‘^’
    • [ -v ] displays most control and other special characters using the carat ‘^’
  • tac — similar to cat but it reverses the order of lines in the output
  • join – combines two files by matching the contents of specified fields within the files
    • [ -t char ] is a char option that allows you to specify which character is to be used in the joining preference
    • by default, join uses the first field as the one to match across files
    • [ -1, -2 ] can be specified to join fields for the first or second file respectively
    • [ -o ] gives a myriad of formatting options to make the command more complex
  • paste — merges files line by line, separating the lines from each file with tabs
  • expand — converts tabs to spaces
    • assumes that tabs stop every eight characters
    • [ -t ] will specify the spacing value
  • od — called octal dump, it displays a file in an unambiguous format (base-8 by default)
    • should be well versed in octal notation and ASCII code
  • sort — sorts data according to specified arguments
    • [ -f ] ignores uppercase or lowercase when using sort
    • [ -M ] causes the program to sort by three-letter month abbreviations (JAN, FEB, MAR, etc…)
    • [ -n ] sorts by number
    • [ -r ] sorts by reverse order
    • [ -k + field (3) ] uses the specified field to sort by
  • split — splits a file into two or more files
    • [ -b ] splits by bytes
    • [ -C=size] used to break files of no more than the specified size without breaking lines across files
    • [ -l (el) ] split by numbers of lines wanted in the new file (default is 1000 lines)
  • tr — changes individual characters from Standard In (stdin)
    • specify the characters you want replaced in a group (set1) and the replacement chars (set2)
    • usually used via Standard In (stdin) using a redirect ‘<‘
  • unexpand — converts multiple spaces to tabs
    • [ -t ] used to specify tab length (default is 8 chars)
  • uniq — removes duplicate lines within a file
  • fmt — formats a file by cleaning up paragraphs which it assumes are delimited by two or more blank lines

    • [ -w char ] sets the line length to width characters
  • nl — a more complex way of numbering lines (compared to the ‘cat’ command)
    • [ -b ] set the numbering style for the bulk of lines
    • [ -h or -f ] sets the style for the header or footer sections if the file is formatted for printing
    • [ -d=code ] tell the ‘nl’ command how to identify a new page (code is the char for the new page)
    • [ -p ] will not reset the numbering to 1 for each page
    • [ -n format ] format is either ‘ln’ or ‘rn’ or ‘rz’ to specify right, left, zero justification
    • Body, Header, or Footer styles can be specified
      • [ t ] defaults to number lines that aren’t empty
      • [ a ] causes all lines to be numbered
      • [ n ] causes line numbers to be omitted
      • [ pPATTERN ] causes only lines that match a specific pattern to be numbered
  • pr — prepares a file for printing (formats the headers, footers, and page breaks)
    • [ -numcols ] creates multiple columns (this does not reformat the text)
    • [ -d ] causes double-spaced output
    • [ -f ] causes a form-feed character between pages (used with certain printers)
    • [ -l (el) ] specifies the length of a page in lines
    • [ -h ] sets the text to be displayed in the header which replaces the file name in the header
    • [ -o ] sets the left margin to a specific length
    • [ -w ] specifies the width which has a default of 72 characters
  •  head — shows the first few lines of a file (default is 10 lines)
    • [ -c ] shows the specified number of bytes
    • [ -n ] shows the specified number of lines
  • tail — shows the last few lines of a file (default is 10 lines)
    • [ -c ] shows the specified number of bytes
    • [ -n ] shows the specified number of lines
    • [ -f ] keeps the file open showing the new lines that are added
    • [ –pid=PID ] stops the -f after the program with the specified PID closes
  • more — enables you to read a file one screen at a time
  • less — enables you to read a file one screen at a time, but is more capable than the ‘more’ command
    • [ spacebar ] moves forward through a file
    • [ esc + V ] moves backward through a file
    • [ / ] searches a file’s contents (‘n’ searches forward, ‘N’ searches backward)
    • [ ? ] searches backward (opposite of the ‘/’ key)
    • [ g + number ] moves to a specific line
    • [ q ] quits the program
    • [ h ] displays the internal less help screen
  • cut — extracts portions of input lines and displays them on Standard Out (stdout)
    • [ -b + list ] cuts the specified list of bytes from the input file
    • [ -c + list ] cuts the specified list of characters from the input file (usually identical to -b)
    • [ -f + list ] cuts the specified list of fields from the input file (default is the tab delimited section)
    • [ -d + char ] cuts the specified list of characters (same as -f but uses a character instead of tab)
    • [ -s ] changes the behavior so that the program doesn’t echo lines that don’t contain the delimiter
    • commonly used on scripts to display specific data
    • commonly used with a pipe (ex. ‘ifconfig ethic | grep HWaddr | cut -d ” ” -f 11’)
  • wc — produces a word, line, and byte count for a file
    • limit the output to lines (-l), words (-w), bytes (-c), characters (-m), or max line length (-L)
  • grep — searches a file that contains a specific string and returns the name of the file and the line
    • [ -c ] displays the number of lines that match the specific pattern
    • [ -f ] takes a pattern from a separate file for the search
    • [ -i ] ignores upper or lower case in the search
    • [ -r ] recursively searches a specified directory (can use ‘rgrep’ instead)
  • sed — directly modifies the contents of files, sending the changes to Standard Out (stdout)
    • [ = ] displays the current line number
    • [ a\text ] appends text to the file
    • [ i\text ] inserts text into the file
    • [ r filename ] appends text from specified file into the current file
    • [ c\text ] replaces the selected range of lines with provided text
    • [ s/regexp/replacement ] replaces text of regexp (regular expression) with replacement
    • [ w filename ] writes the current pattern space to the specified file
    • [ q ] immediately quits the script, but prints the current pattern space
    • [ Q ] immediately quits the script
Scroll to top