Change the application call name (ack-grep is used as an example) in Ubuntu

Ubuntu installed an ack-grep to replace the system grep. However, it is always necessary to enter the complete ACK -grep -[options] in the terminal when calling, which is a bit troublesome to enter when searching for many times. We want to change its call name to ACK -[options], so that it is easier to call when searching. You need to change the ack-grep name in the system.

Look at the location of the ack-grep executable:

test@test-Vostro- 3268.:~$ which ack-grep 
/usr/bin/ack-grep
Copy the code

In /usr/bin

To replace the default ack-grep application name, you need to place the soft link of the ack-grep application in a directory before /usr/bin in the PATH environment variable. View system environment variables:

test@test-Vostro- 3268.:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Copy the code

/usr/local/sbin can be used to place a soft link in this directory before /usr/bin.

Before creating a symbolic link, make sure that there is no executable file or soft link with the same name in the target directory:

test@test-Vostro- 3268.:~$ cd /usr/local/sbin/
test@test-Vostro- 3268.:/usr/local/sbin$ls -l ack ls: cannot access ack: there is no such file or directory test@test-Vostro- 3268.:/usr/bin$ ls
wpa_cli  wpa_passphrase  wpa_supplicant  
Copy the code

There is no ACK in the directory

Creating soft Links

test@test-Vostro- 3268.:~$ sudo ln -s /usr/bin/ack-grep /usr/local/sbin/ack
[sudo] password for test: 
Copy the code

The ack test is successful

test@test-Vostro- 3268.:~$ ack
Usage: ack-grep [OPTION]... PATTERN [FILE]

Search for PATTERN in each source file in the tree from cwd on down.
If [FILES] is specified, then only those files/directories are checked.
ack-grep may also search STDIN, but only if no FILE are specified, or if
one of FILES is "-".

Default switches may be specified in ACK_OPTIONS environment variable or
an .ackrc file. If you want no dependency on the environment, turn it
off with --noenv.

Example: ack-grep -i select

Searching:
  -i, --ignore-case     Ignore casedistinctions in PATTERN ... . . . This is version1.92 of ack-grep.
Copy the code

Ack -grep can be called with ACK

The soft link exists in the directory, and the modification is successful

test@test-Vostro- 3268.:/usr/local/sbin$ ls -l ack
lrwxrwxrwx 1 root root 17  2month19 10:35 ack -> /usr/bin/ack-grep
Copy the code