{"id":11465,"date":"2019-03-14T08:19:03","date_gmt":"2019-03-14T08:19:03","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11465"},"modified":"2019-03-14T08:19:03","modified_gmt":"2019-03-14T08:19:03","slug":"how-to-create-and-use-alias-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-create-and-use-alias-command-in-linux\/","title":{"rendered":"How to Create and Use Alias Command in Linux"},"content":{"rendered":"<p>Linux users often need to use one command over and over again. Typing or copying the same command again and again reduces your productivity and distracts you from what you are actually doing.<\/p>\n<p>You can save yourself some time by creating\u00a0<strong>aliases<\/strong>\u00a0for your most used commands.\u00a0<strong>Aliases<\/strong>\u00a0are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options. Chances are you are already using\u00a0<strong>aliases<\/strong>\u00a0on your Linux system.<\/p>\n<h3>List Currently Defined Aliases in Linux<\/h3>\n<p>You can see a list of defined aliases on your profile by simply executing\u00a0<strong>alias<\/strong>\u00a0command.<\/p>\n<pre>$ alias\r\n<\/pre>\n<p>Here you can see the default aliases defined for your user in\u00a0<strong>Ubuntu 18.04<\/strong>.<\/p>\n<div id=\"attachment_30717\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/List-Aliases-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30717\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/List-Aliases-in-Linux.png\" alt=\"List Aliases in Linux\" width=\"727\" height=\"222\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List Aliases in Linux<\/p>\n<p>As you can see, executing.<\/p>\n<pre>$ ll\r\n<\/pre>\n<p>Is equivalent to running:<\/p>\n<pre>$ ls -alF\r\n<\/pre>\n<p>You can create an alias with a single character that will be equivalent to a command of your choice.<\/p>\n<h3>How to Create Aliases in Linux<\/h3>\n<p>Creating\u00a0<strong>aliases<\/strong>\u00a0is relatively easy and quick process. You can create two types of\u00a0<strong>aliases<\/strong>\u00a0\u2013\u00a0<strong>temporary<\/strong>\u00a0ones and\u00a0<strong>permanent<\/strong>. We will review both types.<\/p>\n<h4>Creating Temporary Aliases<\/h4>\n<p>What you need to do is type the word\u00a0<strong>alias<\/strong>\u00a0then use the name you wish to use to execute a command followed by\u00a0<code>\"=\"<\/code>\u00a0sign and quote the command you wish to alias.<\/p>\n<p>The syntax is as follows:<\/p>\n<pre>$ alias shortName=\"your custom command here\"\r\n<\/pre>\n<p>Here is an actual example:<\/p>\n<pre>$ alias wr=\u201dcd \/var\/www\/html\u201d\r\n<\/pre>\n<p>You can then use\u00a0<code>\"wr\"<\/code>\u00a0shortcut to go to the webroot directory. The problem with that alias is that it will only be available for your current terminal session.<\/p>\n<p>If you open new terminal session, the alias will no longer be available. If you wish to save your aliases across sessions you will need a permanent alias.<\/p>\n<h4>Creating Permanent Aliases<\/h4>\n<p>To keep\u00a0<strong>aliases<\/strong>\u00a0between sessions, you can save them in your user\u2019s shell configuration profile file. This can be:<\/p>\n<ul>\n<li>Bash \u2013\u00a0<strong>~\/.bashrc<\/strong><\/li>\n<li>ZSH \u2013\u00a0<strong>~\/.zshrc<\/strong><\/li>\n<li>Fish \u2013\u00a0<strong>~\/.config\/fish\/config.fish<\/strong><\/li>\n<\/ul>\n<p>The syntax you should use is practically the same as creating a temporary alias. The only difference comes from the fact that you will be saving it in a file this time. So for example, in bash, you can open\u00a0<strong>.bashrc<\/strong>\u00a0file with your favorite editor like this:<\/p>\n<pre>$ vim ~\/.bashrc\r\n<\/pre>\n<p>Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations purposes you can leave a comment before your aliases something like this:<\/p>\n<pre>#My custom aliases\r\n<strong>alias home=\u201dssh -i ~\/.ssh\/mykep.pem tecmint@192.168.0.100\u201d<\/strong>\r\n<strong>alias ll=\"ls -alF\"<\/strong>\r\n<\/pre>\n<p>Save the file. The file will be automatically loaded in your next session. If you want to use the newly defined alias in the current session, issue the following command:<\/p>\n<pre>$ source ~\/.bashrc\r\n<\/pre>\n<p>To remove an alias added via the command line can be unaliased using unalias command.<\/p>\n<pre>$ unalias alias_name\r\n$ unalias -a [remove all alias]\r\n<\/pre>\n<h5>Conclusion<\/h5>\n<p>This was a short example on how to create your own alias and execute frequently used commands without having to type each command again and again. Now you can think about the commands you use the most and create shortcuts for them in your shell.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/create-alias-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux users often need to use one command over and over again. Typing or copying the same command again and again reduces your productivity and distracts you from what you are actually doing. You can save yourself some time by creating\u00a0aliases\u00a0for your most used commands.\u00a0Aliases\u00a0are like custom shortcuts used to represent a command (or set &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/how-to-create-and-use-alias-command-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Create and Use Alias Command in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11465","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11465"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11465\/revisions"}],"predecessor-version":[{"id":11466,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11465\/revisions\/11466"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}