In various posts in the past, I have given some tips using the Terminal and some comments have arrived about how complicated they may seem. Nonetheless, I still think that the flexibility offered by the tools provided are what make the UNIX/Mac environment so good. So in this post I would like to share some useful tips to use the terminal. Let me know what you think!
1. Download a File from the Web & Watch Progress
If you know the URL of a file that you need to download from the web you can 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.
2. List Directory Contents by Modification Date
You can indeed take a look at the graphical interface, but if all you want is a quick list of the files in a directory showing permissions, users, file size, and modification date, with the most recently modified files and folders appearing from the bottom up then simply type the following:
3. Search Spotlight with Live Results from the Command Line
To do that you can use the mdfind command:
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.
4. Kill Processes Using Wildcards
Simply use the pkill command. For example, if you want to get rid of all the processes that start with “Sam” just type:
5. Re-Run the Last Command as Root
The bang is you friend (!) In order to re-run the last command typed but as roor type the following:
6. Get the Last Occurrence of a Command Without Executing It
Once again, the bang is your friend. Use the following command, where “searchterm” must be substituted by the command you are looking for:
For example, to find the last full command that used the prefix “sudo” you would use:
7. Instantly Create a Blank File or Multiple Files
All you have to do is “touch” the file…
You can list out multiple names to create multiple files too.
Do you have any favourite commands or tips to use the command line? Let me know.