Top Banner
It’s dangerous to go alone!! Take This.
120

It’s dangerous to go alone!! Take This.

Dec 29, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: It’s dangerous to go alone!! Take This.

\

It’s dangerous to go alone!! Take This.

Page 2: It’s dangerous to go alone!! Take This.
Page 3: It’s dangerous to go alone!! Take This.

COMMAND LINE BASICS EMBRACE THE TEXT INTERFACE

Page 4: It’s dangerous to go alone!! Take This.

WHAT CAN I DO WITH IT?

▸Automate

▸Execute

▸Improve efficiency

▸Great for pranking! (Don't actually do this)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 5: It’s dangerous to go alone!! Take This.

GOT ANY SPECIFICS?

▸ Check uptime

▸ Change permissions

▸ Batch rename files

▸ Change preference settings

▸ Install software

▸ Look at logs

▸ Check running processes

▸ Format drives

▸ Configure Filevault

▸ Locate large files

▸ Run software updates

▸ Restart/shut down computer

▸ Check hardware specifications

▸ All of the above remotely via ssh

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 6: It’s dangerous to go alone!! Take This.

HOW DO I GET STARTED?

▸ Man pages

▸ man <command> (also try <command> --help)

▸ which

▸ w - shows uptime and what users have logged in (remotely or locally)

▸ Some commands can be destructive or limit access: Use caution

▸ rm <POSIX file path>

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 7: It’s dangerous to go alone!! Take This.

NAVIGATING AT THE COMMANDLINE

▸ ctrl+a - return the cursor to the beginning of the line

▸ ctrl+e - move the cursor to the end of the line

▸ ctrl+c - cancel the running command

▸ Tab completion - less flaky autocorrect for the terminal

▸ Up and down arrows -  scroll through previously entered commands.  

▸ Clear - clears terminal window

▸ * - Wildcard: *.pdf *resume*, picture*,etc

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 8: It’s dangerous to go alone!! Take This.

GLOBBING, AN INTERLUDE

The glob command, short for global, originates in the earliest versions of Bell Labs' Unix[1]. The command interpreters of the early versions of Unix (1st through 6th Editions, 1969–75) relied on a separate program to expand wildcard characters in unquoted arguments to a command: /etc/glob. That program performed the expansion and supplied the expanded list of file paths to the command for execution.

Later, this functionality was provided as a library function, glob(), used by programs such as the shell. - Wikipedia: Glob_(programming)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 9: It’s dangerous to go alone!! Take This.

GLOBBING, AN INTERLUDE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

The common syntax, in order of usefulness (IMHO)

*

[abc] [012]

[a-z]/[0-9]

[!234]

[!e-j]

?

Page 10: It’s dangerous to go alone!! Take This.

NAVIGATION RESUMED

▸ pwd - where am i?  (print working directory)

▸ cd - change directory, can use full path or relative path

▸ ~/ - start with the current user's home directory

▸ ls - list, switches allow for different info or recursive directory traversal

▸ .. - go up a level

▸ mkdir - make directory

▸ rm - remove file or directory

▸ open - open specified path in finder (or launch applications)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

\

Page 11: It’s dangerous to go alone!! Take This.

NAVIGATION EXERCISE

▸ Navigate to your Documents folder or a folder inside your Documents folder

▸ ls (-a/-l/-O/-e/-R) or all of the above

▸ open ../

▸ cd /Applications/<pick one>/Contents/

▸ ls

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

w osascript -e "set Volume 5" say -v Fred "I am groot"EXTRA CREDIT

Page 12: It’s dangerous to go alone!! Take This.

READING TEXT

▸ cat - display text from file to shell can also conCATenate files

▸ head - display lines from the beginning of a file

▸ tail - display lines from the end of a file

▸ more / less - pagers. Allow reading of large files a page at a time

▸ | - Pipe the output of one command to another command

▸ <, <<, >, >> - read in files or direct input and write out files (replacing or append)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 13: It’s dangerous to go alone!! Take This.

SEARCHING, BROWSING AND MANIPULATING TEXT AND FILES

▸ grep - searches for patterns in input and prints lines that match

▸ wc - counts words, characters and bytes

▸ sed - stream editor

▸ awk - pattern directed scanning and processing language

▸ nano - simple command line based text editor (launch with -w)

▸ emacs/vim - complex command line based text editors that also have graphical editors available. Extensive use of key commands.

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 14: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep kitten

Page 15: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep kittenkittenkittendomkittenheartedkittenhoodkittenishkittenishlykittenishnesskittenlesskittenship

Page 16: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep Kitten

Page 17: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep Kittenjpiperbe@jpiperbe-retina:~ :(

Page 18: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep -i Kitten

Page 19: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep -i Kittenkittenkittendomkittenheartedkittenhoodkittenishkittenishlykittenishnesskittenlesskittenship

Page 20: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep -c kitten

Page 21: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep -c kitten9

Page 22: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep -c kit

Page 23: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep -c kit167

Page 24: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep kit | more

Page 25: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 26: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

grep -c kitten < /usr/share/dict/words

Page 27: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) grep -c kitten < /usr/share/dict/words 9

Page 28: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | grep -A2 -B2 kitten

Page 29: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | grep -A2 -B2 kittenKittatinnykittelkittenkittendomkittenheartedkittenhoodkittenishkittenishlykittenishnesskittenlesskittenshipkitterkittereen

Page 30: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat /usr/share/dict/words | wc -w

Page 31: It’s dangerous to go alone!! Take This.

SEARCHING TEXT EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) cat /usr/share/dict/words | wc -w235886

