Linux Terminal Cheat Sheet

#linux #cybersecurity

Commonly used commands

This quick reference helps you get familiar with the following basic Linux commands:

Common Operators used in commands

Important

  • | - The pipe symbol, pipe the output of one command to another
  • || - this does in fact not mean double pipe, this means OR, if a specified command fails, execute the other. run A || run B, will run either A or B.
  • >> - Append to a file preserving it's existing content
  • > - Append and overwrite contents of a file
  • < - Known as input redirection, take the input from somewhere, example: cat < fileA.txt will display the contents of fileA.txt
  • << - Here document, takes multiple lines of input to the given command and when the given keyword is types ends the command Example: cat > output.txt <<END, will allow you to type multiple lines in the command until you type END to close.
  • = - standard assignment operator, assigns a variable a value
  • ! - this means not, as in != means does not equal.
  • ; - will allow you to run multiple commands in a single line, this simply separates them
  • \ - escape character to allow you to display characters uninterrupted.
  • & - run command and send task to background


Usage Syntax for the commands above

Most of the syntax for how to use the commands above is as simple as just using the man pages for each respective command. They will indicate usage syntax and any flags you have to type and other operators you need to use with it.

A rule of thumb regarding flags is

User and Group Management

usermod -aG sales jdeng.

sudo useradd jdeng
sudo groupadd sales
sudo usermod -aG sales jdeng
sudo tail /etc/group | grep sales

Piping output from one command to another

This command displays the contents of file A and then pipes it's output to grep to search for a specific string inside the file.

cat fileA.txt | grep fileAText

The same can be done with directories

ls | grep Documents

This lists the current working directories folders and files and then pipes it to grep to look for a file of folder called documents.

This can also be done using the

Electric Meatball's Digital Garden Home
Permissions
User and Group Permissions Cheat Sheet