With the command line, you can create an alias for a command.
As an example, let’s create an alias
surf that opens up medium.com. To open up medium.com via the command line you need to use
open [URL] syntax:
To create an alias
surf for this command:
- Open up your .bash_profile:
2. Create a new alias
surf by adding the following into the
alias surf='open https://www.medium.com'
3. Save the file and restart the command line window.
4. Now type in
surf and medium.com opens up in the default browser.
View your command line’s command history by typing
history in the command line:
3. Find Commands
This is the one I use a lot. It is a time saver when there is a complex command you’ve run some time ago and you cannot remember/find it.
To find earlier commands from your command line’s history:
- Open up a command line window.
- Start typing (e.g. letters you remember from the command you’re searching for).
- As you type, the command line keeps suggesting a command that matches what you’ve typed. To execute the suggested command, hit enter.
4. Show Hidden Content
To show hidden files and folders, type these two commands:
defaults write com.apple.finder AppleShowAllFiles -bool TRUE killall Finder
Be careful with the hidden files. There is likely a reason why they are hidden by default. Do not delete anything you are not sure you want to delete.
To hide these files back, run the above commands by replacing
5. Move Files
ditto to copy and paste files from a folder to another.
The syntax is:
For example, if you have a folder called
folder1 and you want to create a new folder,
folder2, and copy-paste the contents of
folder1 there, just type:
ditto folder1 folder2
6. Download Files
If you don’t want to use the browser to download a file, the command line can help.
Before downloading with command line, notice that the downloaded file will end up in the directory where you currently are. So if you want it to end up in the
Downloads, change directory there before downloading:
To download the file, use
cURL -O [URL_OF_THE_FILE].
curl -O https://www.medium.com/example_download.txt
7. Keep Mac Awake
To disable your Mac from falling asleep, just type:
To stop caffeinating, just type
To caffeinate for a period of time use
caffeinate -u -t [num_seconds]. For example, let’s caffeinate for 10 minutes (600 seconds):
caffeinate -u -t 600
(Naturally, this can be escaped with
8. View Contents without Opening a File
cat [path_to_file] to view the contents of a file without opening it.
For example, say you have a python file
example.py in your current directory and you want to check its contents with the command line.
To achieve this, just type:
9. Make Your Mac Speak
say [what_to_say] command to make your Mac speak.
For example, to make your Mac say
Hello, World!, run the following command:
say Hello, world!
10. Repeat Characters by Holding Down a Key
Holding a key to repeat characters is something you might be familiar with. By default, this is disabled in a Mac. Luckily, there is a simple way to enable it:
defaults write -g ApplePressAndHoldEnabled -bool FALSE
To revert this change, just run the command above and replace
11. Hide Content
To hide a particular secret file or a folder, use this command:
chflags hidden [path_of_the_folder]
And to make it visible again, use:
chflags nohidden [path_of_the_folder]
For example, given you have a folder called important on your desktop, you can hide it by:
chflags hidden ~/Desktop/important
Keep in mind this doesn’t hide the files completely. For example, you can still run
ls to see the hidden content in the command line.
12. Command Line ASCII Art
To display ASCII art text, use this syntax:
banner -w [banner_width][banner_text]
As an example, let’s print
"Hello" as below:
banner -w 50 Hello
13. Check for macOS Updates
To change the frequency with which your Mac checks for macOS updates from weekly to daily, type:
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
15. List Contents of a Folder and Its Subfolders
ls command lists the contents of a directory. But did you know you can add a
-R to make it list the contents of the subfolders too?
ls -R [path_to_folder]
For instance, if there is a folder called
example in my current directory, I can list all the contents of it with:
ls -R example
Thanks for reading! I hope you enjoyed it!