Sie sind auf Seite 1von 4

OS X Daily - News and Tips for Mac, iPhone, iPad, and Everything Apple

17/10/13 18:22

7 Handy Command Line Tips You Dont Want to Miss


Getting comfortable with the command line is often just a matter of learning a few command tricks and finding uses for them, and were going to offer six handy tricks that youre almost certain to find some use out of regardless of your skill level in the Terminal. Read on, youll be downloading files, using a better directory listing, killing processes quicker, re-running prior commands as root, finding past commands, and creating new files on the fly in no time.

1:Download a File from the Web & Watch Progress


Know the URL of a file that you need to download from the web? Use curl with the O command to start downloading it: curl -O url Be sure to use the full URL. Also, remember to use the upper case O and not the lowercase o to keep the same file name on your local machine. For example, the following command would download the iOS 7 IPSW file from Apples servers to the local Mac, maintaining the same file name as it appears on the remote server: curl -O http://appldnld.apple.com/iOS7/0919495.20130918.FuFu4/iPhone5,1_7.0_11A465_Restore.ipsw Weve covered this trick before quite some time ago and it really is useful. Because it shows download speeds and progress, it can also function as an alternative to the wget trick to test an internet connections speed from the command line.

2: List Directory Contents by Modification Date


Want to long list a directory, showing permissions, users, file size, and modification date, with the most recently modified files and folders appearing from the bottom up? Of course you do:
http://osxdaily.com/ Pgina 1 de 4

OS X Daily - News and Tips for Mac, iPhone, iPad, and Everything Apple

17/10/13 18:22

ls -thor This is extremely useful, and also easy to remember because, well, the command flag is thor, and how could you ever forget about the mythological thor?

3: Search Spotlight with Live Results from the Command Line


The mdfind tool is a command line front-end to the excellent Spotlight search utility, typically accessible from the Finder. But at its default state, mdfind is different from Spotlight search in that it wont update the results live as they are found. Thats what this trick is for, a simple flag will search spotlight from the command line with live updating results: mdfind -time findme This can go awfully quick depending on the specificity of the searched terms, but if you see a match hit Control+C to stop looking. If you have Spotlight disabled or you find its not working, you can always fall back on the trusty find command too.

4: Kill Processes Using Wildcards


Ever wished you could kill a ton of processes or commands at once using wildcards? Or maybe you just want to kill something faster without typing out the full process name or pid? The standard kill command wont take wildcard input, but pkill does accept wildcards, making it the right choice for the job. For example, to kill every active instance of the SampleEnormousTaskNameWhyIsThisProcessNameSoLong process at once, you could use the following: pkill Sam* Remember that wildcards are unforgiving, and pkill ends tasks without hesitation or requesting a save, so if you have any other closely matching process names they will get killed too. The easiest way around that is to just specify a slightly longer element of the task name to target. You can also use pkill to target all of a specific users processes, which can be helpful for some situations on multi-user Macs.
http://osxdaily.com/ Pgina 2 de 4

OS X Daily - News and Tips for Mac, iPhone, iPad, and Everything Apple

17/10/13 18:22

5: Re-Run the Last Command as Root


Dont you hate it when you go to execute a lengthy command and you find out after hitting enter that it requires super user to run? You know, like one of those defaults commands? Dont retype the entire command string, use this simple trick instead: sudo !! This is an oldie-but-goodie trick that has been around for ages, and its sure to get a ton of use as you spend more time at the command line.

6: Get the Last Occurrence of a Command Without Executing It


Cant remember the exact syntax you used the last time you ran a specific command? You can instantly find it without actually executing the command again by using this trick, where searchterm is the command to match: !searchterm:p For example, to find the last full command that used the prefix sudo you would use: !sudo:p This will report something back like the following, giving you the full command syntax, but not running it again: sudo vi /etc/motd Again, this trick will only report back the last time a command was used based on any prefix. If you really need to go digging through your prior command list, you can search through your bash history with grep.

7: Instantly Create a Blank File or Multiple Files


The touch command makes quick work of creating blank files, either for space holders, testing, demonstration, or whatever else your plans may be. The secret is the touch command and its simple to use:

http://osxdaily.com/

Pgina 3 de 4

OS X Daily - News and Tips for Mac, iPhone, iPad, and Everything Apple

17/10/13 18:22

touch filename You can list out multiple names to create multiple files too. For example, this would create three files named index, gallery, and cv, each with the html extension: touch index.html gallery.html cv.html That one is particularly helpful for developers. Want to learn more about Terminal and the command line? We have plenty more command line tricks for those interested.

http://osxdaily.com/

Pgina 4 de 4

Das könnte Ihnen auch gefallen