Linux environment variables

Source: Internet
Author: User

Which LS (you can see the exact location of LS, LS is a file)

LS ==> ls--color=auto

alias (alias)

which command: Used to find the absolute path to a command .

[[email protected] ~]# which LS

Alias ls= ' ls--color=auto '

/bin/ls

lsis aSpecial command., usingaliasCommandmade an alias.. We used it.lsis actually/bin/ls--color=auto', plus--color=auto, it's colored, otherwise it's all black and white..

alias can be to set the alias of a command can also setting aliases for files .

alias usage of , usually in the work we often use some of the command is longer, each shot to need a good time, then you can use alias to make a short alias, speed up.

Example: (change the NIC configuration File command Vi/etc/sysconfig/network-scripts/ifcfg-eth0)

[[email protected] ~]# alias vieth= ' Vi/etc/sysconfig/network-scripts/ifcfg-eth0 '

[Email protected] ~]# Vieth

The configuration file of the NIC appears after running

Device=eth0

Hwaddr=00:0c:29:bf:07:da

Type=ethernet

uuid=454cbf99-9d6c-40a7-a8f7-646870324602

Onboot=yes

Nm_controlled=yes

Bootproto=static

ipaddr=192.168.1.103

netmask=255.255.255.0

gateway=192.168.1.1

dne1=192.168.1.1

dns2=8.8.8.8

~

~

~

Type:quit<enter> to Exit Vim

This will directly edit the configuration file, and then use which to see.

[email protected] ~]# which Vieth

Alias Vieth= ' Vi/etc/sysconfig/network-scripts/ifcfg-eth0 '

/bin/vi

In this way, the next time you edit the network card configuration file, you can directly use the Vieth command to operate, simple and convenient. To cancel this alias , you only need to unalias vieth .

which This command is usually used only to Query the absolute path of a command , not used frequently.

alias (alias), /bin/ls (absolute path of LS)

Why do we enter a lot of commands without having to use the absolute path of the commands?

This is because the environment variable path is in effect.

Please enter Echo $PATH , here's Echo is actually Print the meaning of, while PATH the front $ indicates that a variable is followed by a .

[Email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Because/bin is in the path setting, it is natural to find LS. If the LS is moved under the/root, and then itself is under the/root, but when the execution of LS, he just ignore you, how to do?

This is because the bad environment variable path does not/root this directory, and the LS moved to the bottom of/root, the natural system can not find the executable file, so you will be prompted: Command not found ! (the command was not found)

[Email protected] ~]# mv/bin/ls/root/

[[email protected] ~]# ls

-bash:/bin/ls: No file or directory

MV used to move a file or directory , you can also Renaming .

So how to overcome this problem?

There are two methods, one of which is Add the/root path directly to the $path !

How to increase?

Command can be used to add commands path= $PATH:/root:

[Email protected] ~]# path= $PATH:/root

[Email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin: /root

[[email protected] ~]# ls

Anaconda-ks.cfg install.log Install.log.syslog ls

The other approach is to use Absolute Path :

[Email protected] ~]#/root/ls

Anaconda-ks.cfg install.log Install.log.syslog ls


This article from "12350027" blog, declined reprint!

Linux environment variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.