Useful Mac Command Line Stuff

From Ideasplace
Jump to navigation Jump to search

Ping Sweep

for x in {100..199}; do ping -c 1 -W 100 192.168.1.$x | grep 'time='; done
for x in {1..254}; do ping -c 1 -W 100 192.168.0.$x | grep 'time='; done
for x in {3..253}; do ping -c 1 -W 100 10.22.228.$x | grep 'time='; done
for x in {3..253}; do ping -c 1 -W 100 10.22.229.$x | grep 'time='; done
for x in {3..253}; do ping -c 1 -W 100 10.22.230.$x | grep 'time='; done
for x in {3..253}; do ping -c 1 -W 100 10.22.231.$x | grep 'time='; done


nslookup IP address range

for x in {3..253}; do nslookup 10.198.88.$x | grep 'ni.ad.newsint'; done


Compare two folders and report differences

diff -rq folder1 folder2
for x in {1..254}; do nslookup 10.194.8.$x | grep ‘>'; done


---

To unlock files you can use:

chflags -R nouchg /PATH/
  • chflags = change flags on files/folders such as "locked"
  • -R = recursive or for everything and follow directories within the specified directory
  • nouchg = means the file can be changed
  • /PATH/ = of course is the path to the files you want to change. Something like: ~/Sites/mysite/directory/with/locked/files/ works as well.

In progress:

--- To reset an admin password when booted from the recovery partition or an installer

  • resetpassword

--- Enable screen sharing on OS X El Capitan from the command line.

The first method is an old standby:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -off -restart -agent -privs -all -allowAccessFor -allUsers

This will work in 99% of the cases, but there may be some situations when it’s not quite enough. The above command enables Screen Sharing by enabling Remote Management; however, we lose the ability to add fine-grained control to who can connect & those who can’t.

Here’s another way to enable screen sharing from the command line:

  • sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
  • sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

In the second example, we enable only Screen Sharing, not Remote Management. This allows us to use System Preferences to restrict who can screen share to our machine (e.g. local administrators, network administrators). We use the second example when configuring our authentication servers remotely.

--- Create Bootable installer

for El Capitan:

  • format key as HFS+ Journaled/GUID and call it “Untitled"

Then use:

  • sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app —nointeraction


For High Sierra:

  • sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia—volume /Volumes/Untitled