How to delete alias linux

How to Create and Remove alias in Linux

Aliases are very useful when it comes to fast working in Linux. We can use alias to run a long or hard remember command with a simple word. There are two types of aliases – temporary and permanent. In this tutorial we are going to cover both topics. All commands have been executed on Ubuntu 16.04 and should work on CentOS/RHEL as well, but they are also compatible for other Linux distros.

Temporary aliases are very easy to create and remove, but they will be lost after terminal close/system reboot.

View Aliases

To view the list of all aliases, we can type:

Create Temporary Aliases

To create a temporary alias, we need to type the following command in the terminal:

Creating temporary alias is very helpful if we are going to run a command after doing changes on the system. For example, we can define alias to check the storage usage of the disk and type alias every time we need to run the desired command. In this particular case we must add the following alias:

Afterward, to check disk space we can run «disk» and will see output like this:

Besides of creating temporary aliases we can define permanent aliases which will be usable whenever you want and won’t be lost even after system reboot. Here are some basic alias examples that are predefined in most of Linux distributions:

Note that alias command applies only to current session.

Create Permanent aliases

To define a permanent alias we must add it in

/.bashrc file. Also, we can have a separate file for all aliases (

/.bash_aliases) but to make this file to work we must append the following lines at the end of the

/.bashrc file, using any text editor:

Also we can use the following command to add alias without opening the

this alias can help us to connect to our vps server via a three-letter command

Here are some examples of permanent aliases that can help in daily work

All created aliases will work next time we log in to via ssh or open new terminal. To apply aliases immediately we can use the following command:

In the second command the “.” acts as source command.

Remove Aliases

To remove an alias we must type:

To remove all defined aliases we must type:

Note that unalias command also applies only to current session.

To remove permanent alias we must delete the appropriate entry in the

As mentioned before we can use unalias command to remove an alias, but that applies only to current session and if we open new terminal (or logging in via ssh) our permanent aliases will be still available.

Note that we have a permanent alias (e.g. alias ping=’ping google.com’) and we add a temporary alias during your session with the same name (e.g. alias ping=’ping facebook.com’), the temporary one will have higher privileges during current session. Thus if we type ping we will actually ping to facebook.com and not google.com until we ssh login again.

Now we know how to add aliases in Linux and make them work for us. Let us know your comments.

Читайте также:  Как изменить размер меню пуск windows 10

Источник

Clear all Linux / UNIX bash shell aliases

How to see a list of bash shell aliases

To get a list of aliases for the current user, run:
alias
OR
alias -p

How to defined a new bash shell alias

The syntax is:
alias name=’value’
The following command create a new alias named c for the commonly used clear command:
alias c=’clear’
Next, to clear the screen, instead of typing clear, the user would only have to type the letter c and press the ENTER key:
c
In this example, when user type nano, open a text editor named vim:
alias nano=’vim’
nano

unalias command syntax to remove aliases

The syntax is:
unalias name
unalias [option] name
To remove alias called foo, enter:
unalias foo
To clear alias named c, enter:
unalias c
Please note that alias command with no arguments or with the -p option prints the list of aliases:
$ alias
Sample outputs:

How to clear all Linux / UNIX bash shell aliases

To remove all bash shell aliases NAMEs from the list of defined aliases pass the -a option as follows and it will remove all alias definitions:
unalias -a
Verify it:
alias
Above command removed all bash shell alias.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Sample Linux session that remove all bash shell aliases

How to remove or clear all Linux and Unix bash shell aliases

Getting help of alias and unalias command

Visit this page or type the following commands:
help alias
help unalias
man alias

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Using alias Command in Linux to Improve Your Efficiency

As it is known, Linux and Unix were created as command line based systems, which means having control of the commands typed is basically the most important thing to be a *nix SysOp.

This is where ‘alias’ command comes to the show and can be extremely useful, especially for security purposes and to simplify work for a system administrator.

Linux alias command

The shell alias is simply a way to reference another command. It can be used to avoid repetitive long typing of commands and shell lines and simplify work or to even make things safer or dumb-proof.

