-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathoneliners.sh
308 lines (219 loc) · 11.2 KB
/
oneliners.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/bash
#----------AUTHOR------------
# Jacob Salmela
# 12 March 2013
# https://github.com/jakesalmela/
#---------DESCRIPTION--------
# A collection of powerful and useful one-liner commands for OS X
#----------------------------
###############################
########### FOR FUN ###########
# Watch star wars from the command line
telnet towel.blinkenlights.nl
# Star Wars traeroute
traceroute -m 254 -q1 obiwan.scrye.net
# Correctly pronounce OS X. this command is case sensitive and can be used to prove that OS X is OS Ten, not OS x
say OS X
# Rickroll the Terminal (run these types of commands with caution as any script could be executed)
curl -L http://bit.ly/10hA8iC | bash
# Send your Terminal to the Matrix
# http://osxdaily.com/2013/08/15/turn-the-terminal-into-a-matrix-style-scrolling-screen-of-binary-or-gibberish/
LC_ALL=C tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]"
# Continually scroll anything
# http://osxdaily.com/2013/08/15/turn-the-terminal-into-a-matrix-style-scrolling-screen-of-binary-or-gibberish/
while (true) do echo -n "9A85Y1BF978124871248172487124871248712487124"; done
# Set the screensaver as the wallpaper
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background
###############################
########### FINDER ############
# Remove individual app from Launchpad
sqlite3 ~/Library/Application\ Support/Dock/*.db "DELETE from apps WHERE title='APPNAME';" && killall Dock
# Remove all apps from Launchpad
sqlite3 ~/Library/Application\ Support/Dock/*.db "DELETE from apps; DELETE from groups WHERE title<>''; DELETE from items WHERE rowid>2;"; killall Dock
# Eject all network shares
find /Volumes -maxdepth 1 -not -user root -print0 | xargs -0 umount
# Eject all external storage
find /Volumes -maxdepth 1 -not -user root -print0 | xargs -0 diskutil eject
# Eject all network and external drives
osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
# Expand a .pkg into a folder to explore the files--folder mount point should not exist prior to command
pkgutil --expand installer.pkg /path/to/new/folder/mountpoint
# Eject CD/DVD
drutil open tray
# or
drutil eject
# Remove .DS_Store files that sometimes cause incongruent Finder view settings
sudo find / -name ".DS_Store" -depth -exec rm {} \;
# Fix this error: "x.app" is damaged and can't be opened. You should move it to the Trash.
xattr -rc /Applications/x.app
# Escape whitespace in a filepath
echo $1 | sed 's/\ /\\ /g'
###############################
######### SYSTEM ##############
# Print the date the computer last rebooted
last | awk '/reboot/ {print substr ($0, index($0, $3))}' | head -1
# Print the date the computer last shutdown
last | awk '/shutdown/ {print substr ($0, index($0, $3))}' | head -1
# List the 15 most-used commands
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -15
# Test hard disk speed by creating and removing a 500MB file
time (dd if=/dev/zero of=zerofile bs=1000 count=500;sync);rm zerofile
# Run 10 tests on command or script to check its performance
for i in {1..10}; do time curl http://localhost:8000 >/dev/null; done 2>&1 | grep real
# Print unicode characters in Terminal (you need to know the hex value, which can be found by right-clicking the character info, copying, and then pasting into a text editor.
# To print a sun with hex code e2 98 89
echo -e "\xe2\x98\x89"
# Get computer information CPU, hardware, etc.
sysctl -n machdep.cpu.brand_string
# Set the computer name, hostname, local hostname, or NetBIOS name
sudo scutil --set ComputerName "Macbook"
sudo scutil --set HostName "Macbook"
sudo scutil --set LocalHostName "Macbook"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "Macbook"
# Erase freespace on a disk
# Change the number value to 1, 2, or 3 for number of passes (1, 7, or 35)
# 35 pass is no longer available in the GUI after 10.6, so this is nice to know
diskutil secureErase freespace 2 /dev/disk0s2
# Change boot mode
# Boot into verbost mode
sudo nvram boot-args="-v"
# Boot into Safe Mode
sudo nvram boot-args="-x"
# Boot into Single-User Mode
sudo nvram boot-args="-s"
# Boot into Verbose mode
sudo nvram boot-args="-v"
# Reset the boot options to normal
sudo nvram -d boot-args
# View current nvram settings in xml-format
nvram -xp
# Remove KEXTs
sudo srm -rf /System/Library/Extensions/<extension.kext>
sudo touch /System/Library/Extensions
# View how many processes are allowed
getconf _CHILD_MAX
ulimit -u
# Count your processes
ps -x | wc -l
# Count another users processes
ps -xu root | wc -l
# Count all processes
ps -xa | wc -l
# Add user to admin group
sudo dseditgroup -o edit -a <username> -t user admin
# Reveal Firmware password -- older version only
python -c "print ''.join(chr(int(c, 16) ^ 170) for c in '`sudo nvram security-password`'.split('%')[1:])"
# Print RAM size
sysctl -n hw.memsize | awk '{print $0/1073741824" GB RAM"}';
# Show SMC version
ioreg -c AppleSMC | grep smc-version | cut -d'"' -f4
# or
system_profiler SPHardwareDataType | grep "SMC" | awk '{print $4}'
# Show BootROM (EFI version)
system_profiler SPHardwareDataType | grep "Boot ROM" | awk '{print $4}'
# Show Bluetooth MAC address
ioreg -c IOBluetoothHCIController | grep BluetoothDeviceAddress | grep -v BluetoothDeviceAddressData | cut -d'"' -f4
# Append all commands entered into the system log
# http://jablonskis.org/2011/howto-log-bash-history-to-syslog/
# Add this to .bash_profile
# Used with my Single-user mode IDS
# https://github.com/jakesalmela/single-user-mode-ids
declare -rx PROMPT_COMMAND='history -a >(tee -a ~/.bash_history | logger -t "**SUM-IDS")'
# List launchd processes
# A is active
# I is inactive
# D is on demand
launchctl bslist
# Heirarchical list of launchd processes
launchctl bstree
# Speed up shutdown time by reducing timeout values
sudo defaults write /System/Library/LaunchDaemons/com.apple.coreservices.appleevents ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.apple.securityd ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.apple.diskarbitrationd ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchAgents/com.apple.coreservices.appleid.authentication ExitTimeOut -int 5
# Reset LaunchServices (removes duplicates/problems in Open With...)
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
# Set a default program for a fileytpe. Below is just one example
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType = "com.adobe.pdf"; LSHandlerRoleAll = "com.apple.preview";}'
# Determine if computer is at the login window and owned by root (useful for running scripts that require a GUI)
ps auxc | grep loginwindow | grep root | awk '{print $1}'
# Add item to accessibility
sqlite3 /Library/Application\ Support/com.apple.TCC/TCC.db "INSERT INTO "access" VALUES('kTCCServiceAccessibility','/usr/bin/osascript',1,1,1,NULL)"
# Sync the login window text with the FilveVault unlock screen
sudo touch /System/Library/PrivateFrameworks/EFILogin.framework/Resources/EFIResourceBuilder.bundle/Contents/Resources
# Print hardware UUID
ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'
# Show serial number
ioreg -l | grep IOPlatformSerialNumber | cut -d'"' -f4
# EFI 64 or 32-bit
ioreg -l -p IODeviceTree -l | grep firmware-abi | cut -d'"' -f4
# 64 or 32-bit kernel
uname -a | cut -d'/' -f2-
# Is printer sharing on? 0 for no, 1 for yes
cupsctl | grep "_share_printers=" | cut -d'=' -f2
###############################
###### NETWORK/INTERNET #######
# Create symbolic link to airport utility
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
# Scan available networks using the shortcut created above
airport -s
# Show all open network connections and the apps that are using them
lsof -i | grep ESTABLISHED
# Show password for Website saved in the OS X Keychain
security find-internet-password -s <url> -w
# Show all files downloaded on the Mac
# Any file that passed through Quarantine Manager will show up here
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
# Delete list of downloaded files on the Mac
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
# View what wireless network you are currently connected to
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/[^B]SSID/ {print $2}'
# Tell your Mac to ask for 10,000 requests to run concurrently by 50 pretend users' concurrent connection
ab -n 10000 -c 50 http://test.server.com
# Display 10 second average up/down for en0--change en0 to desired network interface
sar -n DEV 1 10 | grep -i 'average.*en0'| awk '{printf "Up:\t%.2f Kbps\nDown:\t%.2f Kbps\n", $6 / 1024, $4 / 1024 }'
# One page Web server using netcat
while true; do nc -l 80 < error.html; done
# Enable advanced network commands
ENABLE_EXPERIMENTAL_SCUTIL_COMMANDS=1 scutil --net
# Disable IPv6
networksetup -setv6off Ethernet && networksetup -setv6off Wi-Fi
# Do not remember wireless networks
sudo /usr/libexec/airportd prefs RememberRecentNetworks=NO
###############################
########### MISC ##############
# Two ways to check the md5 hash of a file
md5 file1.dmg
openssl md5 file2.dmg
# Two ways to check sha1 hash of a file
shasum file1.dmg
openssl sha1 file2.dmg
# Compare the differences between two files in the GUI (Xcode required)
opendiff file1 file2
# Convert a text document into a spoken track
say -o audio.aiff -f file.txt
# List all apps downloaded from the Mac App Store
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
# Run command if user presses Ctrl+C
trap "<command_to_run>" INT
# Send a text message
# http://osxdaily.com/2014/03/12/send-sms-text-message-from-command-line/
curl http://textbelt.com/text -d number=<ten_digit_phone_number> -d "message=<your_message_here>"
# Enable App Store Degub menu
defaults write com.apple.appstore ShowDebugMenu -bool true
# Start downloading an app. Choose Debug > Show Download Folder
# Make a hard link to copy the installer .pkg to a new location
ln /folder/from/debug/menu.pkg /new/package/location/appstoreinstaller.pkg
# Convert a manpage to HTML
# @jescala https://jamfnation.jamfsoftware.com/featureRequest.html?id=762
gzcat /usr/share/man/man1/man.1.gz | groff -mandoc -Thtml > man-1.html
# Find out how many hours you have been logged into your Mac
ac -p | grep `whoami` | awk '{print $2}'
# Find out the user who has been logged in the most
# https://github.com/timsutton/scripts/blob/master/getMostFrequentUser/getMostFrequentUser.sh
ac -p | sort -nrk 2 | awk 'NR == 2 {print $1}'
# Delete all blank lines
cat something.txt | sed '/^$/d'
# Delete whitespace
cat something.txt | sed 's/ //g'