-----------------------------------------------------------------
Title           : UNIX COMMAND CHEATSHEET
Date            : 2018-10-26
Last updated    : 2018-10-30
Word count      : 835
-----------------------------------------------------------------

=== NAVIGATION ===

[tab]           : autcomplete file or director based on unique characters
[ctrl + e]      : navigate to the end of a line
[ctrl + a]      : navigate to the beginning of a line
[ctrl + k]      : delete line from cursor
[ctrl + ->]     : jump forward by word
[ctrl + <-]     : jump backwards by word

=== FILE SYSTEM ===

pwd     : displays present working directory (current directory)

ls      : list files and folders
ls -l   : list items in current directory and show in long format to see perimissions, size, and modification date
ls -a   : list items in current directory including hidden items
ls -lh  : list long format with readable file size
ls -s   : list items by file size
ls -S   : sort items by file size
ls -t   : sort items by time and date
ls -r   : list items in reverse order
ls -t   : sort by time and date

cd dir          : change directory to dir
cd ..           : navigate up one directory
cd /            : go to root directory
cd ~            : go to home directory
cd -            : go to last directory you were in

mkdir dir       : create a directory called dir
rm dir          : remove directory
rm -r dir       : remove directory recursively
rm file         : remove file
mv file file1   : rename file to file1
cp file dir     : copy file to directory

cat file                : output the contents of a file
cat file file1          : output the contents of multiple files
cat file | more         : output contents of file with paginated more links
cat -n file             : output contents of file with line numbers
cat file > file1        : output contents of file into file1
cat file >> file1       : append contents of file onto the end of file1
less file               : view file with file viewer
head file               : output first 10 lines of a file
tail file               : output last 10 lines of a file
tail -f file            : output the contents of file as it grows, starting with the last 10 lines

sed s/old/new file              : substitute string 'old' for 'new' in file
sed s/old/new file1 > file2     : substites string 'old' for 'new' in file1 and outputting to file2

# for a full explanation of sed commands visit http://www.grymoire.com/Unix/Sed.html

=== SYSTEM TOOLS ===

clear           : clears screen
history         : ouputs contents of bash_history file
history 5       : ouputs last 5 commands from bash_history
history -d 1    : deletes command from history line 1
history -c      : clear history of commands
history -w      : write the current history to the history file and append them to the history list
[alt + d]       : display counts for words, lines and characters on screen
man command     : view manual for a given command
date            : display date
date -s         : display date as a string
date +%A        : display full weekday string
date +%B        : display full month string
date +%D        : display full numeric date
date +%c        : displays full date and time
date +%r        : displays locale's time
date +%T        : displays time
date +%Z        : Alphabetic time zone abbreviation (e.g. EST)

whoami          : displays logged-in user
finger user     : displays information about a user
sync            : The sync program can be called to ensure that all disk writes have been completed before the processor is halted


source file             : executes the content of file
alias                   : displays a list of the user's alias commands
alias command-command   : creates an alias command

// example: alias list-"ls -la"
// this creates a new command called "list" which executes the ls command with the arguments -la
// alias commands only persist for the duration of that login session.
// to create permanent alias commands, add them to the .bashrc file in your home directory. Then append 'source ~/.bashrc' to your .profile file. Restart your session

unalias command         : removes the alias command
unlias -a               : removes all aliases

=== SEARCHING ===

grep string file        : search for a string or pattern in a file
grep -i string file     : search for a case insensitive string or pattern in a file
grep -r pattern dir     : search recursively for a pattern in a given directory
find file               : find all instances of file in real system
locate file             : find all instances of file using indexed database built from the updatedb command. Much faster than find

=== COMPRESSION ===

gzip file                               : compress a file to a .gz archive file
gzip -d file                            : decompress a .gz archive file
tar -cvf file.tar file1 file2 file3     : combines multiple files into a single .tar archive file
tar -xvf file.tar                       : separates a .tar archive file into separate files
tar -cvzf file.tar.gz file1 file2       : creates a .tar archive file and compresses it into a .gz archive file with gzip
tar -xvzf file.tar.gz                   : unzip a tar.gz file

=== PERMISSIONS ===

chmod XXX dir   : change permissions for directory
chmod XXX file  : change permissions for file

=== NETWORKING ===

ping host       : ping a host service and output results
whois domain    : lookup a domain
dig domain      : lookup dns information for a domain