Table of Contents
1. Environment variables
Command search path and sequence
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.
Home Operation and Maintenance Linux Operation and Maintenance Share environment variables and file search examples

Share environment variables and file search examples

Jun 25, 2017 am 10:06 AM
variable document Find environment

"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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? How to transfer files from Quark Cloud Disk to Baidu Cloud Disk? Mar 14, 2024 pm 02:07 PM

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

What is hiberfil.sys file? Can hiberfil.sys be deleted? What is hiberfil.sys file? Can hiberfil.sys be deleted? Mar 15, 2024 am 09:49 AM

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

Detailed explanation of the role of .ibd files in MySQL and related precautions Detailed explanation of the role of .ibd files in MySQL and related precautions Mar 15, 2024 am 08:00 AM

Detailed explanation of the role of .ibd files in MySQL and related precautions MySQL is a popular relational database management system, and the data in the database is stored in different files. Among them, the .ibd file is a data file in the InnoDB storage engine, used to store data and indexes in tables. This article will provide a detailed analysis of the role of the .ibd file in MySQL and provide relevant code examples to help readers better understand. 1. The role of .ibd files: storing data: .ibd files are InnoDB storage

Detailed explanation of log viewing command in Linux system! Detailed explanation of log viewing command in Linux system! Mar 06, 2024 pm 03:55 PM

In Linux systems, you can use the following command to view the contents of the log file: tail command: The tail command is used to display the content at the end of the log file. It is a common command to view the latest log information. tail [option] [file name] Commonly used options include: -n: Specify the number of lines to be displayed, the default is 10 lines. -f: Monitor the file content in real time and automatically display the new content when the file is updated. Example: tail-n20logfile.txt#Display the last 20 lines of the logfile.txt file tail-flogfile.txt#Monitor the updated content of the logfile.txt file in real time head command: The head command is used to display the beginning of the log file

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension ".a" have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run ".a" files. This article will introduce how to comprehensively install and configure the Linux ".a" file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux ".a" file. What is L

Full analysis of Go language file renaming operation Full analysis of Go language file renaming operation Apr 08, 2024 pm 03:30 PM

The os.Rename function is used in Go language to rename files. The syntax is: funcRename(oldpath,newpathstring)error. This function renames the file specified by oldpath to the file specified by newpath. Examples include simple renaming, moving files to different directories, and ignoring error handling. The Rename function performs an atomic operation and may only update directory entries when the two files are in the same directory. Renames may fail across volumes or while a file is in use.

See all articles