Take a simple example where you have to use ls command to show everything in reverse chronological order. You can type ls -lrta all the time or you create an alias (say) ‘ll’ that will be equivalent to ls -lrta. It will save you a few keystrokes.

In a similar fashion, you can substitute long and complicated commands with small and simple commands by using alias in Linux.

Let’s see how to make alias in Linux.

How to create alias in Linux

I’ll continue with the same example I used above.

You must note a few things:

  • The substituted command is always used under the inverted commas (‘).
  • There must be no spaces before or after the equals sign in the alias command. If you mistakenly put a space, you’ll see an error like alias not found.
  • Be careful in choosing the name of the alias. There are no reserved keywords so you may replace an existing command with a totally irrelevant command.

You can check if a certain command is actually an alias with the type command. For example, in Ubuntu, ls is actually an alias to show you colorful output.

If you want to use the original command, without its aliased version, use single quotes around it.

Now, the alias you just is temporary. If you exit the shell, you’ll lose the alias. You need to make the alias permanent.

Make alias permanent

In order to add aliases that can work in a system all the time, you need to simply edit your user’s (or any other user’s) .bashrc file. Some distributions might suggest using a dedicated .bash_aliases file for storing aliases.

Читайте также:  Windows home общий доступ

This file is located in your /home/ / folder. You can use vim command to edit the file in terminal.

This will immediately open your .bashrc file and you must start adding aliases by the end of the file, just after the last written line of it. You should then source the bashrc file.

I suggest creating either blocks or at least adding commentaries in the file for each of the aliases created so it’s easier in the future to know what is each thing for maintenance purposes.

Creating global aliases for all users

If you want the aliases to be available for all users on your Linux system, you should add the aliases in /etc/bash.bashrc file.

If you don’t have this file, create it.

How to see all the alias set on your Linux system for you

If you want to see all the alias set on the system for you, you can check the configuration file of your shell like

However, a much easier way to see all the alias would be to simply run the alias command without any arguments.

A typically Ubuntu system has the following alias set by default.

How to remove alias

If you want to remove an alias, you can use the unalias command in this manner:

You can remove all alias at once using the -a option:

As with the alias command, changes by unalias command are also temporary. If you wan to remove an alias permanently, you should delete it from the bashrc file.

My favorite alias in Linux I cannot live without

Let me share some aliases that I always use to work more effectively in Linux.

1. Making ‘rm’ safer

As it is well known, rm command is very commonly used day by day and can be also very destructive and disruptive of a system if not properly used.

This is why, I use the following alias:

This makes ‘rm’ command safer as whenever you use it, it will always ask if you are sure you want to perform the infamous removal operation before proceeding, giving you a second and last chance to not break things unintentionally.

2. Making ssh to other systems easier and faster

Sometimes, especially if you use private keys instead of credentials to log in to other Linux systems, it can be easier to set up aliases for each of them with mnemonic names.

As a SysOp, I use SSH for logging in to different Linux servers and I have several private keys, depending on my clients, therefore it helps me to have aliases such as:

As you can see, I have all my private keys in a folder named “SSH-keys” inside my own user’s folder and then I simply create aliases to connect each of them, following a standard of “ssh”+”name of the server”.

This way I only have to remember the name of the server I want to connect and not where the key is located, the name of each key (if they are different) or even the username that needs to be used for each server to connect.

3. Show time or date for day to day things

Some people either because they script things that use specific times or need to consult time and/or date and want to have in specific formats, can get some benefit of aliases by doing:

4. Easily manage your iptables information

Let’s face it: iptables or nftables are not the easiest nor friendly thing in the world and even though it’s not hard, the first time you deal with it is not that easy. This is why using aliases such these ones can make things a lot easier:

5. Update Debian based servers in one single command

I use Ubuntu myself, but you can adapt this for any Red Hat, CentOS servers and ‘yum’ command. On Debian/Ubuntu, updating a server in a single command could be done through an alias such as this one:

6. Add an alias to run alias with sudo

You cannot run an alias with sudo by default. If you want to run an aliased command with root access, you’ll have to create an alias with sudo like this:

Conclusion

