OSX – useful Terminal Commands

Here is a list of useful Terminal Commands.
The easiest way to open Terminal is using Spotlight.
Press Command + Space and enter Terminal .
Now you see the Terminal window.

First you will see the prompt which shows your Mac’s Hostname followed by a double dot, a tilde, a blank space and your username.
The tilde is an alias for your user profile path.
If you change the folder (look at the CD command examples) you will see the folder path instead of the tilde.

Clear the Terminal window

To clear the Terminal window, simply use the command clear:clear

After that you’ll see only the Hostname and username with our any informations from earlier used commands.

Navigating to folders

To navigate to folders in Terminal use the Command cd and the folder you want to navigate.
For example the Applications folder use:

If you have some spaces in your folder path you’ll have to use the backslash.
To enter a folder named „unknown artist“ on your desktop use this code:cd /desktop/unknown\ artist
Or you can use quotation marks and any spaces that path contains will be ignored.cd „/desktop/unknown artist
You can also drag and drop the folder from Finder to your Terminal window if you are not sure how to write it.

List the Content of a folder

To show the content of a folder use the LS command:ls
Now you will see all folders and files in that directory

To see a formatted list usels -l

To see all hidden folders and files usels -a

You can combine the list view and the hidden files/folders viewls -la

Check the uptime of your Mac

If you use your Mac like me, it may bee some days / weeks after your last reboot / shutdown.
To see how long you haven’t restarted use the uptime command:uptime

Show / Install available OSX Updates

After Apple moved the Updates to the AppStore we can use Terminal commands to show and install available updates.
To show your available updates use this command:sudo softwareupdate -l
After entering your password it takes a few seconds an you will get a list of all available updates.
Using this command will install all available updates:sudo softwareupdate -ia

Rerun a command

To use the same command again you’ll only have to enter:!!

If you want to enter the same command again with sudo in front of it use:sudo !!

Download a file using Terminal

If you want to download a file without a browser use this command:curl -0 http://url_to_the_fileChange url_to_the_file to your files URL

Shutdown/Reboot your Mac with/without delay

These commands are useful to shutdown / restart remote clients like OSX Servers.
Normally its not that useful on your own Mac.

To shutdown your Mac immediately use:sudo shutdown -h now

To shutdown your Mac in 60 Minutes use:sudo shutdown -h +60

To restart your Mac immediately use:sudo shutdown -r now

To restart your Mac in 60 Minutes use:sudo shutdown -r +60

Prevent OSX from standby

If you don“t want your Mac get in standy use this command:caffeinate
This command will get your Mac awake until you press Control + C to stop it.

If you want to prevent the standby for 10 minutes use:caffeinate -u -t 600
The time value is in seconds!