40 useful Mac OS X Shell scripts and terminal commands

Source: Internet
Author: User
Tags net command

40 useful Mac OS X Shell scripts and terminal commands

There are a bunch of terminal commands under Mac OS x. I have classified these commands in a simple way. Many commands here are equally effective in other systems (Windows and Linux, especially Linux/Unix. I hope these commands will help you.

System

Restart Mac OS X:

 
1 shutdown- r now


Disable Mac OS X:

 
1 shutdownnow
Power Management/power saving

Obtains information about current power management settings.

 
1 pmset -g

Set the monitor to off after no activity for 15 minutes

 
1 sudopmset displaysleep 15

Sleep the computer after being idle for 30 minutes

 
1 sudopmsetsleep30
OS X appearance

Disable dashboard (do not forget to drag the dashboard Dock icon out)

 
1 defaults write com.apple.dashboard mcx-disabled -boolean YES
2 killall Dock

Enable dashboard

 
1 defaults write com.apple.dashboard mcx-disabled -boolean NO
2 killall Dock

Force the Finder program to display hidden files

 
1 defaults write com.apple.finder AppleShowAllFiles TRUE

Force Finder programs not to show hidden files

 
1 defaults write com.apple.finder AppleShowAllFiles FALSE
Network

Ping a host

 
1 ping-o bkjia.net

Use traceroute to diagnose a route node of a host

 
1 traceroutebkjia.net

Check whether an HTTP service is running on a host or whether a website is available

 
1 curl -I www.bkjia.net |head-n 1

Manage Windows networks (equivalent to the NET command in Windows). This command has many options. Run the following command to view these options.

 
1 mannet

Use dig to diagnose Domain Name Information

 
1 digwww.bkjia.net A
2 digwww.bkjia.net MX

Check who is logging on to your Mac Machine

 
1 w

Show System route table

 
1 netstat-r

Show Active Network Connections

 
1 netstat-an

Show Network statistics

 
1 netstat-s
Fault Diagnosis

List all open files

 
1 lsof

Restart Bonjour-useful when there is no Mac in the Network

 
1 sudolaunchctl unload /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
2 sudolaunchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

Pop-up CD (not necessarily disk1)

 
1 diskutilejectdisk1
Text operation commands

You often need to obtain some text from the clipboard or file and convert and use the text. The commands listed here are related to text processing.

Count the number of lines of text in the clipboard

 
1 pbpaste |wc-l

Count the number of words in the text on the clipboard

 
1 pbpaste |wc-w

Sort the text lines in the clipboard and re-write them back to the clipboard.

 
1 pbpaste |sort| pbcopy

Reverse the text lines in the clipboard and return them to the clipboard.

 
1 pbpaste | rev | pbcopy

Removes duplicate lines of text from the clipboard and writes them back to the clipboard.

 
1 pbpaste |sort|uniq| pbcopy

Find the duplicate row in the Chinese text of the clipboard, copy the row, and write it back to the clipboard (including the row of the duplicate row)

 
1 pbpaste |sort|uniq-d | pbcopy

Find the duplicate row in the Chinese text of the clipboard, copy the row, and write it back to the clipboard (excluding duplicate rows)

 
1 pbpaste |sort|uniq-u | pbcopy

Clears HTML text from the clipboard and writes it back to the clipboard.

 
1 pbpaste | tidy | pbcopy

Display the first five lines of text in the clipboard

 
1 pbpaste |head-n 5

Display the last five lines of text in the clipboard

 
1 pbpaste |tail-n 5

Convert the tabs in the text in the clipboard into spaces.

 
1 pbpaste |expand| pbcopy
Other useful commands:
1 htpasswd -nb username password
B:
1 AuthType Basic
2 AuthName"restricted area"
3 AuthUserFile /path/to/your/site/.htpasswd
4 require valid-user

Display the commands previously entered in the terminal window

 
1 history

Convert a file to HTML. The supported formats include Text,. RTF, And. DOC.

 
1 textutil -convert htmlfile.extension

Nano is a simple and easy-to-use text editor that can be used to quickly change text files. It is much weaker than vim, but it is very convenient.

 
1 nano [file_to_edit]

In the nano editor, you can use ctrl + o to maintain and ctrl + x to exit.

Clear content displayed on the terminal

 
1 clear
ITunes Problems

Change the iTunes link behavior to the local iTunes library instead of the iTunes Store.

 
1 defaults write com.apple.iTunes invertStoreLinks -bool YES

Change the iTunes link behavior to iTunes Store instead of the local iTunes library

 
1 defaults write com.apple.iTunes invertStoreLinks -bool NO
Other Mac OS X terminal Resources

Mac OS X Hacking Tools (old but detailed list for the obsessive only ).

Cameron Hayne's Bash Scripts

Mac OS X Hints

Apple Forums

Note: In the previous examples, we used pbpaste to obtain data from the clipboard, or cat to obtain data from the file.

 
1 cat[/path/to/filename]

Replace pbcopy:

 
1 > ~/Desktop/filename.txt

Original English, OSCHINA Original translation


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.