{"id":554,"date":"2014-01-16T16:58:03","date_gmt":"2014-01-16T23:58:03","guid":{"rendered":"http:\/\/somethingk.com\/main\/?p=554"},"modified":"2014-01-16T16:59:30","modified_gmt":"2014-01-16T23:59:30","slug":"aliases","status":"publish","type":"post","link":"https:\/\/somethingk.com\/main\/aliases\/","title":{"rendered":"Aliases,  loosing command identity&#8230;"},"content":{"rendered":"<p>Today, I was looking into my environment setup and realized, aliases are really useful. So for your enjoyment, here is a quick reference into how to setup and utilize the flexibility of aliases in your own Unix setup.<\/p>\n<p><b>What is alias?<\/b><\/p>\n<p><a title=\"Alias\" href=\"http:\/\/en.wikipedia.org\/wiki\/Alias_(command)\" target=\"_blank\">Aliases<\/a>\u00a0in any platform is a command that lets you replace one word for another. \u00a0Nothing really confusing here. The alias command is:<\/p>\n<pre>alias &lt;NAME&gt;=&lt;VALUE&gt;<\/pre>\n<p>An example:<\/p>\n<pre>alias list='ls \u2013l'<\/pre>\n<p>This will replace any instance where you type list with \u201cls \u2013l.\u201d<\/p>\n<p><a href=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-16-at-6.52.45-PM.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-medium wp-image-555\" alt=\"Screen Shot 2014-01-16 at 6.52.45 PM\" src=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-16-at-6.52.45-PM-300x205.png\" width=\"300\" height=\"205\" srcset=\"https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-16-at-6.52.45-PM-300x205.png 300w, https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-16-at-6.52.45-PM.png 567w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Listing isn\u2019t a big deal, but say you have a really long command, imagine replacing that really long command with one word. Seeing the benefits now?<\/p>\n<p>To get rid of an alias, either close your shell or type the command:<\/p>\n<pre>unalias &lt;NAME&gt;<\/pre>\n<p>This is great and all, but the alias will only work for the current shell it was called in. As soon as I close my shell, my list alias will disappear. What if I want an alias to be a permanent fixture. I want every shell I open to have my list alias. How do I do this? Well, the bash configuration files will help us here.<\/p>\n<p><b>Bash Files for Unix Systems<\/b><\/p>\n<p>When you login to a Unix system over bash shell, ~\/.bash_profile is read. From this file, the shell gathers settings for that particular bash shell. If by chance ~\/.bash_profile is corrupted or does not exist, ~\/.profile is read instead. Say you are already logged into a Unix environment and you open a shell, instead of ~\/.bash_profile being read, ~\/.bashrc is instead reviewed for shell settings.<\/p>\n<p>So ~\/.bash_profile is read by a login shell and ~\/.bashrc is read the other shell. I hate being repetitive. I want my aliases in one spot, I don\u2019t want to have to manage two sets.<\/p>\n<p>Well, there is a really easy fix for this problem! Ensure your ~\/.bash_profile invokes ~\/.bashrc! Check to see if your ~\/.bash_profile has the following lines of code that perform the operation or just add them yourself.<\/p>\n<pre>if [ -f ~\/.bashrc ]; then<\/pre>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 . ~\/.bashrc<\/pre>\n<pre>fi<\/pre>\n<p>Nice, now you can store all your aliases in one place, ~\/.bashrc. I just stuck mine in at the bottom of the file.<\/p>\n<p><b>Example Aliases<\/b><\/p>\n<p>Sudo reboot every time:<\/p>\n<pre>alias reboot='sudo reboot'<\/pre>\n<p>Sudo update application package manager:<\/p>\n<pre>alias update='sudo apt-get upgrade'<\/pre>\n<p>List directories in color:<\/p>\n<pre>alias ls='ls --color=auto'<\/pre>\n<p>Forget vi, always use vim:<\/p>\n<pre>alias vi='vim'<\/pre>\n<p>Show open ports:<\/p>\n<pre>alias ports='netstat -tulanp'<\/pre>\n<p>Directory traversals made easy:<\/p>\n<pre>alias ..='cd ..'<\/pre>\n<pre>alias ...='cd ..\/..'<\/pre>\n<pre>alias ....='cd ..\/..\/..'<\/pre>\n<pre>alias .....='cd ..\/..\/..\/..'<\/pre>\n<p>Go to your web directory:<\/p>\n<pre>alias www='cd \/var\/www\/html'<\/pre>\n<p>Grep with color:<\/p>\n<pre>alias grep='grep --color=auto'<\/pre>\n<p>Remove recursively by force:<\/p>\n<pre>alias rm='rm \u2013rf'<\/pre>\n<p>The possibilities are endless! Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, I was looking into my environment setup and realized, aliases are really useful. So for your enjoyment, here is a quick reference into how to setup and utilize the flexibility of aliases in your own Unix setup. What is alias? Aliases\u00a0in any platform is a command that lets you replace one word for another. \u00a0Nothing really confusing here. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[136,11,5],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-linux","tag-alias","tag-commands","tag-terminal"],"_links":{"self":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":3,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"predecessor-version":[{"id":558,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/554\/revisions\/558"}],"wp:attachment":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}