Alias a tool for shortening long commands


Abarbarian

Acruncher
Joined
Sep 30, 2005
Messages
10,467
Reaction score
940
How to Create Aliases for Customizing Commands in Ubuntu

If you do a lot of installations on your system and wish to avoid using the entire sudo apt-get install command, you can create a short alias for it using the following method:
If you are new to linux then one useful tool to make life easier is the alias tool. The example in the article shows how to simplify a long command to a short usable one.

Here are a few of my own aliases.

Code:
alias sudo="sudo " #Create an alias for sudo with a space at the end then all other aliases will work with #sudo.

alias   w7="sudo mount /dev/nvme0n1p3 /mnt"

alias   w7u="sudo umount /dev/nvme0n1p3"

alias  ls="ls --color=auto"

alias    x="startx"

alias  pacu="pacaur -Syu"

alias  paci="pacaur -S"

alias  pacr="pacaur -Rns"

alias  pacq="pacaur -Q"

alias pacor="pacaur -Rns $(pacman -Qtdq)"

alias  rbs="firejail --private --dns=8.8.8.8 --dns=8.8.4.4 firefox -no-remote"

alias   gf="grim-fandango"

alias   ha="hangman"

alias   boa="flatpak run com.realm667.WolfenDoom_Blade_of_Agony"

alias    ss="scrot -s"
The first alias on my list is a very useful one to implement as it takes away the need to always input a password if some sudo command requires it.

If you do make some aliases then always remember to,

Code:
$ source ~/.bashrc
as your normal user to allow you to use the alias without having to reboot.

:cool:
 

Ian

Administrator
Joined
Feb 23, 2002
Messages
19,037
Reaction score
1,037
A handy tip - I didn't know this was possible!

I often have to run the same long commands on one of the servers, so this is going to save me a lot of typing :).
 
Ad

Advertisements

Abarbarian

Acruncher
Joined
Sep 30, 2005
Messages
10,467
Reaction score
940
A handy tip - I didn't know this was possible!

I often have to run the same long commands on one of the servers, so this is going to save me a lot of typing :).
You can do some pretty clever stuff with alisa's. Here are some more articles with some complicated examples.

https://shapeshed.com/unix-alias/
Why create a shell alias?
For the following example suppose that a user prefers to confirm deleting a file before using the rm command. The rm command supports this with the -i option.

rm -i file.txt
remove file.txt? y

To avoid forgetting to use the -i option each time an alias can be created so that each time rm is run it will use the -i option and prompt the user to confirm.
http://www.linuxhowtos.org/Tips and Tricks/command_aliases.htm


Alias with variables
You can not make aliases with variables. But you can make functions, having a function in your .profile/.bashrc will work just like an alias. To use ssh to copy files to a location on a server you can use

sendpic () { scp "$@" (e-mail address removed):/www/misc/Pictures/; }
http://www.linfo.org/alias.html

For example, if a user often accesses the Apache web server configuration file, which is /etc/httpd/conf/httpd.conf on Red Hat Linux 9, and uses the gedit text editor to read it, such user might type each time:

gedit /etc/httpd/conf/httpd.conf

However, this could quickly become tedious. It would be much easier to make this command into an alias and give it a short name, perhaps even a single letter, such as a:

alias a="gedit /etc/httpd/conf/httpd.conf"

Then, whenever the user wants to open the Apache configuration file using gedit, all that is necessary is to type the following single-letter command and press the ENTER key:

a
Bash Shell Temporarily Disable an Alias

I have couple of shell aliases defined in ~/.bashrc file. How do I temporarily remove (disable) a shell alias and call the core command directly without using unalias command under a bash shell on a Linux or Unix-like systems?
Bash aliases not running or working over ssh client on Unix based system

To solve this problem run ssh command as follows:
$ ssh -t user@remote /bin/bash -ic 'your-alias-here'
$ ssh -t user@remote /bin/bash -ic 'file_repl'
Where ssh command options:

  1. -t : Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful. With the -t option you will get an error that read as “bash: cannot set terminal process group (-1): Inappropriate ioctl for device. bash: no job control in this shell.”
Where bash shell options:

  1. -i : Make the shell is interactive so that it can run bash aliases
  2. -c : Commands are read from the first non-option argument command_string. If there are arguments after the command_string, they are assigned to the positional parameters, starting with $0.
In short run the following command to run a bash aliases called ll:
$ ssh -t (e-mail address removed) -ic 'll'
30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X

Hope some of that is useful to folks. The articles contain most information that an ordinary user would likely need with some more complicated information for folk running servers and remotely accessible pc's.

:cool:
 
  • Like
Reactions: Ian

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top