As you can see, it all depends on what you do and your creativity, but you can basically take the time to create as many aliases as you need for your day to day tasks and make them easier by using this useful ‘alias’ command in Linux.

Читайте также:  Set java path windows command

Источник

How do I remove an alias?

I want to remove gs alias from my PC. When I type gs it will open GhostScript. But I checked everywhere in the home directory .alias .bash_aliases .bashrc

I also overwrite the gs with my custom alias.

I can’t remove it. And I also type alias in terminal, in the list I couldn’t find it.

Please I want to remove it.

3 Answers 3

The command to remove an alias is unalias so.

NAME

unalias — remove alias definitions

SYNOPSIS

DESCRIPTION

The unalias utility shall remove the definition for each alias name specified. See Alias Substitution . The aliases shall be removed from the current shell execution environment; see Shell Execution Environment .

-a Removes All aliases

/.bashrc , they will come back when you create a new shell (or terminal window). So you should remove the definition of the aliases from where they are stored in order to get rid of them, unless they are temporary aliases.

TL;DR: The command to remove a shell alias is unalias . See the unalias manual. Run:

But if your gs command is not an alias (most likely), it will not help. The response will be something like:

To find the type of the command trouble you’re in, use type built-in shell command:

On my system it says it is an executable:

Compare that with a common alias ll :

See help type for detailed description of the type shell built-in command

You can also check if it is a symbolic link with:

On my system it isn’t:

-rwxr-xr-x 1 root root 14520 Aug 24 17:03 /usr/bin/gs

Otherwise there would be an arrow like this:

-rwxr-xr-x 1 root root 14520 Aug 24 17:03 /usr/bin/gs -> /some/other/file

As pointed out by others, removing the alias from the current shell session is temporary. For permanent removal, you will need to find where it is defined, such as alias gs=xyz , and remove it there, or add unalias gs to your

If it is not an alias, you can locate the package that installed the command and uninstall it. On Debian/Ubuntu for instance:

Источник

Как добавить/удалить алиас(alias) в Linux?

В этой записи, я распишу как добавлять, удалять, а так же как правильно хранить alias (алиас) в Linux. И что нужно сделать, чтобы они постоянно не удалялись после перезагрузки ОС.

Ниже в этом посте «алиас, я буду называть «alias» — как это есть в англ. языке. Чтобы не путать себя и вас тоже.

Создание

Для создания alias, вам написать команду в консоли alias , далее его название и какую команду он будет выполнять. Все просто. Смотрите пример ниже.

В этом примере, я назвал alias wpdir , который вызовет команду cd /var/www/wp-site.ru/public_html/ , то есть перейдет в рабочую директорию с сайтом.

И при вводе wpdir , я теперь всегда буду попадать в папку сайта. В вашем случае — это может быть какой-то другой путь и т.д.

Это очень удобно, потому что не нужно постоянно прописывать пусть до нужной директории. Таким образом можно создать кучу разных alias и вводя 3-4 буквы переходить с одной директории в другую.

Удаление

Если у вас есть alias, которые больше не актуален, то его можно удалить командой unalias .

Посмотреть список активных alias

Введите команду alias и вы увидите список alias’ов, которые есть у вас на текущем пользователе.

Правильное хранение

Для более удобного использования alias, лучше всего создать отдельный файл.

    Переходим в домашнюю директорию — cd

  • Создаем файл .bash_aliases
  • Как это показано ниже:

    • Вводим пароль от root и внутри файла вводите новый alias на каждой строчки.
    • После чего сохраните файл, нажмите Ctrl + X, введите «Y» и нажимаем Enter.
    • После того как файл сохранился, введите source .bash_aliases , чтобы активировать все alias’ы

    Вы возможно спросите: А в чем плюс этого способа?

    Если вы сделали бы без файла, то вам нужно было вводить alias друг за другом в консоль и после того как вы перезагрузили ОС, они у вас удаляться. В случае с файлом — они тоже удаляться, но чтобы восстановить их — вам все лишь нужно написать следующую короткую команду: cd

    && source .bash_aliases и alias из файла снова активируются в системе.

    Источник

    Оцените статью