From e4118b1585cda4f74694cb1895d4af6b061e9b6b Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Mon, 10 Feb 2014 12:36:05 -0800 Subject: [PATCH] A bunch of new pages: common/: dig, gzip, rm, sort, zfs, zpool linux/: apt-get, shutdown osx/: airport, caffeinate, diskutil, networksetup open, pgrep, qlmanage, say, shutdown, sysctl, system_profiler Edits to existing pages: curl: Added simple download example find: Added iname and size exmaples grep: Edited -c description ps: Added wide lines example ssh: edited -D description, added simple port forwarding example unzip: added list option --- common/curl.md | 4 ++++ common/dig.md | 15 +++++++++++++++ common/find.md | 6 ++++++ common/grep.md | 2 +- common/gzip.md | 23 +++++++++++++++++++++++ common/ps.md | 4 ++++ common/rm.md | 15 +++++++++++++++ common/sort.md | 15 +++++++++++++++ common/ssh.md | 6 +++++- common/unzip.md | 4 ++++ common/zfs.md | 27 +++++++++++++++++++++++++++ common/zip.md | 2 +- common/zpool.md | 33 +++++++++++++++++++++++++++++++++ linux/apt-get.md | 24 ++++++++++++++++++++++++ linux/shutdown.md | 16 ++++++++++++++++ osx/airport.md | 15 +++++++++++++++ osx/caffeinate.md | 13 +++++++++++++ osx/diskutil.md | 23 +++++++++++++++++++++++ osx/drutil.md | 12 ++++++++++++ osx/lookupd.md | 15 +++++++++++++++ osx/networksetup.md | 19 +++++++++++++++++++ osx/open.md | 23 +++++++++++++++++++++++ osx/pgrep.md | 15 +++++++++++++++ osx/qlmanage.md | 11 +++++++++++ osx/say.md | 14 ++++++++++++++ osx/shutdown.md | 13 +++++++++++++ osx/sysctl.md | 24 ++++++++++++++++++++++++ osx/system_profiler.md | 15 +++++++++++++++ osx/systemsetup.md | 24 ++++++++++++++++++++++++ 29 files changed, 429 insertions(+), 3 deletions(-) create mode 100644 common/dig.md create mode 100644 common/gzip.md create mode 100644 common/rm.md create mode 100644 common/sort.md create mode 100644 common/zfs.md create mode 100644 common/zpool.md create mode 100644 linux/apt-get.md create mode 100644 linux/shutdown.md create mode 100644 osx/airport.md create mode 100644 osx/caffeinate.md create mode 100644 osx/diskutil.md create mode 100644 osx/drutil.md create mode 100644 osx/lookupd.md create mode 100644 osx/networksetup.md create mode 100644 osx/open.md create mode 100644 osx/pgrep.md create mode 100644 osx/qlmanage.md create mode 100644 osx/say.md create mode 100644 osx/shutdown.md create mode 100644 osx/sysctl.md create mode 100644 osx/system_profiler.md create mode 100644 osx/systemsetup.md diff --git a/common/curl.md b/common/curl.md index fd01697dab..c3505a0744 100644 --- a/common/curl.md +++ b/common/curl.md @@ -3,6 +3,10 @@ > Transfers data from or to a server > Supports most protocols including HTTP, FTP, POP +- Download a URL to a file + +`curl "{{URL}}" -o filename` + - send form-encoded data `curl --data {{name=bob}} {{http://localhost/form}}` diff --git a/common/dig.md b/common/dig.md new file mode 100644 index 0000000000..fab845bd3a --- /dev/null +++ b/common/dig.md @@ -0,0 +1,15 @@ +# dig + +> DNS Lookup utility + +- Lookup the IP(s) associated with a hostname (A records) + +``dig +short {{hostname.com}} + +- Lookup the mail associated with a given domain name (MX records) + +``dig +short {{hostname.com}} MX + +- Specify an alternate DNS server to query (8.8.8.8 is google's public DNS) + +`dig @8.8.8.8 {{hostname.com}}` diff --git a/common/find.md b/common/find.md index f5f1756eb1..1712d6891e 100644 --- a/common/find.md +++ b/common/find.md @@ -15,3 +15,9 @@ - find files modified since a certain time `find {{root_path}} -name {{'*.py'}} -mtime {{-1d}}` + +- find files using case insensitive name matching, of a certain size + +`find {{root_path}} -size +120k -iname {{'*.dOC'}} ` +`find {{root_path}} -size -100M -iname {{'*.moV'}} ` +`find {{root_path}} -size -1.2T -size +800G -iname {{'*.TaR.gZ'}} ` diff --git a/common/grep.md b/common/grep.md index cef3d8e5b1..c6cb5badba 100644 --- a/common/grep.md +++ b/common/grep.md @@ -19,7 +19,7 @@ `grep -C 3 {{something}} {{file_path}}` -- print the number of matches +- print the count of matches instead of the matching text `grep -c {{something}} {{file_path}}` diff --git a/common/gzip.md b/common/gzip.md new file mode 100644 index 0000000000..a4d90d4701 --- /dev/null +++ b/common/gzip.md @@ -0,0 +1,23 @@ +# gzip + +> Compress/uncompress files with gzip compression (LZ77) + +- compress a file, replacing it with a gzipped compressed version + +`gzip {{file.ext}} + +- decompress a file, replacing it with the original uncomrpessed version + +`gzip -d {{file.ext.gz}} + +- compress a file specifying the output filename + +`gzip -c {{file.ext}} > compressed-file.ext.gz + +- uncompress a gzipped file specifying the output filename + +`gzip -c -d {{file.ext.gz}} > uncompressed-file.ext + +- specify the compression level. 1=Fastest (Worst), 9=Slowest (Best), Default level is 6 + +`gzip -9 -c {{file.ext}} > compressed-file.ext.gz` \ No newline at end of file diff --git a/common/ps.md b/common/ps.md index 6f472f5e50..15f7e5a851 100644 --- a/common/ps.md +++ b/common/ps.md @@ -5,3 +5,7 @@ - list all running processes `ps aux` + +- list all running processes including the full command string + +`ps auxww` diff --git a/common/rm.md b/common/rm.md new file mode 100644 index 0000000000..d3bf1745e7 --- /dev/null +++ b/common/rm.md @@ -0,0 +1,15 @@ +# rm + +> Remove files or directories + +- Remove files from arbitrary + +`rm {{/path/to/file}} {{/otherpath/to/file2}}` + +- Remove recursively a directory and all it's subdirectories + +`rm -r {{/path/to/folder}}` + +- Prompt before every removal + +`rm -i *` \ No newline at end of file diff --git a/common/sort.md b/common/sort.md new file mode 100644 index 0000000000..62d6bcc361 --- /dev/null +++ b/common/sort.md @@ -0,0 +1,15 @@ +# sort + +> sort lines of text files + +- Sort a file in ascending order + +`sort {{filename}}` + +- Sort a file in descending order + +`sort -r {{filename}}` + +- Sort passwd file by the 3rd field + +`sort -t: -k 3n /etc/passwd ` diff --git a/common/ssh.md b/common/ssh.md index 06efdcb023..19c08159b9 100644 --- a/common/ssh.md +++ b/common/ssh.md @@ -11,6 +11,10 @@ `ssh {{username}}@{{remote_host}} -P {{2222}}` -- ssh tunneling +- ssh tunneling: dynamic port forwarding (SOCKS proxy on localhost:9999) `ssh -D {{9999}} -C {{username}}@{{remote_host}}` + +- ssh tunneling: forward a specific port (localhost:9999 to slashdot.org:80) + +`ssh -L {{9999}}:slashdot.org:80 {{username}}@{{remote_host}}` diff --git a/common/unzip.md b/common/unzip.md index a335b86187..0b394bdc66 100644 --- a/common/unzip.md +++ b/common/unzip.md @@ -9,3 +9,7 @@ - extract zip files(s) to given path `unzip {{files(s)}} -d {{/path/to/put/extracted/files}}` + +- list the contents of a zip file without extracting + +`unzip -l {{file}} diff --git a/common/zfs.md b/common/zfs.md new file mode 100644 index 0000000000..493cc28524 --- /dev/null +++ b/common/zfs.md @@ -0,0 +1,27 @@ +# zfs + +> Manage ZFS filesystems + +- List all available zfs filesystems + +`zfs list` + +- Create a new ZFS filesystem + +`zfs create poolname/newfsname` + +- Delete a ZFS filesystem + +`zfs destroy {{poolname/newfsname}}` + +- Create a Snapshot of a ZFS filesystem + +`zfs snapshot {{poolname/filesystem@snapshot-name}} + +- Enable compression on a filesystem + +`zfs set compression=on {{poolname/fileystem}} + +- Change mountpoint for a filesytem + +`zfs set mountpoint={{/my/mount/path}} {{poolname/filesystem}} \ No newline at end of file diff --git a/common/zip.md b/common/zip.md index 2aea58557f..53d623b577 100644 --- a/common/zip.md +++ b/common/zip.md @@ -1,6 +1,6 @@ # zip -> package and compress (archive) files into zip file +> Package and compress (archive) files into zip file - package and compress multiple directories & files diff --git a/common/zpool.md b/common/zpool.md new file mode 100644 index 0000000000..7acdb9692f --- /dev/null +++ b/common/zpool.md @@ -0,0 +1,33 @@ +# zpool + +> Manage ZFS pools + +- Show the configuration and status of all ZFS zpools + +`zpool status [{{poolname}}]` + +- Check a ZFS pool for errors (verifies the checksum of EVERY block). Very CPU and disk intensive. + +`zpool scrub {{poolname}}` + +- List zpools available for import + +`zpool import` + +- Import a zpool, optionally specifying a new name + +`zpool import {{poolname}}` +`zpool import {{poolname}} {{newpoolname}}` + +- Export a zpool (unmount all filesystems) + +`zpool export {{poolname}}` + +- Show the history of all pool operations + +`zpool histrory {{poolname}}` + +- Create a mirrored pool. + +`zpool create {{poolname}} mirror {{disk1}} {{disk2}}` +`zpool create {{poolname}} mirror {{disk1}} {{disk2}} mirror {{disk3}} {{disk4}}` diff --git a/linux/apt-get.md b/linux/apt-get.md new file mode 100644 index 0000000000..30e18f3665 --- /dev/null +++ b/linux/apt-get.md @@ -0,0 +1,24 @@ +# apt-get + +> Debian and Ubuntu package management utility + +- Synchronize list of packages and versions available. This should be run first, before running subsequent apt-get commands. + +`apt-get update` + +- install a new package + +`apt-get install {{package}}` + + +- remove a package + +`apt-get remove {{package}}` + +- Upgrade installed packages to newest available versions + +`apt-get upgrade` + +- Upgrade installed packages (like `apt-get upgrade`) including removing obsolete packages and installing additional packages to meet new package dependencies. + +`apt-get dist-upgrade` diff --git a/linux/shutdown.md b/linux/shutdown.md new file mode 100644 index 0000000000..7e156721cf --- /dev/null +++ b/linux/shutdown.md @@ -0,0 +1,16 @@ +# shutdown + +> Shutdown and reboot the system + +- Reboot or poweroff (halt) the system immediately + +`shutdown -r now` +`shutdown -h now` + +- Reboot in 5 minutes. + +`shutodwn -r +5 &` + +- Cancel a pending shutdown/reboot operation + +`shutdown -c` \ No newline at end of file diff --git a/osx/airport.md b/osx/airport.md new file mode 100644 index 0000000000..141eb19a3d --- /dev/null +++ b/osx/airport.md @@ -0,0 +1,15 @@ +# Airport + +> Airport utility + +- Create a symlink so you can easily run 'airport' without specifying a path. + +`sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport` + +- Scan for available wireless networks + +`airport -s` + +- Disassociate from current airport network + +`sudo airport -z` diff --git a/osx/caffeinate.md b/osx/caffeinate.md new file mode 100644 index 0000000000..eb05c2467f --- /dev/null +++ b/osx/caffeinate.md @@ -0,0 +1,13 @@ +# caffeinate + +> Prevent a system from sleeping + +- Prevent mac from sleeping for 1 hour (3600 seconds) + +`caffeinate -u -t 3600` + +- Prevent mac from sleeping until a command completes + +`caffeinate -s {{command}}` + + diff --git a/osx/diskutil.md b/osx/diskutil.md new file mode 100644 index 0000000000..a2de64b845 --- /dev/null +++ b/osx/diskutil.md @@ -0,0 +1,23 @@ +# diskutil + +> Utility to manage local disks and volumes + +- List all currently available disks, partitions and mounted volumes. + +`diskutil list` + +- Repair permissions on a volume + +`diskutil repairPermissions {{/Volumes/Name}}` + +- Repair the file system data structures of a volume + +`diskutil repairVolume {{/dev/diskX}} + +- Unmount a volume + +`diskutil unmountDisk {{/dev/diskX}}` + +- Eject a CD/DVD (unmount first) + +`diskutil eject {{/dev/disk1}} diff --git a/osx/drutil.md b/osx/drutil.md new file mode 100644 index 0000000000..f3157d2230 --- /dev/null +++ b/osx/drutil.md @@ -0,0 +1,12 @@ +# drutil + +> Interact with DVD burners + +- Eject a disk from the drive + +`drutil eject` + +- Burn a folder as an ISO9660 filesystem onto a DVD. Don't verify and eject when complete. + +`drutil burn -noverify -eject -iso9660` + diff --git a/osx/lookupd.md b/osx/lookupd.md new file mode 100644 index 0000000000..141eb19a3d --- /dev/null +++ b/osx/lookupd.md @@ -0,0 +1,15 @@ +# Airport + +> Airport utility + +- Create a symlink so you can easily run 'airport' without specifying a path. + +`sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport` + +- Scan for available wireless networks + +`airport -s` + +- Disassociate from current airport network + +`sudo airport -z` diff --git a/osx/networksetup.md b/osx/networksetup.md new file mode 100644 index 0000000000..7a64403a82 --- /dev/null +++ b/osx/networksetup.md @@ -0,0 +1,19 @@ +# networksetup + +> Configuration tool for Network System Preferences + +- List available network service providers (Ethernet, Wi-Fi, Bluetooth, etc) + +`networksetup -listallnetworkservices` + +- Show network settings for a particular networking device + +`networksetup -getinfo {{"Wi-Fi"}}` + +- Get currently connected Wi-Fi network name (Wi-Fi device usually en0 or en1) + +`networksetup -getairportnetwork {{en0}}` + +- Connect to a particular Wi-Fi network + +`networksetup -setairportnetwork {{en0}} {{"Airport Network SSID"}} {{password}} diff --git a/osx/open.md b/osx/open.md new file mode 100644 index 0000000000..317b48949e --- /dev/null +++ b/osx/open.md @@ -0,0 +1,23 @@ +# open + +> Opens files, directories and applications + +- Open a file with the associated application + +`open filename.ext` + +- Run a graphical MacOSX application + +`open /Applications/iTunes.app` + +- Open the current directory in Finder + +`open .` + +- Reveal a file in finder + +`open -R /path/dir/file` + +- Open all the word docs in the current directory with Microsoft Word + +`open *.doc` \ No newline at end of file diff --git a/osx/pgrep.md b/osx/pgrep.md new file mode 100644 index 0000000000..f7684d1917 --- /dev/null +++ b/osx/pgrep.md @@ -0,0 +1,15 @@ +# pgrep + +> Find or signal process by name + +- return PIDs of any running processes with a matching command string + +`pgrep {{Finder}}` + +- case insensitive greping + +`pgrep -i {{fireFOx}} + +- kill all processes which match + +`pkill -9 {{Finder}} diff --git a/osx/qlmanage.md b/osx/qlmanage.md new file mode 100644 index 0000000000..b1831ff797 --- /dev/null +++ b/osx/qlmanage.md @@ -0,0 +1,11 @@ +# qlmanage + +> QuickLook server tool + +- displays QuickLook for one or multiple files + +`quicklook -p {{filename}} {{filename2}}` + +- Compute 300px wide PNG thumbnails of all JPEGs in the current directory and put them in a directory. + +`quicklook *.jpg -t -s 300 {{/existing//thumbnail/directory}} diff --git a/osx/say.md b/osx/say.md new file mode 100644 index 0000000000..bd56d9a948 --- /dev/null +++ b/osx/say.md @@ -0,0 +1,14 @@ +# say + +> Uses text to speech to speak through the default sound device + +- Speak a phrase aloud + +`say "I like to ride my bike.` + +- Speak a file aloud + +`say -f {{filename}}` + +- Create an AAC compressed audio file with the spoken text +`say -o {{filename.m4a}} "Everyone loves iTunes"` diff --git a/osx/shutdown.md b/osx/shutdown.md new file mode 100644 index 0000000000..eb8a53d725 --- /dev/null +++ b/osx/shutdown.md @@ -0,0 +1,13 @@ +# shutdown + +> Shutdown and reboot the system + +- Reboot, poweroff (halt) or sleep immediately + +`shutdown -r now` +`shutdown -h now` +`shutdown -s now` + +- Reboot in 5 minutes. + +`shutodwn -r +5` diff --git a/osx/sysctl.md b/osx/sysctl.md new file mode 100644 index 0000000000..ca21de6b2d --- /dev/null +++ b/osx/sysctl.md @@ -0,0 +1,24 @@ +# sysctl + +> Access kernel state information + +- Show all available variables and their values + +`sysctl -a` + +- Show Apple model identifier + +`sysctl -n hw.model` + +- Show CPU model + +`sysctl -n machdep.cpu.brand_string` + +- Show available CPU features (MMX, SSE, SSE2, SSE3, AES, etc) + +`sysctl -n machdep.cpu.feature` + +- Set a changeable kernel state variable + +`sysctl -w name=value` +`sysctl -w kern.maxfiles=15000` diff --git a/osx/system_profiler.md b/osx/system_profiler.md new file mode 100644 index 0000000000..3362707fde --- /dev/null +++ b/osx/system_profiler.md @@ -0,0 +1,15 @@ +# system_profiler + +> Report system hardware and software configuration + +- Display a full system profiler report which can be opened by System Profiler.app + +`system_profiler -xml > MyReport.spx` + +- Display a hardware overview (Model, CPU, Memory, Serial, etc) + +`system_profiler SPHardwareDataType` + +- Print the system serial numebr + +`system_profiler SPHardwareDataType|grep "Serial Number (system)" |awk '{print $4}'` diff --git a/osx/systemsetup.md b/osx/systemsetup.md new file mode 100644 index 0000000000..49e3598173 --- /dev/null +++ b/osx/systemsetup.md @@ -0,0 +1,24 @@ +# systemsetup + +> Configure System Preferences machine settings + +- Enable remote login (SSH) + +`systemsetup -setremotelogin on` + +- Specify TimeZone, NTP Server and enable network time + +`systemsetup -settimezone {{US/Pacific}}` +`systemsetup -setnetworktimeserver {{us.pool.ntp.org}}` +`systemsetup -setusingnetworktime on` + +- Make the machine never sleep; restart on freeze & power failure + +`systemsetup -setsleep off` +`systemsetup -setrestartpowerfailure on` +`systemsetup -setrestartfreeze on` + +- List valid startup disks, specify a new startup disk + +`systemsetup -liststartupdisks` +`systemsetup -setstartupdisk {{path}}`