Linux Commands

Commands

Directory Controls

cd, ls, pwd, cp, mv, mkdir, rmdir, locate, history, clear, touch, exit


View File Contents

cat, less, more, tail


Process Controls

pid, kill, sleep


Text Editors

vi, vim, nano

Exit Nano - CTRL + X (god forbid I end up in this forsaken editor) Save Changes - CTRL + O


Bash Shebang

#!/bin/bash


| pipe |

Connects STDOUT to STDIN for a following command.

For simplification sake, performs "then use that output to do this"


> greater than >

Redirect STDOUT to a file. Can create a new file, or will append new output to end of an existing file.


echo

Prints output

echo [option] [string] (string in quotations)


Options

-e Enable backslash escapes (table below)

Use variable - echo "$VARIABLE"

e.g. 'echo "$USER" > username.txt' saves the value of the user variable to a txt file named username


grep

Regex Search - print lines that match patterns.

grep [OPTION] PATTERNS [FILE]


Matching Options

-f [FILE] or files separated by spaces

-i Ignore Case

-v Invert Match (select non-matching lines)

-w Select matches containing whole words

-x Select matches that exactly match the whole line

-r recursive search for directory.

e.g. grep -r "admin" site --include \*.js searches the 'site' folder for admin but only checks .js files (\* is wildcard)


Output Options

-c only prints count of matching lines for each input file

-l only prints name of each input file that contains match

-L only prints name of each input file that doesn't contain a match


chmod

Changes Permissions of file or folder

+ or - adds or removes permissions in symbolic notation

r(ead) w(rite) x(ecute)

Octal Notation kinda complicated - 777 grants everything e.g. 'chmod 777 foo' grants all users full permissions to file foo


compgen

Lists names of available things

Options

-c all commands

-a aliases

-b builtins

-d directories

-f files

-g groups

-j jobs

-k shell reserved words

-s services

-u user names

-v shell variables

Escape Sequence Represents
\a Bell (alert)
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark