Difference between revisions of "Mac Commandline Tools"
(Created page with "---- '''systemsetup''' Manage a variety of configuration stuff. sudo systemsetup -getdate # view system date systemsetup -getcomputername # display computer name -…") |
AshleySueMas (talk | contribs) |
||
(8 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | + | This is a list of commands specific to Mac OSX 10.4+. It is important to note that some commands have arguments that differ from one os version to the other but overall it is accurate of the latest software builds. | |
− | + | ||
+ | =System Management= | ||
+ | |||
+ | ==systemsetup== | ||
Manage a variety of configuration stuff. | Manage a variety of configuration stuff. | ||
Line 9: | Line 12: | ||
---- | ---- | ||
− | + | ==softwareupdate== | |
Execute Apple Software update from the commandline | Execute Apple Software update from the commandline | ||
Line 18: | Line 21: | ||
---- | ---- | ||
− | + | ==networksetup== | |
Manage the network configuration | Manage the network configuration | ||
Line 27: | Line 30: | ||
---- | ---- | ||
− | + | ==dscl== | |
− | Directory service management, for example users, groups etc. | + | Directory service management, for example users, groups etc. |
+ | |||
+ | *''See also [[Mac_OSX_adduser_script| adduser script]].'' | ||
dscl localhost -list /Local/Default/Users # list all local users | dscl localhost -list /Local/Default/Users # list all local users | ||
Line 58: | Line 63: | ||
passwd username | passwd username | ||
+ | |||
+ | But all of this is simplified by our in-house adduser script: | ||
+ | |||
+ | ===[[Mac_OSX_adduser_script| adduser script]]=== | ||
+ | This is a shell script designed to do all of the above ''dscl'' commands automatically, asking only for the user's input. | ||
---- | ---- | ||
− | + | ==dscacheutil== | |
Manage DNS cache | Manage DNS cache | ||
Line 67: | Line 77: | ||
---- | ---- | ||
− | + | ==system_profiler== | |
View system information (Like SystemProfiler.app in Utilities) | View system information (Like SystemProfiler.app in Utilities) | ||
Line 82: | Line 92: | ||
---- | ---- | ||
− | + | ==sysctl== | |
Display or set the kernel state. Commonly used to retrieve information on the system such as | Display or set the kernel state. Commonly used to retrieve information on the system such as | ||
Line 89: | Line 99: | ||
sysctl -a | grep hw.memsize # list the amount of memory in the system | sysctl -a | grep hw.memsize # list the amount of memory in the system | ||
+ | ---- | ||
− | + | =File Management= | |
− | + | ||
+ | ==chflags== | ||
Change file flags, like “hidden”, “archived”.. | Change file flags, like “hidden”, “archived”.. | ||
Line 100: | Line 112: | ||
---- | ---- | ||
− | + | ==GetFileInfo== | |
View extended file attributes, like icon, creator and so on. To write these attributes use SetFileInfo | View extended file attributes, like icon, creator and so on. To write these attributes use SetFileInfo | ||
− | GetFileInfo any.txt # list the attributes | + | GetFileInfo any.txt # list the attributes of a specified file |
+ | |||
+ | ---- | ||
+ | ==mdutil/mdfind== | ||
+ | Manage Spotlight and search it's cache | ||
+ | |||
+ | mdutil -s / # show indexing status on root drive | ||
+ | |||
+ | mdfind -name "filename" # similar to find, check the cache for a specified file or directory | ||
---- | ---- | ||
− | + | ||
+ | =Storage Management= | ||
+ | |||
+ | ==diskutil== | ||
Manage local disks | Manage local disks | ||
− | diskutil list # list local drives and partitions | + | diskutil list # list local drives and partitions |
− | + | ||
+ | diskutil activity # monitor activity on the local disk | ||
+ | |||
+ | diskutil repairvolume disk0s1 # attempt to repair the specified partition | ||
+ | |||
+ | diskutil checkraid # display status of local RAID arrays | ||
+ | |||
+ | diskutil appleRAID update AutoRebuild 1 disk0 # set the specified disk path to automatically be rebuild if the array is broken | ||
+ | |||
+ | diskutil repairPermissions / # repair any improper permissions caused by third-party software or updates | ||
+ | |||
+ | diskutil randomDisk 3 /dev/disk0 # erase the specified disk by writing random 1s and 0s to the entire disk using 3 passes | ||
+ | |||
+ | diskutil secureErase 4 /dev/disk0 # erase the specified disk with a DoD algorithm using 3 passes | ||
---- | ---- | ||
− | + | ||
+ | ==hdiutil== | ||
Manage disk images | Manage disk images | ||
− | hdiutil burn animage.dmg # burn imagefile to cd/dvd | + | hdiutil burn animage.dmg # burn imagefile to cd/dvd |
− | hdiutil create -srcfolder path any.dmg # create dmg-image from folder | + | hdiutil create -srcfolder path any.dmg # create dmg-image from folder |
---- | ---- | ||
− | + | ==drutil== | |
Interact with CD/DVD drives | Interact with CD/DVD drives | ||
− | drutil eject # eject media | + | drutil eject # eject media |
− | drutil status # show detailed information about drives and media | + | drutil status # show detailed information about drives and media |
+ | ---- | ||
+ | |||
+ | =Misc= | ||
+ | |||
+ | ==curl== | ||
− | - | + | Retrieve websites or files on those websites much like ''wget''. |
− | ''' | + | |
+ | curl -OL http://www.freegeek.org/index.php # download the index page of our website | ||
+ | |||
+ | For those who are resistant to change, most people can simply set an alias to sidestep curl and use it like ''wget'': | ||
+ | |||
+ | echo 'alias wget="curl -O"' >> ~/.bash_profile | ||
+ | |||
+ | ==open== | ||
− | Open a file with a given application. | + | Open a file with a given application in the gui. |
− | open example.txt # opens the file in the default text editor | + | open example.txt # opens the file in the default text editor |
− | open . # opens a new finder window with the current commandline path | + | open . # opens a new finder window with the current commandline path |
+ | |||
+ | open -a Safari # opens Safari | ||
---- | ---- | ||
− | + | ==pbcopy/pbpaste== | |
Access OSX clipboard | Access OSX clipboard | ||
− | ls | pbcopy # copy dir listing to clipboard | + | ls | pbcopy # copy dir listing to clipboard |
---- | ---- | ||
− | + | ==periodic== | |
− | + | Run periodic system jobs | |
+ | |||
+ | sudo periodic daily # run daily stuff | ||
− | + | However, any such tasks can be done traditionally with ''cron'' as well. | |
− | |||
− | |||
---- | ---- | ||
− | + | ==say== | |
+ | |||
+ | Have the local machine speak to you. | ||
− | + | say "I am way cool" | |
+ | |||
+ | say -v Bruce "Zip zop zoo bitty bop" | ||
− | + | [[category:Macintosh Archive]] | |
− | + | [[category:Tech Support]] |
Latest revision as of 12:14, 21 February 2014
This is a list of commands specific to Mac OSX 10.4+. It is important to note that some commands have arguments that differ from one os version to the other but overall it is accurate of the latest software builds.
System Management
systemsetup
Manage a variety of configuration stuff.
sudo systemsetup -getdate # view system date systemsetup -getcomputername # display computer name
softwareupdate
Execute Apple Software update from the commandline
softwareupdate -l # list available updates sudo softwareupdate -i -a # install all available updates
networksetup
Manage the network configuration
sudo networksetup -listallhardwareports # list all network interfaces with MAC addresses sudo networksetup -switchtolocation home # switch network locations
dscl
Directory service management, for example users, groups etc.
- See also adduser script.
dscl localhost -list /Local/Default/Users # list all local users
Users are added from the command line with dscl. In OSX, it is done as such:
dscl . -create /Users/username # creates the new user entry. The "." specifies the local machine and "-create" is the verb which directs the command. dscl . -create /Users/username UserShell /bin/bash # sets the default shell for said user dscl . -create /Users/username Realname "user name" # the alternative name used optionally by OSX to log in dscl . -create /Users/username UniqueID 503 # set a unique number id for the user dscl . -create /Users/username PrimaryGroupID 1000 # sets the primary group id. In OSX the admin groups are usually either administrator or staff. dscl . -create /Users/username NFSHomeDirectory /Local/Users/username # sets the user's home directory dscl . -passwd /Users/username password # sets the user's password dscl . -append /Groups/admin GroupMembership username
As a note, to list all available groups and their ids, you can type
dscacheutil -q group
And passwords can be set or changed in the traditional linux way with
passwd username
But all of this is simplified by our in-house adduser script:
adduser script
This is a shell script designed to do all of the above dscl commands automatically, asking only for the user's input.
dscacheutil
Manage DNS cache
dscacheutil -flushcache # clear local DNS cache
system_profiler
View system information (Like SystemProfiler.app in Utilities)
system_profiler # list all information on system available. It is A LOT OF INFO!! system_profiler -detaillevel basic # lists only hardware and network information system_profiler SPHardwareDataType # lists a hardware overview of the local system system_profiler SPSoftwareDataType # lists a software overview of the local system system_profiler -xml filename >/Users/username/Documents/sys-info.xml # generates an xml file rather than plain text output.
sysctl
Display or set the kernel state. Commonly used to retrieve information on the system such as
sysctl -n machdep.cpu.brand_string # display information on the processor sysctl -a | grep hw.memsize # list the amount of memory in the system
File Management
chflags
Change file flags, like “hidden”, “archived”..
chflags -R -V hidden /some/file.txt # hides the specified file from the gui ls -l0 # View flags in the current directory
GetFileInfo
View extended file attributes, like icon, creator and so on. To write these attributes use SetFileInfo
GetFileInfo any.txt # list the attributes of a specified file
mdutil/mdfind
Manage Spotlight and search it's cache
mdutil -s / # show indexing status on root drive mdfind -name "filename" # similar to find, check the cache for a specified file or directory
Storage Management
diskutil
Manage local disks
diskutil list # list local drives and partitions diskutil activity # monitor activity on the local disk diskutil repairvolume disk0s1 # attempt to repair the specified partition diskutil checkraid # display status of local RAID arrays diskutil appleRAID update AutoRebuild 1 disk0 # set the specified disk path to automatically be rebuild if the array is broken diskutil repairPermissions / # repair any improper permissions caused by third-party software or updates diskutil randomDisk 3 /dev/disk0 # erase the specified disk by writing random 1s and 0s to the entire disk using 3 passes diskutil secureErase 4 /dev/disk0 # erase the specified disk with a DoD algorithm using 3 passes
hdiutil
Manage disk images
hdiutil burn animage.dmg # burn imagefile to cd/dvd hdiutil create -srcfolder path any.dmg # create dmg-image from folder
drutil
Interact with CD/DVD drives
drutil eject # eject media drutil status # show detailed information about drives and media
Misc
curl
Retrieve websites or files on those websites much like wget.
curl -OL http://www.freegeek.org/index.php # download the index page of our website
For those who are resistant to change, most people can simply set an alias to sidestep curl and use it like wget:
echo 'alias wget="curl -O"' >> ~/.bash_profile
open
Open a file with a given application in the gui.
open example.txt # opens the file in the default text editor open . # opens a new finder window with the current commandline path open -a Safari # opens Safari
pbcopy/pbpaste
Access OSX clipboard
ls | pbcopy # copy dir listing to clipboard
periodic
Run periodic system jobs
sudo periodic daily # run daily stuff
However, any such tasks can be done traditionally with cron as well.
say
Have the local machine speak to you.
say "I am way cool" say -v Bruce "Zip zop zoo bitty bop"