Last active
July 31, 2020 19:07
-
-
Save demoive/1fb18a74defe724a47aa to your computer and use it in GitHub Desktop.
Reference for commands/utilities for use in CLI on Unix and Mac OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use: | |
# .bash_profile - only gets executed for login bash shells | |
# .bashrc - only gets executed for NON-login bash shells for only NON-login shells | |
# .profile - gets executed for ANY login shell | |
# .bash_logout - only gets executed for bash shells after logout | |
# Sets the prompt: | |
#PS1='\h:\w \u\$ ' | |
#PS2='> ' | |
#PS1='[\!] \h:\w \$ ' | |
# \a - The ASCII bell character (you can also type \007) | |
# \d - Date in "Wed Sep 06" format | |
# \e - ASCII escape character (you can also type \033) | |
# \h - First part of hostname (such as "mybox") | |
# \H - Full hostname (such as "mybox.mydomain.com") | |
# \j - The number of processes you've suspended in this shell by hitting ^Z | |
# \l - The name of the shell's terminal device (such as "ttyp4") | |
# \n - Newline | |
# \r - Carriage return | |
# \s - The name of the shell executable (such as "bash") | |
# \t - Time in 24-hour format (such as "23:01:01") | |
# \T - Time in 12-hour format (such as "11:01:01") | |
# \@ - Time in 12-hour format with am/pm | |
# \u - Your username | |
# \v - Version of bash (such as 2.04) | |
# \V - Bash version, including patchlevel | |
# \w - Current working directory (such as "/home/pravila") | |
# \W - The "basename" of the current working directory (such as "pravila") | |
# \! - Current command's position in the history buffer | |
# \# - Command number (this will count up at each prompt, as long as you type something) | |
# \$ - If you are not root, inserts a "$"; if you are root, you get a "#" | |
# \xxx - Inserts an ASCII character based on three-digit number xxx (replace unused digits with zeros, such as "\007") | |
# \\ - A backslash | |
# \[ - This sequence should appear before a sequence of characters that don't move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly. | |
# \] - This sequence should appear after a sequence of non-printing characters. | |
# These "defaults" commands help adjust (usually hidden) settings in Mac OS X | |
# defaults domains | |
# defaults read [domain] | |
# defaults read-type [domain] [key] | |
# defaults delete [domain] [key] | |
# Dock | |
# defaults write com.apple.dock no-glass -boolean [yes] - doesn't use the deafult glass tray look of Leopard when Dock is on the bottom | |
# defaults write com.apple.dock mineffect -string [suck] - defines the minimization effect of windows | |
# defaults write com.apple.dock pinning -string [middle | start | end] - defines the alignment of the dock | |
# defaults write com.apple.dock orientation -string [top] - defines location of the dock | |
# defaults write com.apple.dock showhidden -boolean [yes] - enable transparent icons for hidden applications | |
# defaults write com.apple.dock showshadow -boolean [yes] - show dock shaddow | |
# defaults write com.apple.dock AppleShowAllFiles -boolean [yes] - show hidden items in folders and disks | |
# defaults write com.apple.dock largesize -int [512] - change magnification size | |
# defaults write com.apple.dock single-app -boolean [yes] - toggles only one program visible (same as Cmd + Opt + clicking a program in the dock) | |
# Finder | |
# defaults write com.apple.finder AppleShowAllFiles -boolean [yes] - show hidden files in finder | |
# defaults write com.apple.finder ProhibitEmptyTrash -boolean [yes] - prohibits the Trash from being emptied (prank) | |
# defaults write com.apple.finder CreateDesktop -int 0 - no icons displayed on desktop (prank) | |
# Expose | |
# defaults write com.apple.dock wvous-floater -boolean [yes] - shows the useless "Expose blob" | |
# defaults write com.apple.dock wvous-showcorners -boolean [yes] - shows the active screen corners of Expose | |
# defaults write com.apple.dock wvous-olddesktop -boolean [no] - defines the "desktop" feature of Expose (buggy) | |
# Dashboard | |
# defaults write com.apple.dashboard mcx-disabled -boolean [yes] - disables the dashboard | |
# Safari | |
# defaults write com.apple.Safari IncludeDebugMenu -bool [yes] - show Debug menu | |
# defaults write.com.apple.Safari WebIconDatabaseEnabled -bool NO - dissable favicons | |
# iTunes | |
# defaults write com.apple.iTunes invertStoreLinks -bool YES - little arrows search your library rather than the Music Store (v4.5) | |
# Global (USE WITH CAUTION) | |
# defaults write com.apple.screencapture type -string [extension] - file type that screen shot is saved as (bmp/gif/jpg/jp2/pdf/pict/png/psd/sgi/tga/tiff) | |
# defaults write com.apple.screencapture location -string [path] - location screenshot is saved | |
# defaults write com.apple.screencapture name -string [name] - name of file | |
# killall SystemUIServer; open /System/Library/CoreServices/SystemUIServer.app/ | |
# defaults write -g AppleScrollBarVarient -string DoubleMin - put both scroll arrows on top (left) | |
# defaults write -g AppleScrollBarVarient -string DoubeMax - put both scroll arrows on bottom (right) | |
# defaults write -g AppleScrollBarVarient -string DoubleBoth - put both scroll arrows on both sides | |
# defaults write -g AppleScrollBarVarient -string Single - put single scroll arrows | |
# Login Window (USE WITH CAUTION) | |
# defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText -string "Login Greeting" | |
# defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText-FontSize -int 12 | |
# defaults write /Library/Preferences/com.apple.loginwindow Kiosk -int 1 - doesn't allow anyone to shutdown/restart/logout (unless: sudo shutdown -h now) | |
# defaults write /Library/Preferences/com.apple.loginwindow RetriesUntilHint -int 1 - 0 means won't ever show hints | |
# defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "/Path/to/picture/you/want/to/use/image.jpg" | |
# (note, you can click on the grayed txt above greeting to see different info about the computer) | |
# Good Finder Keyboard Shortcuts: | |
# Ctr+F2 Access Apple Menu Toolbar | |
# Cmd+Shift+C Open Computer | |
# Cmd+Shift+H Open Home Directory | |
# Cmd+Shift+A Open Applications Folder | |
# Cmd+Shift+U Open Utilities Folder (Open URL in Camino) | |
# Cmd+Shift+G Go to... | |
# Cmd+Shift+Y Open up Stickies | |
# Cmd+Shift+F Perform Spotlight search on highlighted txt | |
# Cmd+Shift+L Open up Safari (searches highlighted txt with Google) | |
# Cmd+Shift+K Open Networks | |
# Cmd+Shift+C Open Computer | |
# Cmd+Shift+I Connect to iDisk | |
# Cmd+Opt+D Toggle Dock hiding | |
# Universal Access | |
# Cmd+Opt+* Turn on Zoom | |
# Cmd+Opt++ Zoom in | |
# Cmd+Opt+- Zoom out | |
# Cmd+Opt+Ctr+* Negative colors on screen | |
# Ctr+F1 Turn on Full Keyboard Access (allows the following commands): | |
# Ctr+F2 Focus to Apple Menu | |
# Ctr+F3 Focus to Dock | |
# Ctr+F4 Toggle between all windows | |
# Ctr+F5 Focus to Toolbar | |
# Ctr+F6 Focus to Utility Palette (if open in an application) | |
# Cmd+D Duplicate | |
# Cmd+L Create an Alias | |
# Cmd+R Show Original | |
# Cmd+Opt+Eject Sleep | |
# Cmd+Ctr+Eject Restart | |
# Cmd+Opt+Ctr+Eject Shutdown | |
# Cmd+Shift+Q Logout | |
# Cmd+Opt+Shift+Q Immediate Logout | |
# Startup | |
# Cmd+V - Verbose Mode: shows console messages during boot & shutdown | |
# Cmd+S - Single User Mode | |
# Shift - Safe Mode: disables login items and non-essential kernel extensions | |
# C - Boot from internal CD-ROM drive | |
# D - Boot from internal disc (if the default boot device has been set to something else) | |
# X - Force Mac OS X Start up | |
# N - Boot from Network | |
# T - Boot into Firewire Target Mode (boots as external HD when connected to another machine) | |
# Mouse Button - Eject floppy disc before starting up | |
# Cmd+Opt+O+F - Boot into "Open Firmware" mode to configure various properties of your system related to booting. | |
# ls - lists the devices below the current node in the device tree (similar to ls in a filesystem) | |
# pwd - lists the location of the current node in the device tree (similar to pwd in a filesystem) | |
# printenv - prints the current and default values of the settings in the Open Firmware environment | |
# eject fd - eject a floppy disk | |
# eject cd - eject the CD-ROM drive | |
# shut-down - permanently store the Open Firmware environment variables and power down the computer | |
# mac-boot - Boot Mac OS on an Open Firmware 3 system | |
# Classic UNIX multi-user login mode | |
# At the OS X login window, type | |
# >console | |
# for the user and leave the password field blank. | |
# Hide the menu bar and dock for any application. | |
# Add the following 2 lines to the "info.plist" of any Cocoa application | |
# right below the <dict> entry: | |
# | |
# <key>LSUIPresentationMode</key> | |
# <integer>4</integer> | |
# fs_usage | |
# tidy | |
# tidy -ic -asxhtml -wrap 9999 -o out.html in.html | |
# tidy -ic -asxhtml -wrap 9999 -m replace.html | |
# System Preference Titles | |
# /Applications/System Preferences.app/Contents/Resources/English.lproj/NSPrefPaneGroups.strings | |
# Dock files | |
# /System/Library/CoreServices/Dock/Contents/Resources | |
# Extract all the email addresses from the Address Book | |
# sqlite3 ~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb "select ZADDRESSNORMALIZED from ZABCDEMAILADDRESS;" | sort | uniq | |
# Location of the default wallpaper | |
# /System/Library/CoreServices/DefaultDesktop.jpg | |
# Terminal login greeting: | |
# /etc/motd | |
# Batch changes in vim | |
# vim -c "argdo %s/ABC/DEF/ge | x" *.c | |
# vim -e -s file.txt < thefilter | |
# runs screen saver as desktop (use kill to stop) | |
# /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background & | |
# show your routing table | |
# netstat -r -f inet -n | |
# backup | |
# cd ~/ | |
# rsync -n -auEv --delete --exclude=/.Trash/ --exclude=/Music/ ./ /Volumes/iPaul/bkup/Tiger/ | grep -v "/._" | grep -v "/$" | tee /Volumes/iPaul/bkup/2006.05.08.log | |
# Show Login Window (Lock Computer) | |
# /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend | |
# http://www.macworld.com/weblogs/macosxhints/2007/03/peekinstall/index.php?lsrc=mwrss | |
# List the contents of an installer file | |
# (inside the "Content" folder of a package: | |
# | |
# lsbom Archive.bom | more | |
# or | |
# gzip -cd archive.pax.gz | pax | more | |
# Applescript | |
# do shell script "rsync -aE --delete "What to backup" "Where to backup" || echo -n" | |
# redirect specific outputs on the command line shell (with sh) | |
# | |
# 1> stdout | |
# 2> stderr | |
# 0> stdin | |
# | |
# ls > file 2>&1 send stderr (2) to the same place as stdout(1) | |
# ls 1>file1 2>file2 redirect stdout to file1 and stderr to file2 | |
# ls >&output.txt redirect both stdout & stderr | |
# | |
# Great system monitoring commands (originally used in Geektool) | |
# top -FR -cd -o cpu -n 7 -l2 | tail -n14 | |
# ps -racx -o command,%cpu | head -n7 | grep -v '%' | |
# netstat -ab -f inet | grep -i 'established' | sort +4 | |
# grep -h "^$(date '+%m/%d')" /usr/share/calendar/calendar.* | cut -f2 | |
# ps -arcx -o %cpu,command | awk ' { if (FNR <= 6 && $1 != "%CPU" && $1 != "0.0") { printf("%c%c%3.1f%% ", ($1 < 100 ? " " : ""), ($1 < 10 ? " " : ""), $1); for (i= 2; i <= NF; i++) { printf("%s ", $i); } printf("\n"); } }' | |
# ifconfig | grep "inet [0-9]" | grep -v 127.0.0.1 | awk '{print $2}'; ifconfig | grep "ether" | awk '{print $2}' | |
# ifconfig en1 | grep " active" (en1 is usually airport, en0 is ethernet) | |
# Airport Stregnth meter: | |
# while x=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done | |
# | |
# The value is in dBm, which is a logarithmic scale so that an increase of 10 | |
# units means a factor of 10 increase in power; an increase of 20 means a factor | |
# of 100 increase in power; etc. Watching this reading, I was able to position | |
# the router and antenna for maximum signal strength at various places in the | |
# shed. | |
# calendar -f /usr/share/calendar/ | |
# /usr/share/misc/ | |
# create iso disk image from file/directory | |
# hdiutil makehybrid -verbose -iso -joliet -o <target.iso> <directory> | |
# Hides a file from showing up in the finder. | |
# /Developer/Tools/SetFile -a V /Volumes/Untitled/ | |
# /Developer/Tools/SetFile -a v /Volumes/Untitled/ | |
# telnet towel.blinkenlights.nl | |
# for user installed binaries, put them in /usr/local/bin (and add to PATH) | |
# man curl_unescape | |
# man getopt | |
# man iswalnum, iswalpha, iswascii, iswblank, iswcntrl, iswdigit, iswgraph, iswhexnumber, iswideogram, iswlower, iswnumber, iswphonogram, iswprint, iswpunct, iswrune, iswspace, iswspecial, iswupper, iswxdigit | |
####### Fricken really useful (and probably not well known) ####### | |
# tidy - validate, correct, and pretty-print HTML files | |
# expand/unexpand - expand tabs to spaces, and vice versa ( | |
# fmt - simple text formatter | |
# aspell - NOT INCLUDED WITH OS | |
# htpasswd - Create and update user authentication files | |
# textutil - manipulate text files ( textutil -convert html /Users/Paulo/Desktop/ProjectOutline.rtf ) | |
# ( textutil -convert txt /Users/Paulo/Desktop/ProjectOutline.rtf ) | |
# pstopdf - convert PostScript input into a PDF document | |
# enscript - convert text files to PostScript ( enscript -E --color -Whtml --toc -p OUTPUT.html *.h *.c ) | |
# ( enscript -G2rE -U2 -p OUTPUT.ps INPUT.c ) | |
# ( enscript -B -E --color -p - INPUT.FILE | pstopdf -i -o OUTPUT.pdf ) | |
# ( textutil -stdout -convert txt INPUT.rtf | enscript -B -E --color -p - | pstopdf -i -o OUTPUT.pdf ) | |
# lsbom - list contents of a bom file | |
# pax - read and write file archives and copy directory hierarchies | |
# zipgrep - search files in a ZIP archive for lines matching a pattern | |
# sips - scriptable image processing system | |
# nmap - network port scanner (NOT INCLUDED WITH OS) | |
# vmstat - display virtual memory statistics (NOT INCLUDED WITH OS) | |
# readefl - show information and statistics about a designated elf binary (NOT INCLUDED WITH OS) | |
# watch - run a command repeatedly, at specified time intervals (NOT INCLUDED WITH OS) | |
# size - print the size of the sections in an object file | |
# curl - transfer a URL | |
# lynx - NOT INCLUDED WITH OS | |
# links - NOT INCLUDED WITH OS | |
# split - split a file into pieces | |
# cat - concatenate and print files | |
# cmp - compare two files byte by byte | |
# uniq - report or filter out repeated lines in a file | |
# bc - arbitrary precision calculator language | |
# dc - an arbitrary precision calculator (reverse-polish) | |
# units - conversion program | |
# expr - evaluate expression | |
# look - display lines beginning with a given string | |
# dd - convert and copy a file | |
# find - walk a file hierarchy ( find / -name '\.DS_Store' -exec rm -f {} \; ) | |
# ( find ~ -name \.DS_Store ) | |
# ( find ~ -name *\.app -type d ) | |
# tee - pipe fitting | |
# strings - find the printable strings in a object, or other binary, file | |
# nm - display name list (symbol table) | |
# otool - object file displaying tool | |
# stat - display file status | |
# srm - securely remove files or directories | |
# rs - reshape a data array | |
# rev - reverse lines of a file | |
### Pretty interesting, and maybe even cool, but probably not common for day-to-day use | |
# lock - reserve a terminal | |
# leave - remind you when you have to leave | |
# banner - print large banner on printer | |
# figlet - convert text into a signature (NOT INCLUDED WITH OS) | |
# wait4path - wait for given path to show up in the namespace | |
# tiffutil - manipulates tiff files | |
# tiff2icns - converts TIFF to icns format | |
# ar - create and maintain library archives | |
# cscope - interactively examine a C program | |
# column - columnate lists | |
# apropos - search the whatis database for strings | |
# lam - laminate files | |
# cut - select portions of each line of a file | |
# csplit - split files based on context | |
# comm - select or reject lines common to two files | |
# colrm - remove columns from a file | |
# xmllint - command line XML tool | |
# screencapture - capture and manipulate clipboard contents | |
# say - convert text to audible speech | |
# uptime - show how long system has been running | |
# last - indicate last logins of users and ttys | |
# dmesg - display the system message buffer | |
# ac - display connect time accounting | |
# id - return user identity | |
# w - display who is logged in and what they are doing | |
# who - display who is on the system | |
# whoami - display effect user id | |
# logname - display user's login name (maybe different from whoami if su is used) | |
# finger - user information lookup program | |
# hostname - print the name of current host system | |
# hostinfo - host information | |
# uname - print Operating System name | |
# sw_vers - print Mac OS X operating system version information | |
# machine - print machine type | |
# arch - print architecture type | |
# manpath - format and display the on-line manual pages | |
# netstat - show network status | |
# top - display and update sorted information about processes | |
# ps - process status | |
# df -h/H - display free disk space | |
# du -hd 0 - display disk usage statistics | |
# lsof - list open files | |
# cksum - display file checksums and block counts | |
# pbcopy/pbpaste - provide copying and pasting to the pasteboard (the Clipboard) from command line | |
# - pbpaste | wc | |
# - pbpaste | xmllint -- noout - // see if clipboard contents are well XML formed | |
# - ls ~/Pictures pbcopy | |
# Shell tcsh bash | |
# Display all shell variables set set | |
# Create a shell variable set name value name=value | |
# Remove a shell variable unset name unset name | |
# List all environment variables env env | |
# Create an environment variable setenv name value export name=value | |
# Remove an environment variable unsetenv name unset name | |
####### System Tools ####### | |
# mdfind - finds files matching a given query | |
# mdls - lists the metadata attributes for the specified file | |
# mdutil - manage the metadata stores used by Spotlight | |
# mdimport - import file hierarchies into the metadata datastore | |
# at - queue, examine, or delete jobs for later execution | |
# cron - daemon to execute scheduled commands (Vixie Cron) | |
# crontab - maintain crontab files for individual users | |
# nice - execute a utility with an altered scheduling priority | |
# asr - Apple Software Restore; copy volumes (e.g. from disk images) | |
# softwareupdate - system software update tool | |
# defaults - access the Mac OS X user defaults system | |
# SetFile - get attributes of files and directories (MAC OS X) | |
# GetFileInfo - set attributes of files and directories (MAC OS X) | |
### Dangerously Administrative | |
# su - substitute user identity | |
# sudo - execute a command as another user | |
# passwd - modify a user's password | |
# mount - mount file systems | |
# logger - make entries in the system log | |
# hdiutil - manipulate disk images (attach, detach, verify, create, convert, burn) | |
# deafults - access the Mac OS X user defaults system | |
# bless - set volume bootability and startup disk options | |
# diskutil - modify, verify and repair local disks | |
# fdisk - DOS partition maintenance program | |
# pmset - modify power management settings | |
# shutdown - close down the system at a given time | |
# iostat - report I/O statistics | |
# quotaon/quotaoff - turn filesystem quotas on and off | |
# quota - display disk usage and limits | |
# edquota - edit user quotas | |
# quot - display total block usage per user for a file system | |
# repquota - summarize quotas for a file system | |
# pwpolicy - gets and sets password policies | |
# leaks - search a process's memory for unreferenced malloc buffers | |
####### You really should know these (if not, learn them cause they're good) ####### | |
# grep - print lines matching a pattern | |
# awk - pattern-directed scanning and processing language | |
# sed - stream editor | |
# head - display first lines of a file | |
# tail - display the last part of a file | |
# diff - compare files line by line | |
# diff3 - compare three files line by line | |
# sftp - secure file transfer program | |
# scp - secure copy (remote file copy program) | |
# ssh - OpenSSH SSH client (remote login program) | |
# rsync - faster, flexible replacement for rcp | |
# dig - DNS lookup utility | |
# host - DNS lookup utility | |
# whois - Internet domain name and network number directory service | |
# xxd - make a hexdump or do the reverse | |
# time - time command execution | |
# file - determine file type | |
# jot - print sequential or random data | |
# yes - be repetitively affirmative | |
# zip/unzip | |
# gzip/gunzip | |
# tar | |
# compress/uncompress | |
# traceroute - print the route packets take to network host | |
# ping - send ICMP ECHO_REQUEST packets to network hosts | |
# spray - send many packets to host | |
# wc - word, line, character, and byte count | |
# date - display or set date and time | |
# cal - displays a calendar | |
# ditto - copy files and directories to a destination directory | |
# pwd - return working directory name | |
# jobs/fg/bg - control process execution | |
# alias/unalias - create or remove a pseudonym or shorthand for a command or series of commands | |
# source - | |
# talk - talk to another user | |
# write - send a message to another user | |
# wall - write a message to users | |
# mesg - display (do not display) messages from other users | |
# touch - change file access and modification times | |
# sort - sort lines of text files | |
# !m | |
# !-5 | |
# !?-L?! | |
# ^-l^-la^ | |
# mail [email protected] < message.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment