Greetings people of Dec π. This is Thanos (or d3adr1nger, as I go in the e-hood) back with a bite-sized treat of tech wizardry. Today, we're diving into a secret corridor of the Mac Terminal β a warm alley full of surprises known as aliases. Well... let's face it, I'm all about getting things done with minimal effort. Why type a paragraph when a word will do? That's the beauty of aliases β they're our sneaky shortcut in the command-line realm, turning tedious typing into a one-hit wonder. So, for my fellow efficiency enthusiasts (and yes, the proudly lazy among us), let's dive into the art of aliasing!"
A command alias in computing is essentially a shortcut to run a specific command or set of commands. Think of it as a nickname you give to a longer command or a series of commands, so you don't have to type out the entire thing every time you want to execute it. In the context of the Mac Terminal, which typically runs the Zsh (Z Shell) as its default shell since macOS Catalina, aliases are incredibly handy for saving time and reducing repetitive typing.
How-To: Crafting Your First Alias on Your MacBook
So let's get down to business ( πΆ I don't got no time to play around, what is this? πΆ). Creating your first alias on your MacBook is like a walk in the park. Hereβs a step-by-step guide to make you an alias pro in no time:
-
Open Terminal: Let's start by firing up the Terminal. You can find it in your Applications folder under Utilities, or just hit
Command + Space
and type "Terminal". Or if you've followed my iTerm2: Your Mac's Terminal, Upgraded! then feel free to follow using your ultra cool customized iTerm2. π€ -
Access the Zsh Configuration File: Now, we need to edit your Zsh configuration file. This is where the magic happens. Type
open -e ~/.zshrc
and hit Enter. This command will open your .zshrc file in TextEdit (or your default text editor). Or if you are an ultra nerd like me you can type:nano ~/.zshrc
to open up the config file directly in your terminal. ( You can become a nuclear nerd and use Vim too, but let's play safe for now π). -
Letβs Make an Alias: Time to create your very own alias. Think of a command you use often. For beginners, letβs start with something simple. Say, we want to create an alias for listing files in a detailed view. Normally, youβd type
ls -l
. We'll make an aliasll
for this. In your .zshrc file, simply add a new line at the bottom:alias ll="ls -l"
-
Save and Close the File: After typing in your alias, save the file and close the editor. ( If you choose to open the file with nano, you can hit
ctrl + x
then justy
andenter
). -
Activate Your Alias: For your alias to take effect, you need to reload your .zshrc file. Go back to the Terminal and type
source ~/.zshrc
. This command refreshes your configuration, activating the alias. - Test Your New Alias: It's showtime! In the Terminal, type ll and hit Enter. VoilΓ ! You should see a detailed list of files in your current directory, just as if you had typed ls -l.
That was it... How easy was that? But wait... It can become much easier!
Creating Aliases with one command at a time
We can deploy our scripting knowledge and come up with a cool command that will create an alias on the spot.
Let's see, let's say that we want to create an alias for quickly editing our zshrc.
The command is: nano ~/.zshrc
. Ok not that bad, but who really wants to remember the name of the file? it would be nice if we could just type something like: edit-zsh
and have it pop up.
#Command No1
echo alias edit-zsh="'nano ~/.zshrc'" >> ~/.zshrc
#Command No2
echo alias sauce="'source ~/.zshrc'" >> ~/.zshrc
#For the last time run to be able to run the aliases on the same terminal
source ~/.zshrc
Break down of the command
- echo: This command is used to output the text that follows.
- alias edit-zsh="'nano ~/.zshrc'": This is the text that will be added to your .zshrc file. It's the definition of your new alias.
- >> ~/.zshrc: This part appends the output of the echo command to the end of your .zshrc file.
After running this command, you'll need to either restart your Terminal or source your .zshrc file with source ~/.zshrc
for the changes to take effect. Once you do that, typing edit-zsh in your Terminal will execute nano ~/.zshrc
.
At the end of the config file that has been opened with nano the following lines.
alias edit-zsh='nano ~/.zshrc'
alias sauce='source ~/.zshrc'
So from now on, you can just restart your terminal by typing sauce π₯«.
Aliases you may like
Since you now have been taught how aliases work you are ready to play around and experiment on your own. Since every crazy experience needs a spark, here is a list of useful aliases to get you started!
Navigation Shortcuts
- alias back="cd ..": Move up one directory level.
- alias back2="cd ../../": Move up two directory levels.
- alias home="cd ~": Go to your home directory.
- alias root="cd /": Go to the root directory.
Listing
- alias ll="ls -lah": Show an extended list of files, including hidden ones.
- alias la="ls -A": List all files, excluding . and ...
File Management
- alias cpi="cp -iv": Copy files with interactive mode and verbose output.
- alias mvi="mv -iv": Move files interactively with verbose output.
- alias rm="rm -i": Remove files with confirmation prompt.
Quick Access
- alias docs="cd ~/Documents": Navigate to the Documents folder.
- alias downloads="cd ~/Downloads": Go straight to Downloads.
Git Shortcuts
- alias gs="git status": Check the status of your Git repository.
- alias ga="git add": Add files to your Git repository.
- alias gc="git commit": Commit changes in Git.
- alias gp="git push": Push changes to a remote Git repository.
- alias gi="git init": Initialize folder as a new repo
- alias gci="ga . && gc -m 'Initial Commit' && gs": First Initial Commit of project.
Here you see for the first time a real glimpse of the power of aliases by chaining aliases to perform a task otherwise quite large.
Aliases for hackers
Nmap Scans
- alias nmapf='nmap -T4 -F': Fast Scan
- alias nmapa='nmap -T4 -A -v': Full Scan
- alias nmapp='nmap -p': Port Scan
Network Requests
- alias curlv='curl -v': Curl with verbose output
- alias get='curl -X GET': HTTP GET
- alias post='curl -X POST': HTTP POST
Searching
- alias ffind='find . -type f -name': Find files
- alias grep='grep --color=auto': Grep with color
SSH and Networking
- alias sshv='ssh -v': SSH with verbose logging
- alias ncl='nc -lvnp': Netcat listener
π Python Server
Love that one:
- alias pyserv='python -m SimpleHTTPServer': Start a simple HTTP server
Always keep in mind that aliases are a personal choice and should fit your workflow. You can customize these aliases to suit your preferences and the specific tasks you perform regularly in penetration testing.
Finishing Up: Your Command-Line, Your Rules
And there you have it, Realmers β a whirlwind tour through the enchanting world of aliases in the Mac Terminal. From the basics to some nifty hacker-style shortcuts, we've covered a lot of ground. Aliases are more than just shortcuts; they're a reflection of your unique style and approach to navigating the digital realm. They're about making your command-line experience not just faster, but also a lot more fun.
Remember, the list of aliases we explored is just the beginning. The real magic happens when you start creating aliases that fit your specific needs. Your Terminal is your playground, and with aliases, you're the one setting the rules. So go ahead, experiment, mix and match, and maybe even come up with something completely out of the box.
In the end, whether you're a coding newbie, a seasoned developer, or a stealthy hacker, aliases can make your life in the Terminal smoother, more efficient, and let's be honest β a whole lot cooler. So, keep exploring, keep tweaking, and most importantly, keep having fun with it. Until next time, this is d3adr1nger signing off. Happy aliasing, and stay curious!
If you liked the post you may also like these ones:
- iTerm2: Your Mac's Terminal, Upgraded!
- Setting up custom local development domains with Apache on Debian-based systems
Or you may like the entire website π€ͺ who knows?
Make sure to pay a visit it will cost you a click: π Sudorealm
Top comments (0)