Page 32: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls ~/

Page 33: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls -a ~/

Page 34: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls -R ~/Documents/*.pdf

Page 35: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 36: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls -R ~/Documents | grep -c .pdf

Page 37: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 38: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

??????????

Page 39: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

find ~/Documents -name '*.pdf'

Page 40: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

find ~/Documents -name '*.pdf' | grep -c .pdf

Page 41: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 42: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

??????????

Page 43: It’s dangerous to go alone!! Take This.

SEARCHING FILES

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 44: It’s dangerous to go alone!! Take This.

FIND/DU

▸find / -name .DS_Store -delete ▸find ~/ -size +500M ▸find ~/-size +1G▸du -sh ~ /*▸du -sh ~/

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 45: It’s dangerous to go alone!! Take This.

NOW THAT WE CAN FIND FILES...

Permissions/Modes, ownership and size

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 46: It’s dangerous to go alone!! Take This.

PERMISSIONS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

drwxr-xr-x@ 22 jpiperbe staff hidden 704B Oct 21 2014 A+

u

g

o7

5

5

chmod

Page 47: It’s dangerous to go alone!! Take This.

PERMISSIONS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

drwxr-xr-x@ 22 jpiperbe staff hidden 704B Oct 21 2014 A+

xattr

Page 48: It’s dangerous to go alone!! Take This.

PERMISSIONS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

drwxr-xr-x@ 22 jpiperbe staff hidden 704B Oct 21 2014 A+

chown

Page 49: It’s dangerous to go alone!! Take This.

PERMISSIONS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

drwxr-xr-x@ 22 jpiperbe staff hidden 704B Oct 21 2014 A+

chgrp

Page 50: It’s dangerous to go alone!! Take This.

PERMISSIONS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

drwxr-xr-x@ 22 jpiperbe staff hidden 704B Oct 21 2014 A+

chflags

Page 51: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

▸ACLs

▸ls -ale

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 52: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cd ~/

Page 53: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

mkdir cmdLine

Page 54: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cd cm[tab]

Page 55: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

pwd

Page 56: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

touch testing

Page 57: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls

Page 58: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

nano -w t[tab]

Page 59: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 60: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

more t[tab]

Page 61: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

chmod 700 t[tab]

Page 62: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

sudo chown root t[tab]

Page 63: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

more t[tab]

Page 64: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

sudo chown [username] testing

Page 65: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

chmod u-r t[tab]

Page 66: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls -l

Page 67: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

open t[tab]

Page 68: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

chmod 650 ../cmd[tab]

Page 69: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cd ..

Page 70: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

ls -l

Page 71: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 72: It’s dangerous to go alone!! Take This.

ONE MORE THING (AND LET'S TRY THIS)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

chmod -R 755 cmd[tab]

Page 73: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

▸Aliases

▸Prompts

▸Paths

▸Font/Display/Colors

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 74: It’s dangerous to go alone!! Take This.

COLORS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 75: It’s dangerous to go alone!! Take This.

COLORS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 76: It’s dangerous to go alone!! Take This.

COLORS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 77: It’s dangerous to go alone!! Take This.

COLORS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 78: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

https://bit.ly/2NmjRvk

Page 79: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

bash_profilezshrc

Page 80: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

mv ~/.bash_profile ~/.bash_profile.old

Page 81: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

mv ~/Downloads bash_profile ~/.bash_profile

Page 82: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cp ~/.zshrc ~/.zshrc.old

Page 83: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat ~/Downloads/zshrc > ~/.zshrc

Page 84: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

cat ~/.bash_profile

Page 85: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

nano -w ~/.zshrc

Page 86: It’s dangerous to go alone!! Take This.

CUSTOMIZING YOUR EXPERIENCE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

nano -w ~/.bash_profile

Page 87: It’s dangerous to go alone!! Take This.

OTHER USEFUL CUSTOMIZATIONS

▸ change window size

▸ alias top20="top -o cpu -n 20"

▸ add to your .bash_profile or .zshrc

▸ echo "alias top20=\"top -o cpu -n 20\"" >> .bash_profile

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 88: It’s dangerous to go alone!! Take This.

ADMIN STUFF▸ sudo profiles renew -type enrollment

▸ softwareupdate

▸ system_profiler

▸ installer

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 89: It’s dangerous to go alone!! Take This.

EXERCISE WITH SOFTWARE UPDATE AND SYSTEM PROFILER

▸softwareupdate -l

▸system_profiler -detaillevel mini

▸system_profiler -listDataTypes

▸system_profiler SPHardwareDataType

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 90: It’s dangerous to go alone!! Take This.

SO MANY COMMANDS

▸ sysadminctl

▸ scutil

▸ fdesetup

▸ profiles

▸ jamf/munki 

▸ diskutil

▸ systemsetup

▸ networksetup

▸ ifconfig

▸ ping

▸ traceroute

▸ nslookup / whois

▸ defaults

▸ plutil/PlistBuddy

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 91: It’s dangerous to go alone!! Take This.

LET'S TRY SOME OF THIS

▸profiles list

▸diskutil list

▸diskutil info disk1s1

▸ fdesetup list

▸sudo fdesetup list

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 92: It’s dangerous to go alone!! Take This.

PROFILES AND PLISTS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

▸defaults

▸plutil

▸PListBuddy (/usr/libexec/PlistBuddy)

Page 93: It’s dangerous to go alone!! Take This.

PROFILES AND PLISTS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

STANDARDS

The plutil command obeys no one's rules but its own.

Page 94: It’s dangerous to go alone!! Take This.

TEXT

PLISTS AND PROFILES

▸ profiles install -path <pathtofile>

▸ MDM

▸ defaults write NSGlobalDomain com.apple.swipescrolldirection -bool true

▸ https://fgimian.github.io/blog/2015/06/27/a-simple-plistbuddy-tutorial/

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 95: It’s dangerous to go alone!! Take This.

SCRIPTING

▸Commandline, now with persistence and variables!

▸Repeat commands

▸ install software

▸update settings

▸And so much more!

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 96: It’s dangerous to go alone!! Take This.

SCRIPTING EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

▸https://bit.ly/2NmjRvk

▸Download PSUMac2019*.sh files

▸ls -lO ~/Downloads | grep PSUMac

▸chmod u+x

Page 97: It’s dangerous to go alone!! Take This.

SCRIPTING EXERCISE CONTINUED

▸~/Downloads/PSUMac2019SystemReport.sh▸open ~/Desktop/PSUMac2019SystemReport.txt▸cd ~/Downloads; ./PSUMac2019Colortable.sh▸./PSUMac2019colortablenumber.sh▸ feel free to open in your text editor of choice and take a

look at the commands and ask questions

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 98: It’s dangerous to go alone!! Take This.

USERS

▸login - login as another user (goes to their home)

▸su - substitute user (keeps location the same)

▸sudo (-s) - super user do runs following command as admin. Requires password

▸exit - logout

▸dscl - read/edit users and groups on the system

▸sysadminctl - secureToken / add/remove users / settings

▸last - shows sessions in reverse time order (auditing public macs)

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 99: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 100: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

sudo sysadminctl -addUser test ⮐-fullName "Test User"-shell /bin/zsh ⮐-password password -hint "bad choice" ⮐-home /Users/test -admin

Page 101: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 102: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) sudo sysadminctl -addUser test -fullName "Test User" -shell /bin/zsh -password password -hint "bad choice" -home /Users/test -admin Password:2019-07-02 13:58:44.064 sysadminctl[23070:2870546] ----------------------------2019-07-02 13:58:44.064 sysadminctl[23070:2870546] No clear text password or interactive option was specified (adduser, change/reset password will not allow user to use FDE) !2019-07-02 13:58:44.064 sysadminctl[23070:2870546] ----------------------------2019-07-02 13:58:44.277 sysadminctl[23070:2870546] Creating user record…2019-07-02 13:58:45.879 sysadminctl[23070:2870546] Assigning UID: 5042019-07-02 13:58:56.127 sysadminctl[23070:2870546] Home directory is assigned (not created!) at /Users/test

Page 103: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 104: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) login testPassword:Last login: Sun Jun 30 21:26:23 on ttys000No home directory: /Users/testjpiperbe-retina%

Page 105: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe-retina% pwd/jpiperbe-retina% exitjpiperbe@jpiperbe-retina:~ :)

Page 106: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) mkdir /Users/testmkdir: /Users/test: Permission deniedjpiperbe@jpiperbe-retina:~ ಠ_ಠ sudo mkdir /Users/testPassword:jpiperbe@jpiperbe-retina:~ :) sudo chown -R test /Users/test/jpiperbe@jpiperbe-retina:~ :) login testPassword:Last login: Tue Jul 2 14:02:09 on ttys005jpiperbe-retina% pwd/Users/testjpiperbe-retina% sudo cp /Users/jpiperbe/.zshrc .Password:jpiperbe-retina%

Page 107: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

jpiperbe@jpiperbe-retina:~ :) login testPassword:Last login: Tue Jul 2 14:16:23 on ttys005test@jpiperbe-retina:~ ! exitjpiperbe@jpiperbe-retina:~ :)

Page 108: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

dscl . -list /Users UniqueIDdscl . -list /Users UniqueID | grep -v _sudo sysadminctl -deleteUser testdscl . -list /Users UniqueID | grep -v

Page 109: It’s dangerous to go alone!! Take This.

USERS EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 110: It’s dangerous to go alone!! Take This.

CONFIGURING AND TESTING NETWORK AND OTHER SETTINGS

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 111: It’s dangerous to go alone!! Take This.

NETWORK AND CONFIGURATION EXERCISE

▸nslookup <ipreportedfromping>▸whois <insertwebsite.com>▸ifconfig en0▸scutil --get ComputerName▸sudo systemsetup -getcomputername

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 112: It’s dangerous to go alone!! Take This.

MORE ADMIN THINGS (FOR JAMF USERS)

▸sudo jamf enroll -prompt

▸sudo jamf manage

▸sudo jamf policy -id <policy id>

▸sudo jamf policy -trigger enrollmentComplete

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 113: It’s dangerous to go alone!! Take This.

SETUP ASSISTANT

▸ctrl+opt+cmd+t =

▸rm /var/db/.AppleSetupDone - re-runs setup assistant at next reboot,

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 114: It’s dangerous to go alone!! Take This.

DOING ALL THIS REMOTELY

▸Almost anything you did here can be done remotely (environment dependent)

▸SSH Keys

▸Admin accounts

▸pushing scripts with management software

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 115: It’s dangerous to go alone!! Take This.

LOGGING

▸ Console

▸ /Library/Logs/

▸ /var/log

▸ log show

▸ log stream

▸ --predicate is critical

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 116: It’s dangerous to go alone!! Take This.

LOGGING EXERCISE

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 117: It’s dangerous to go alone!! Take This.

LOGGING EXERCISE

▸ more /var/log/system.log

▸ cat /var/log/system.log | tail -100 | more

▸ ls /Library/Logs/

▸ log show --predicate 'eventMessage CONTAINS "en0"' --last 15m

▸ log show --predicate 'eventMessage CONTAINS "en0"' ⮐ --last 15m | more

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 118: It’s dangerous to go alone!! Take This.

CATALINA (MACOS 10.15)

▸ZSH replacing BASH - NBD

▸https://scriptingosx.com/2019/06/moving-to-zsh/

▸Python/Ruby/Perl will not be included by default

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS

Page 119: It’s dangerous to go alone!! Take This.

??? " ???

Page 120: It’s dangerous to go alone!! Take This.

RESOURCES (NOT BY ANY MEANS EXHAUSTIVE)

▸ http://www.nparikh.org/unix/prompt.php

▸ https://www.cgl.ucsf.edu/chimerax/docs/user/commands/colornames.html

▸ http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux

▸ https://www.modtitan.com/2017/04/finding-shutdown-causes-in-macos.html

▸ https://eclecticlight.co/2018/03/19/macos-unified-log-1-why-what-and-how/

▸ https://scriptingosx.com/

▸ https://www.php.net/manual/en/reference.pcre.pattern.syntax.php

▸ https://derflounder.wordpress.com

▸ https://fgimian.github.io/blog/2015/06/27/a-simple-plistbuddy-tutorial/

IT’S DANGEROUS TO GO ALONE, TAKE THIS: A TREASURE-FILLED WORKSHOP FOR NEW MAC ADMINS