Command-line tools on your Mac

Source: Internet
Author: User
Tags imagemagick install node ssh access

Turn to self-love rice Home Blog, original: "Eight Terminal Utilities every OS X Command line User should Know"

OS X's Terminal terminal opens up the world of powerful UNIX utilities and scripts. If you are a user who has been transferred from Linux, you will find many familiar commands on the OS X terminal. But even advanced users often ignore the fact that OS X terminals also have a range of terminal tools that are not available in other operating systems. When you learn these lessons for Mac only, you can use the MAC command line more efficiently to eliminate the difference between your UNIX system and your Mac system. 1. OpenOpen: Opens files, directories, and programs. It's exciting, isn't it? In fact, its real role is to command line simulates mouse double-click Operation。 Suppose when you enter:
    1. $ open/applications/safari.app/
Entering this command launches the Safari browser as you would double-click the Safari icon in the Finder. If you use the Open command to point to a file, it will start the relevant GUI application to load the file. The Open screenshot.png command opens the picture in the preview. Of course you can include the-a flag in the command to select the application you want to load the file in, or open the edit directly in the text editor using the-e identity. Running the open command for a directory opens the directory directly in the Finder window. This method is especially useful for running open on the command line. To open the current directory. Keep in mind that the integration between the Finder and the terminal terminal is mutual, and when you drag a file from the Finder into the Terminal terminal window, its absolute path is pasted on the command line. 2. Pbcopy and PbpasteThese two commands allow you to copy and paste text content from the command line. Of course you can do this directly with the mouse. But the real magic of Pbcopy and Pbpaste is that they are UNIX commands, which allows them to benefit from pipelines (piping), redirects, and can be used with other commands in the script. For example, when entering:
    1. $ ls ~ | Pbcopy
Entering this command copies the list of files in your home directory to the Clipboard in the OS X system. You can easily get the contents of a document by using the following command:
    1. $ pbcopy < Blogpost.txt
or something more crazy. The following script will crawl the latest Google Doodle link and copy it to your clipboard.
    1. $ curl http://www.google.com/doodles#oodles/archive | grep-a5 ' Latest-doodle on ' | grep ' img src ' | sed s/.* '
Using Pbcopy in a pipeline is a good way to crawl the command-line output without having to flip the page and look at every line of content carefully. This method makes it easy to share diagnostic information. Pbcopy and Pbpaste can also be used to perform similar tasks automatically or quickly. For example, when you want to save the subject line of an e-mail message to a task list, you can copy the content in the mail program before running:
    1. $ pbpaste >> tasklist.txt
3. MdfindMany users of heavy Linux use the Locate command on their Mac to search for files, but they quickly find that this method is not feasible. There is an old find command in Unix, but in OS X it has its own killer search tool: Spotlight. So why don't we borrow its power from the command line? This is what mdfind is doing in practice. Any spotlight can search for content, Mdfind also can search. This, of course, also includes searching the file for internal and meta-data. Mdfind because of its convenience, it makes it stand out from the Big Brother. For example, the-onlyin identity can limit the search to a specified directory:
    1. $ mdfind-onlyin ~/documents Essay
The Mdfind database needs to update the data frequently in the background, but you can use the Mdutil command to troubleshoot (the same applies to spotlight). If Spolight does not work correctly, using MDUTIL-E will clear the index in the database and then rebuild the index by crawling. You can also completely complete the index by running mdutil-i off. 4. ScreencaptureScreencapture allows you to take a variety of screen shots. It is similar to Drawing Programor CMD + shift +3 and CMD + SHIFT + 4 for the screenshot shortcut, but it's more flexible. Here are a few ways you can use Screencapture: Grab all the contents of the screen, including the cursor, and attach the (name ' Image.png ') to a new e-mail message:
    1. $ screencapture-c-M image.png
Select a window from your mouse and then crawl the contents of the window (excluding the shadow effect of the window) to copy it to the Clipboard:
    1. $ screencapture-c-W
Time-lapse 10 second screenshot and open it in preview:
    1. $ screencapture-t 10-p image.png
Select an area with the mouse and save the content as a PDF file:
    1. $ screencapture-s-T PDF image.pdf
You can see more options by entering Screencapture-help. 5. LaunchctlLaunchctl allows you to interact with OS X's init scripting system launchd. By starting the daemon and starting the agent, you can control your startup service items when you start your PC. You can even perform operations at regular or specified intervals by writing scripts, similar to the Corn tool in Linux. For example, when you want to start the Apache server automatically when you start your Mac, you can enter:
    1. $ sudo launchctl load-w/system/library/launchdaemons/org.apache.httpd.plist
