Linux command--file and directory lookup

Source: Internet
Author: User
Tags aliases

A • File search

Which: the absolute path used to find the command
--Show the absolute path of the shell command
--Simply search for the command you want to find in the PATH variable
--Search for aliases, then find them from path
1. View the user's path variable: The search path for the command
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin

Command not found possible causes:
1) The Wrong knock
2) command not installed
3) The path of the command is not in the definition of the PATH variable

# CP which vim /TMP/VIM2
# VIM2/ETC/PA sswd
Bash:vim2:command not found
#/TMP/VIM2/ETC/PASSWD//absolute path execution
2. Add Paths to Path
1) temporarily modify the path value
# path= $PATH:/tmp//$PATH: Preserving the original value of the variable
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin:/tmp
2) permanently modify the path value will always be used in the work
/etc/profile//Global profile, effective for all users
~username/.bashprofile//local profile, only valid for specific users
# Vim/root/.bashprofile
Path= $PATH: $HOME/bin:/tmp//Add red Section
The above file is not immediately valid, and normally it is executed when the user logs on.
# Source/root/.bashprofile//re-read the configuration file for the changes to take effect
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin:/root/bin:/tmp
Cons: Every time a new terminal or tag is opened, it needs to execute # source/root/.bashprofile
If you want to once and for all, then need to exit the system, re-login, that is, logout.
system--> Log out root--> log out
# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin:/tmp

# which LS
Alias ls= ' ls--color=auto '
/bin/ls
# which VIM
/usr/bin/vim
Alias for Command: Alias
1. See what aliases are present on the system (root and normal user aliases may be different)

2. Set the alias of the command
1) Temporary

2) Permanent, change file
Where is the alias defined?
(1)/ROOT/.BASHRC CP RM MV
(2)/ETC/PROFILE.D
colorls.sh
which2.sh
3. Cancel Aliases
[profile.d]# Unalias VI
[profile.d]# vi/etc/passwd//No color anymore
Locate
--Retrieve files by file name with the fastest retrieval speed
--all the things that can be retrieved are stored in the database.
-Locate limitations, some file systems, some files and some directories are not searched by default
1, suppose I know the name of the NIC configuration file, but do not know the specific path:
# Locate Ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
# Locate Ifcfg
/etc/dbus-1/system.d/nm-ifcfg-rh.conf
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-lo
/sbin/ifcfg
/usr/lib64/networkmanager/libnm-settings-plugin-ifcfg-rh.so
/usr/share/man/man8/ifcfg.8.gz
/var/log/anaconda.ifcfg.log
2. Manually update the database
# CP which vim /ROOT/VIM3
# Locate VIM3//No results found
Cause: Because the locate database is a one-day update, it is not updated in real time.
# UpdateDB
# Locate Vim3
/root/vim3
Database file:/var/lib/mlocate/mlocate.db error:
1) database file does not exist
2) manually generate it
# UpdateDB

3. Locate database configuration file
# vim/etc/updatedb.conf
# LS/TMP/VIM2
/tmp/vim2
# Locate VIM2//cannot be searched because/tmp is in the exclusion list

Linux command--file and directory lookup

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.