Created by Gavin Mogan / @halkeye
$ man find
$ help for
$ ls --help
$ pwd
/home/gavinm
$ echo $PWD
/home/gavinm
$ cd /apps/habitat_media
$ cd /apps/habitat\ media
$ cd "/apps/habitat media"
$ pwd
/home/gavinm
$ cd /home/gavinm/Develop
$ pwd
/home/gavinm/Develop
$ cd -
$ pwd
/home/gavinm
$ cd ~
/home/gavinm
$ cd ~eti
/home/eti
$ cd
/home/gavinm
Simple Directory Listing
$ ls
Long Listing
$ ls -l
Descending(r) by Time(t)
$ ls -ltr
Hidden files
$ ls -a
Head will give you the first n lines
$ head -n 2 /var/log/nginx/presentations.gavinmogan.com.access.log
presentations.gavinmogan.com:80 108.172.217.87 - - [24/Jun/2015:07:02:03 +0000] "GET /stats/ HTTP/1.1" 200 5566 "http://odin.kodekoan.com:4080/halkeye/gavinmogan.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36" "108.172.217.87"
presentations.gavinmogan.com:80 108.172.217.87 - - [24/Jun/2015:07:02:03 +0000] "GET /stats/css/reveal.css HTTP/1.1" 200 48591 "http://presentations.gavinmogan.com/stats/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36" "108.172.217.87"
Tail will give you the last n lines
$ tail -n 2 /var/log/nginx/presentations.gavinmogan.com.access.log
presentations.gavinmogan.com:80 162.158.64.218 - - [27/Jun/2015:03:35:46 +0000] "HEAD / HTTP/1.1" 403 166 "-" "Mozilla/5.0 (compatible; CloudFlare-AlwaysOnline/1.0; +http://www.cloudflare.com/always-online)" "162.158.64.218"
presentations.gavinmogan.com:80 162.158.64.218 - - [27/Jun/2015:03:35:46 +0000] "GET / HTTP/1.1" 403 345 "-" "Mozilla/5.0 (compatible; CloudFlare-AlwaysOnline/1.0; +http://www.cloudflare.com/always-online) AppleWebKit/534.34" "162.158.64.218"
Common Options
Output to file
$ echo "hi" > file.txt
Errors to file
$ curl http://fake.server 2> errors.txt
Input from file
$ mysql < import.sql
$ tail -F ~/Develop/*/logs/development.log
Will look find all directories that have a logs directory underneath it.
$ tail -F ~/Develop/*/logs/*.log
Will find all log files under all directories that have a log directory (one level deep)
$ ls /apps/local/{nginx,ruby}
It is the same as:
$ ls /apps/local/nginx /apps/local/ruby
$ mkdir [a-e]
Makes a,b,c,d,e directories
find is super powerful, Check man pages
Find all directories
$ find -type d
Find all files
$ find -type f
Find all files ending in log
$ find -name '*.log'
$ find -name '*.log' -exec ls {} \;
$ find -name '*.log' -exec ls {} +
With a few combos you can do anything
Filter out text
grep
Pull out parts of a line
ack / cut
Reorder items
uniq / Sort
Loops
for
grep /favicon.ico access.log
long output
grep /favicon.ico access.log | awk '{print $17}'
AppleWebKit/537.36
grep /favicon.ico access.log | awk -F'"' '{print $6}'
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
Add sort and uniq pipes
$ yum install tig
You need to be root to perform this command.
$ sudo !!
$ sudo yum install tig
Literally who is logged in to this box right now.
Lists user accounts and when they log in.
$ who
Lists who is online and what they are doing.
$ w
Curl and wget work kinda the same, but under different designs.
Wget is great at downloading files.
$ wget http://i.imgur.com/Ia48QDR.jpg
Curl is better at retrieving content.
$ curl http://jenkins/job/test-workflow/api/json?pretty=true
for i in $(seq 1 10); do echo $i; done
for i in gavin likes pie; do mkdir $i; done
for i in *; do mv $i $i.bak; done
Sed, perl, python, etc
I prefer perl pie
$ echo "Gavin likes Pie" > file.txt
$ perl -pi -e 's/Gavin/Phil/' file.txt
$ cat file.txt
Run a script in debug mode
$ bash -x script.sh
Enable debugging right now
$ set -x
What are ssh keys?
Why would you want them?
How do you use them?
man ssh_config