By running the Launchctl list, the startup scripts loaded in all current states are listed. The sudo launchctl unload [path/to/script] command stops and unloads the running script, which, when added with the-W flag, will permanently purge the script from your startup queue. I like to use this command to terminate the "assistant" that runs all the Automatic Updates like Adobe programs and Microsoft Office. The startup scripts are stored in the following locations:
    1. ~/library/launchagents
    2. /library/launchagents
    3. /library/launchdaemons
    4. /system/library/launchagents
    5. /system/library/launchdaemons
For a detailed mechanism to understand the startup process and launch agent, you are recommended to browse Paul Annesley's blog, which will take you to the content from the file format. And if you want to learn how to write your own startup scripts, Apple has a lot of helpful documentation on their developer sites for reference. If you want to avoid command-line operations altogether, there is also a great program called Lingon that can help you. 6. SayThis is an interesting command: Say converts text to speech using the text-to-speech system used by voiceover in OS X. Without any options, the say command translates any text content you enter into speech output:
    1. $ say "Never trust a computer you can ' t lift."
You can use the say command with the-f flag to read the contents of a text document while using the-O identity to save the output's audio content:
    1. $ say-f Mynovel.txt-o Myaudiobook.aiff
The say command can be used for script console logs and alarm sounds. For example, you can set up batches or hazel scripts to process files and use the say command to issue reminders after processing is complete. But the best way to play with the say command is sinister: if you have SSH access to your friend or colleague's Mac, you can log on to their computer silently via the command line. Then give them a siri-ous surprise. You can set the voice (and language) of the say command in the dictation and Speech panel in System Preferences. 7. DiskutilDiskutil is in OS X Disk Management Toolscommand-line interface. It can accomplish any task that its graphical interface brothers can accomplish, and it also contains some additional capabilities-such as writing 0 or random data on a disk. The simple input diskutil list lists the path names of all the disks and links to removable media media on your computer, and then points to the commands for the volume you want to manipulate. Note: If you use the Diskutil command incorrectly, the data on the disk will be permanently clear. 8. BrewWell, this is strictly not a local command. However, none of the OS X advanced users will be homebrew away. Its official website defines it as "The missing package management tool on OS X", which is said to be correct. If you have used the Apt-get command on a Linux system, you will find the sense of organization in homebrew. Brew makes it easy for you to get thousands of open utilities and repositories from the open source community. For example, the Brew install ImageMagick command installs the ImageMagick tool for you, which enables a powerful toolkit that can engage any conversion task from GIF animations to dozens of different types of images. The Brew Install node command installs Nodejs for you, which is the latest hot tool for developing and running JavaScript programs on the server side. You can also use homebrew to get fun: The Brew install Archey command installs Archey for you, a cool script to display your Mac's configuration in a colorful Apple logo. Homebrew has a wide selection of options, and it's easy to create new rules, and new packages are always added. Archeyarchey-all the configurations in my command-line tool. But what is the biggest advantage of homebrew? It keeps all of its files in a separate directory:/usr/local/. This means that you can install the latest version of the system software without interfering with the system's built-in software, such as Python and MySQL. And when you uninstall the Homebrew installation package, it's easy to remove. 5.15 Modification: I was advised not to blindly delete the contents of the/usr/local/directory. This is a very important precautionary measure. For safe removal of homebrew, use the Unload script. 9. TextutilTextutil uses the cocoa text engine to manipulate documents and can convert between multiple formats, including,. doc,. txt, and. rtf. For example, convert an HTML document into a simple Word document.
    1. $ Textutil-convert HTML Article.doc
Textutil Another interesting feature is the ability to combine multiple files into a single long document. The following command merges three Word documents into one. RTF Document:
    1. $ textutil-cat rtf Article1.doc Article2.doc article3.doc
Ten. SIPsSIPs is an image processing tool that is a native alternative to ImageMagick. Because it's built on Apple's core image, SIPs has a lot of features in terms of color configuration. But it's also a good fast image processing tool such as converting, resizing, cropping, and rotating. This script converts a picture in ipegs format in a file into PNG format:
    1. $ for file in *.jpeg; Do sips-s format png $file--out $file. png
Ssh-add.If you repeatedly use SSH to access a secure server, such as Amazon's EC2, you should know Ssh-add. This command allows you to save the private key file to OS X keychain. You can use SSH commands only once, without having to manually include the private key file or mix ~/. SSH/content before:
    1. $ ssh-i KEYFILE.PEM [Server]
After:
    1. $ ssh-add-k Keyfile.pem
    2. $ SSH [Server]
ManThe man command brings up the help manual that is not unique to OS X, needless to say. But the Twitter user @peternlewis reminds me of the Terminal.cpp feature. If you enter a command name in the Help menu, terminal will automatically bring up the page that is related to it. For more operations on terminal programs, here's a A-Z list of all the available console command lines in OS X 10.9 Mavericks.

Command-line tools on your Mac

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.