Share environment variables and file search examples

零下一度
Release: 2017-06-25 10:06:21
Original
1483 people have browsed it

"Linux Basics (New Edition)" study notes
Attached is the laboratory address:

1. Environment variables

  • declare

    Declare or display shell variables;
    linux $ declare tmp=liming //Create $ echo $tmp //Display $ liming $ unset tmp //Delete

Share environment variables and file search examples

  • The Shell program also runs on the operating system as a process, and most of the commands we run in the Shell will be Run as a child process.

  • Three commands related to environment variables:

    • set // All variables of the current Shell

    • env // Variables related to the current user

    • ##export // Variables that export environment variables from the Shell

Share environment variables and file search examples

  • Regarding which variables are environment variables, they can be simply understood as sub-processes in the current process If it is valid, it is an environment variable, otherwise it is not

    • Note: In order to distinguish it from ordinary variables, we are usually used to set the environment variable name to uppercase.

    • Share environment variables and file search examples

    ##Permanently effective
* 永久的变量和临时的变量(export声明)
* 两个文件:
    * "/etc/bashr // shell变量"
    * "/ect/profile // Share environment variables and file search examples,对所有用户永久生效"
* 用户目录的一个隐藏文件:".profile //只对当前用户生效"
* 如何实现永久:
    * 将需要的Share environment variables and file search examples添加到"/etc/profile"
Copy after login

Command search path and sequence

$ echo $PATH
$ PATH=$PATH:/home/shiyanlou/mybin
// (这里在mybin目录下有自己写的.sh)
// 添加自定义路径到“PATH”Share environment variables and file search examples中
Copy after login

But once you exit the terminal and reopen it, it will become invalid

Achieving global validity

There is a Shell in each user's home directory, and one is executed by default every time it is started. Configure scripts to initialize the environment, including adding some user-defined environment variables, etc.

The configuration file of zsh is .zshrc,

The configuration file of Bash is .bashrc.


They also have one or more global configuration files under etc, but we generally only modify the configuration files in the user directory.

$ echo "PATH=$PATH:/home/shiyanlou/mybin" >> .zshrc
Copy after login

>>

means appending to a file

>

means overwriting to a file

Modify and delete existing variables

Modify variables

##Variable setting method Description${Variable name#matching string}Start matching from the beginning and delete the shortest data that matches the matching string${Variable name##matching string}Start matching from the beginning to the end and delete the longest data that matches the matching string${Variable name% matching string}Start matching from the end to the front, delete the shortest data that matches the matching string${Variable name% % Match string} Match from the end to the front, delete the longest data that matches the matching stringReplace the first string that matches the old string with the new string##${Variable name //Old string/ New string}Replace all strings matching the old string with new strings
$ path=$PATH
$ echo $path
$ path=${path%/home/shiyanlou/mybin}
# 或使用通配符,*表示任意多个任意字符
$ path=${path%*/mybin}
Copy after login
Let the environment variables take effect immediately
$ source .zshrc
 或使用.
$ . ./.zshrc
Copy after login
##${Variable name/old string/new string}
Example:
2. File search

Commonly used search commands:

whereis

Search binary files (- b), man file (-m), source code file (-s)
  • * 通过“/var/lib/mlocate/mlocate.db”数据库
    * 手动更新数据库"updatedb"
    * 例:
    Copy after login
    $ locate /etc/sh //Find files starting with sh in the etc directory $ locate /usr/share/*.jpg // \ escape

  • *
  • -c

    count*
    -i" ignore case
    which

    Can only search for commands from PATH
  • find

  • $ find ~ -mtime 0 //查找当天有改动的文件
    Copy after login
  • The Matrix Digital Rain

    Command: cmatrix

    $ sudo apt-get update;sudo apt-get install cmatrix
    Copy after login

    The above is the detailed content of Share environment variables and file search examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!