Making an Alias to Shutdown Ubuntu
Ubuntu is a widely used operating system because of its versatile features and security. Most of the professional programmers like to work on it but we don’t like to waste our time when it comes to performing basic functions of the computer through GUI. In this article, we will write an alias to Shutdown a computer using just a single word.
alias shut='echo | sudo -S shutdown now'
In this command, we need to put our password and it will pass it to sudo command while running so you don’t need to put it manually each and every time. As we need root privileges to shutdown our system so we are using sudo, ‘now’ after shutdown command shows we don’t want to wait or set any particular time at which we’d want our system to turn off. We can set particular time as well, Also if we use ‘shutdown -h’, It will shut down exactly after 1 minute.
Alias command is being used to tell our system that whenever we put command ‘shut‘, We’d like it to run this lengthy code.
As alias are not permanent and often session-oriented so we need to put it in .bashrc file to make this alias permanent. To open the .bashrc file in vim, We’ve to use this command ‘vim ~/.bashrc’
Once we are into our bashrc, We need to put this whole alias into the bunch of aliases present in it and to save and quit the .bashrc we need to use :wq command. This command is now bash oriented and will work for every session.
Whenever we will use shut on our terminal, It will shut down our system immediately!