Moving Around CLI: Job Management: ls – List directory contents (ls –ltra) ./command.sh & - & forces to run in bkgrnd mkdir – Make directory jobs – Lists jobs running rmdir – Remove directory fg – Will bring job to foreground cp – Copy file/directory (cp –a) bg – Forces job to background rm – Remove file/directory (rm –rf) nohup process & - Process will run post logout mv – Move files/dirs or rename Ctrl-z – Suspends task touch – Create empty file, update time stamp Saving Sessions: Working with Text: screen / tmux – Allows a user to have multiple shells echo – Echoes back text to terminal or file on one connection, can disconnect and re-attach to cat – Concatenate, print a file out, top down it later tac – Print a file out, bottom up head – Print the top xx lines out (–n 100) Network Essentials: tail – Print the last xx lines out (–f) ifconfig – Lists network adapters/IP info more – Print text, page per page ip address – Lists network adapters/IP info less – Like more, ability to go line by line ping ip/dnsname – See if you can reach IP diff – Compare contents of files/directories traceroute/tracepath – Show hops to IP nslookup google.com – Lookup IP address Text Parsing Tools: netstat: Show ports (netstat -nap), processes grep – Searches for text strings listening on ports, (netstat –nr) shows default sort – Will sort text output gateway uniq – Condenses text to unique instances systemd-resolve –status – Shows DNS servers wc – Word count (or line count) cut – Extract data from delimited output Process Elevation: sudo command – Elevates a single command More Advanced Text Tools: su – Super user, change to root (su -) awk – Manipulates data and generates reports su – username – Switch user to specified user sed – Stream editor, text transformation id – Shows current user and group membership
File System/Disk Information: Bash History Management: df – Disk Free (-h) history – Lists last 1000 commands du – Disk Usage (--max-depth=1 –h) cat ~/.bash_history - Same as history lsblk – List block devices (-f) !### - Runs command number from history find – Find files (find / -name search*) Ctrl-r – Reverse search in history which – Where is the binary locate – Optional package (updatedb) Help: man – Manual pages File/Directory Permissions: command –help – Shows available flags chown – Change owner/group of file/dir info – Bash manual chmod – Change file/dir modes Permissions for chmod: IO Redirection: 4 – (R)ead > - Redirect output to file 2 – (W)rite >> - Add redirected output to file 1 – E(x)ecute | - Out one program into another Ex. 7 = RWX 5 = R-X 4 = R-- Bash Envionment: Process Management: env – List all environmental variables ps - Process list (ps fax) set – Set a variable top - System monitor, Sort by (M)em, C(P)U export – Export variable kill xxx - Kill process PID, get from ps or top killall process_name - Kill process name
Bash Shortcuts (Pico/Nano): Ubuntu (Debian) Package Management: Ctrl-a – Beginning of line apt – Pull dependencies/packages from Internet Ctrl-c - Cancel dpkg – Debian Package manager, more local Ctrl-e – End of line To upgrade: Ctrl-k - Cut from cursor forward apt update Ctrl-y – Paste the cut apt upgrade Ctrl-p – Back (up arrow) Other useful commands: Ctrl-n – Next in CLI history (down arrow) apt search packagename Ctrl-l – Clear screen apt install packagename Ctrl-s – Freezes the screen apt remove packagename Ctrl-q – Will unlock your screen apt list –installed Ctrl-h – Backspace replacement dpkg –i localpackage.deb Ctrl-d – Delete or logout (on empty line) Tab – Command line completion Redhat/CentOS/Fedora RPM Package Mgmt: Shift Insert - Highlight paste yum – YellowDog Update Manager, like apt Shift Pg-Up – Scroll up in terminal dnf – New version of Yum Shift Pg-Down – Scroll down in term rpm – Redhat package manager To upgrade: vi/vim Text Editor Shortcuts: yum update Command Mode (Escape key): Other useful commands: Arrow keys to move (may not work with vi) yum install packagename h – Back (left arrow) yum whatprovides somelibrary j – Next line (down arrow) yum search packagename k – Previous line (up arrow) yum remove packagename l – Forward (right arrow) rpm –Uvh package.rpm – Updates/installs pkg dd – Delete line (type 10 before will del 10 lines) rpm –e package – Removes package yy – Yank line (also accepts a number before) rpm –qa – List all packages p – Paste line rpm –qif /some/file – Tells you what pkg file u – Undo rpm –qil package – List files in package / - Search, n for next, p for previous :1 – First line, xx number to that line number :$ - End of File :w – Write :wq – Write & quit :w filename.txt – Write to a specific name :q! – Quit without writing vi/vim Edit Mode ((a)ppend or (i)nsert): Works much like notepad, escape to return to command mode.