8

I want to set up a shorter name as an alias of this command:

sudo -i pantheon-files $(pwd)

For example I want to type sfoh (for sudo file open here) and it should run this command.

How do I do this?

6

For this session

Simply run this command:

alias key='your long command'

Permanently

Add the commands as described above into .bash_aliases.

Open scratch with the Applications menu and edit the file .bash_aliases in your home directory. It's a hidden file, so press Ctrl+H to see it.

Or you can type in the terminal: scratch-text-editor ~/.bash_aliases

Then add into it the following line:

alias key='your long command'

To apply the changes immediately run this command:

source ~/.bashrc
  • 1
    That doesn't seem to allow for passing in an option. – Lewis Goddard Jun 30 '15 at 21:24
  • @Tim yes key is the short command – Djax Jun 30 '15 at 21:25
  • @LewisGoddard Don't know what you mean but for his case it works. – Djax Jun 30 '15 at 21:27
  • for those who use zsh, you can add the alias at ~/.zshrc – igrossiter Jun 30 '15 at 21:29
  • @Djax I meant the line alias key=... doesn't take options, like the directory in this example, unless it does and I'm just being silly. – Lewis Goddard Jun 30 '15 at 21:35
4

Creating an alias is quite simple, and it opens a whole realm of possibility for adding shortcuts to your terminal usage.

In General:

Open up ~/.bashrc in your favourite text editor, and add the following to the end:

alias <string>='<full and long command>'

For your specific example:

Again, adding to the end of the .bashrc file:

alias sfoh='sudo -i pantheon-files $(pwd)'

This does not require a restart to take effect, but it will require a new terminal window to be opened so that the ~/.bashrc file can be parsed again.

  • @Tim Technically anywhere is okay, so long as bash loads it, but ~/.bash_aliases is the default I believe. – Lewis Goddard Jun 30 '15 at 21:36
  • @Tim I'm of the belief that the fewer configuration files I have, the better, so I use .bashrc. I've never tried .bashrc_aliases, so YMMV – Bill O'Dwyer Jun 30 '15 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy