HOW TO BE A TERMINAL PRO - 100 COMMANDS TO KNOW https://code.tutsplus.com/courses/how-to-be-a-terminal-pro and https://code.tutsplus.com/courses/advanced-command-line-techniques
In the SHELL:
- echo "hello world" or with with options echo -n "hello world"
- ctrl a and ctrl e (start and end of line)
- Up key for previous command
- !! for repeating previous command
- tab and double tab
- ~ (home directory)
- clear
- man echo (manual for each command)
- pwd (print working directory)
- cd .. and cd folder (clear directory)
- ls directory1 directory2 or ls -lat (list, all, time)
- open . (open current directory)
- open -a "Sublime Text 2" beans.txt (open beans.txt with application sublime)
- open http:aljazeera.com/interactive (open website)
- "file name" or file\ name (escaping spaces)
- Drag file into terminal for path (super useful)
- open -R file.txt (reveal)
- killall Finder (reopen filder)
- touch anewfile.txt (make a new file) or touch directory/anewfile.txt (make a new file in this directory)
- nano afile or vim afile or vi afile
- mkdir newdirectory
- cp beans1.txt beans2.bak (copy a backup) or cp -r beans1 beans2 (copy recursive)
- mv afile adirectory (rename a file) or mv afile adirectory/afilenew (move a file to a new directory)
- mv file* adir/ (globbing)
- cat anewfile.txt (view the contents)
- rm santa.txt (remove it) or rm -r santa (remove and remove recursive)
- rmdir (delete a directory) could also use rm -r (to delete a folder)
- ln -s beans1 beans2 (soft symbolic link to point to another)
- ln beans1 beans2 (hard shortcut link)
- find . -name "*.txt" (search current directory)
- find . -type f (find all the files)
- find . -iname "beans" (case insensitive file)
- find . -size +2048 (1mb size files)
- find . -mtime -1 (-atime -ctime) (modified, access, created)
- find . -iname ".txt" -or -iname ".doc" -and mtime -1 (.doc or .txt file last modifiend one day ago)
- find . -prune -print (only find direct children)
- grep "hello" afile.txt (shows you which line in the code)
- grep -ilr "hello" * (find all "hellos") (-i case insensitive -l just the files -r recursively)
- find . -name "*.txt" -exec grep -il "Hello" {} ; (grep and find at the same time)
- -rw-r--r-- js staff - file, user, group, anyone else
- drwxrwxrwx (everyone has access to read, write and execute on the directory)
- chmod u+w (user) or chmod g+w (group) or chmod o+w (others) or chmod a+w(anyone)
- chmod og-x afile.txt (take execution rights from othrs and from the group)
- chmod u=rw,g=r,o=, text.txt (user can rw, group can r, others can do nothing)
- chmod 644 text.txt (444 is equal to read for everyone)(4 read, 2 write, 1 execute)(700 user can do everything everyone else nothing)
- Nano poem.txt (arrow keys, control k to cut, control u to paste, control o to save file, control x to exit)
- vim index.php (normal mode or insert mode)
- vim NORMAL MODE (beginning gg) (shift curly brace - moves to the end of paragraph) (^ beginning of line or $ end of line) (shift colon - :set number, :syntax on, :5 (line 5), :) (shift o or shift O add a new line) (shift s - wipe out lines) (shift r - replace text) (dd - delete) (p - paste) (yy - copy) (%s/print/echo/g) (up and down arrows in :) (:w newname.php) (:wq)
- vim INSERT MODE (you escape with esc) (u - undo ) (ctrl r - redo)
- vim ~/.rc (type in set number, syntax on, set ignorecase)
- MAKING TAR FILES
- tar -zxvf nameoftar.tar.gz (unzip)
- cd nameoftar (open)
- ./configure (dot slash configure)
- make (make the files)
- make install (make install the files)
- nameoftar --version (now check it worked)
- echo "hello world" > afile.txt (append to a file >>)
- ls fakefile 2> log (save to a log)
- ls documents >> log 2>&1
- translate tr a e
- tr a e < afile.txt (replace all a's with e's in this file)
- PIPING - ls -a | grep "." (only find hidden files and directories)
- top (sample of processes on your mac)(exit with q)
- top -o cpu (order by CPU usage)
- ps -cvx (c- name, x- owned by user, v- other info)(process statuses)
- ps -cvx | grep "Google" (finds all Google processes)
- term 35157 (quits Google Chrome)
- kill -s KILL 35178 (force quits)
- ssh-keygen -t rsa (creates id_rsa, id_rsa.pub, known hosts)
- scp id_rsa.pub [email protected]:~/.ssh/authorized_keys (securely copy to the remote server)
- login user2
- (dont' overwrite the pubkey) cat id_rsa.pub |ssh [email protected] "cat >> ~/.ssh/authorized_keys"
- SSH host alias (cd .ssh, nano config, Host server, Hostname 10.1.1.1, User Haddad)
- scp file1.txt server:~/remote
- sftp server
- lpwd (locally print out my working directory)
- put file1.txt
- get random.txt (exit or quit)
- curl (supports many protocols)(scrapes web pages or get files)
- curl http://aljazeera.com > afile.html
- curl -Of http://aljazeera.com (fail silently)
- nano .bash_profile - function helloworld(){ echo "hello, $1"}
- SHELL SCRIPTS - nano newSite.sh (#!/bin/bash) (chmod +x newSite.sh)(./newSite.sh someexample)
- sudo cp /usr/local/bin (super user do)
- echo $PATH
- alias runthis="ssh [email protected]"