Linux Commands | Introduction to Linux | Basic Linux Commands

Check the Total Number of Words and Lines in a File

wc [option] [file path/name to inspect]

wc stands for word counts. It shows totals such as the number of words and lines in a file.

Options

  • -l lines
  • -w words

Check the Absolute Path of a Linux Command

which [Linux command]

which shows the absolute path of a Linux command.

Search for a Specific Pattern in a File

grep [pattern] [file name to search]

grep tells you where a specific pattern appears in a file.

Pattern example: “dump”

Change the Current User

su [ID]

su stands for substitute user. It changes the user account currently being used. (ID change)

Specify Input and Output

> or >> [input/output device]

Redirection lets you directly specify an input or output device.

  1. cat test.txt > 1.txt overwrites 1.txt with the output of cat test.txt.
  2. cat test.txt >> 1.txt appends the output of cat test.txt to 1.txt.
  3. The command cat test.txt is equivalent to cat test.txt >. If nothing follows >, the output is printed to the screen.

Run Linux Commands in Sequence

| (the character next to the Backspace key)

A pipeline connects Linux commands. It is used when running several commands together.

For example:

cat test.txt | head -1