Terminal 101: 5 Command Line Shortcuts to Make Your Life Easier
Terminal 101: 5 Command Line Shortcuts to Make Your Life Easier
Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
Last week, we showed you how to create and utilize aliases in the terminal. This week, weâre going to share our favorite aliases with you. These are shortcuts that can be used to make your life easier, and your workflow quicker. From creating directory jumps, to utilizing complex terminal commands, continue reading to learn more.
Creating Aliases
If you donât know how to create and use aliases, go back to last weekâs post and check it out: Terminal 101: Creating Aliases for Commands. When you have an understanding of command line aliases, come back here and learn about our favorites.
1. Jump Through Directories
In the command line, you can make a relative jump by typing "cd ../" to jump to the directory above the current directory youâre browsing. You can keep adding "../" to the statement to jump up multiple levels in the directory structure.
Create the following aliases for easy relative directory jumps. By typing .. you will jump one directory up, and by typing ..4 you will jump 4 directories up in the structure.
alias ..='cd ../'
alias ..2='cd ../../'
alias ..3='cd ../../../'
alias ..4='cd ../../../../'
2. List Directories
When listing the files in the terminal, we often like the view the listing in a column format that displays permissions by typing âls -lâ, but typing this command again and again can get a little old. You can shorten this five character command into two by using the following alias:
alias ls='ls -l'
3. Enable Terminal to Ask Before Deleting a File
In UNIX, the rm command is used to delete a command, but if you add the â-iâ flag to the command, it will ask before deleting a file. Use the following alias to replace the system-default rm command with the interactive version that will prompt you before a file is deleted for good.
alias rm='rm -i'
4. Quickly Enable SSH
When connecting to another machine through SSH, a long command is typically used to establish a connection and enter your username in one fail swoop, but you can easily
alias server_name='ssh -l USERNAME IP_ADDRESS'
Replace USERNAME and IP_ADDRESS above with the appropriate username and IP address of the machine that you wish to connect to. When you are ready to connect, simply enter the alias and type in your password when prompted.
For more information on how to set up and use SSH on your Mac, check our previous post on SSH.
5. Change Commands
If you move around between the Windows command line and UNIX-based commands like those on the Mac, then aliases may be in order so that you donât type the wrong command when using the terminal on your Mac. These aliases are also good for those times when you just canât remember that âcpâ means copy.
alias move='mv'
alias copy='cp'
alias ren='mv'
alias del='rm'
alias cls='clear'
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.
Comment