Danh mục

16.8. 20 Useful Unix Utilities

Số trang: 12      Loại file: pdf      Dung lượng: 47.64 KB      Lượt xem: 10      Lượt tải: 0    
Hoai.2512

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

16.8. 20 Useful Unix Utilities So far, youve read about only a handful of the hundreds of Unix programs that are built into Mac OS X and ready to run. Yes, ls and sudo are very useful tools, but theyre only the beginning. As you peruse beginner-level Unix books and Web sites
Nội dung trích xuất từ tài liệu:
16.8. 20 Useful Unix Utilities16.8. 20 Useful Unix UtilitiesSo far, youve read about only a handful of the hundreds of Unix programs that are builtinto Mac OS X and ready to run. Yes, ls and sudo are very useful tools, but theyre onlythe beginning. As you peruse beginner-level Unix books and Web sites (see Appendix E),for example, youll gradually become familiar with a few more important terms and tools.Heres a rundown of some more cool (and very safe) programs that await yourexperimentation.Tip: If you dont return to the $ prompt after using one of these commands, type q or, insome cases, quit, and then hit Enter.16.8.1. 20 Useful Unix Utilities16.8.1.1. bcMac OS X and Windows arent the only operating systems that come with a basiccalculator accessory; Unix is well equipped in this regard, too.When you type bc and hit Enter, you get a copyright notice and then…nothing. Just typethe equation you want to solve, such as 2+2, or 95+97+456+2-65,or(2*3)+16595*(2.5*2.5), and then press Enter. On the next line, bc instantly displays theresult of your calculation.(In computer land, * designates multiplication and / represents division. Note, too, that bcsolves equations correctly; it calculates multiplication and division before addition andsubtraction, and inner parentheses before the outer ones. For more bc tricks and tips, typeman bc at the prompt.)16.8.1.2. killMac OS X offers no shortage of ways to cut the cord on a program that seems to belocked up or runnning amok. You can force quit it, use Activity Monitor, or use kill.The kill program in Terminal simply force quits a program, as though by remote control.(It even works when you SSH into your Mac from a remote location, as described inChapter 22.) All you have to do is follow the kill command with the ID number of theprogram you want to terminate.And how do you know its ID number? You start by running top—described in amoment—whose first column shows the PID (process ID) of every running program.Tip: Unless you also use sudo, you can kill only programs that you own—those that arerunning under your account. (The operating system itself—root—is always runningprograms of its own, and its technically possible that other people, dialing in from theroad, are running programs of their own even while youre using the Mac!)When you hear Unix fans talk about kill online, they often indicate a number flag afterthe command, like this: kill -9. This flag is a noncatchable, non-ignorable kill. In otherwords, its an industrial-strength assassin that accepts no pleas for mercy from theprogram youre killing.If you check top and find out that BeeKeeper Pros process ID is 753, youd abort it bytyping kill -9 753 and then pressing Enter.16.8.1.3. openWhat operating system would be complete without a way to launch programs? In MacOS Xs version of Unix, the command is easy enough: open -a, as in open -a Chess. The -a flag allows you to specify an application by name, regardless of where it is on your harddrive, exactly the way Spotlight does it. You can even specify which document you wantto open into that program like this: open -a Preview FunnyPhotoOfCasey.tif.Tip: The -e flag opens any text document in TextEdit (or whatever your default texteditor may be), like this: open -e Diary.txt. This shortcut saves you from having tospecify TextEdit itself.The real utility of this command might not be apparent at first, but imagine doingsomething like this in the Finder: Select from a folder of hundreds of HTML files thosethat contain the word Sequoia in their file names and preview them all withtheOmniWeb browser, regardless of what application theyre actually associated with. Youcould do it with the help of the Spotlight command, but that would take quite a few steps.In Terminal, though, you just switch to that directory (using the cd command) and typeopen -a OmniWeb *Sequoia*. Done!Of course, you may not often bother simply launching programs and documents this way.Nevertheless you can see how useful open can be when youre writing automated scriptsfor your Mac, like those used by the launchd command scheduler program (Section16.8.5.4).16.8.1.4. psThe ps (process status)command is another way to get a quick look at all the programsrunning on your Mac, even the usually invisible ones, complete with their ID numbers.(For the most helpful results, use the -a, -u, -x, and -w flags like this: ps -auxw. For acomplete description of these and other flags, type man ps and hit Enter.)16.8.1.5. shutdownIts perfectly easy to shut down your Mac from the menu. But using shutdown withits -h flag (for halt) in Terminal has its advantages. For one thing, you can control whenthe shutdown occurs, using one of these three options: • Now. You can safely shut down by typing shutdown -h now. (Actually, only the root user is allowed to ...

Tài liệu được xem nhiều: