Linux knowledge point Review: Environment Variable PATH, linux knowledge point path

Source: Internet
Author: User
Tags chrony

Linux knowledge point Review: Environment Variable PATH, linux knowledge point path
2.10 introduction to the PATHwhich command for Environment Variables

Which can view the path where the command is located. which queries the path through the following path:

[root@aminglinux-01 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

This path is separated by: If the command is in the above path, you do not need to enter the absolute path. The actual command is to operate through the absolute path.

Which example
[Root @ hf-01 ~] # Which ls view ls path alias ls = 'ls -- color = auto'/usr/bin/ls [root @ hf-01 ~] # Ls/usr/bin/ls [root @ hf-01 ~] # Cp/usr/bin/ls/tmp/ls2 copy/usr/bin/ls path to/tmp/ls2 [root @ hf-01 ~] #/Tmp/ls2 use the command/tmp/ls2 to view the results, it will be found that the results of the ls command is the same as the anaconda-ks.cfg [root @ hf-01 ~] # Ls anaconda-ks.cfg [root @ ahf-01 ~] # Ls2 execute the ls2 command, will prompt that the command is not found, because this command is not in the above directory-bash: ls2: Not found Command [root @ hf-01 ~] # PATH = $ PATH:/tmp/If you want to directly run the ls2 command, you need to change the environment variable to assign a new value to PATH [root @ hf-01 ~] # Echo $ PATH:/tmp/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin: /tmp/[root @ hf-01 ~] # Ls2 at this time in the run discovery can execute the anaconda-ks.cfg [root @ hf-01 ~] # Which ls2/tmp/ls2
The new environment variable becomes invalid on the terminal.

At this time, on the terminal, copy the SSH channel, open a terminal, execute the ls2 command, and you will find that it is no longer valid (open the terminal method, right-click the terminal-copy the SSH channel) If you want to continue to take effect,

Solution
1. in system vi/etc/profile (this command will be loaded when the terminal is started or opened) 2. add PATH = $ PATH:/tmp/at the end and save and exit 3. check whether the file is successfully loaded by using cat/etc/profile. 4. then echo $ PATH will get/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp /: /root/bin no matter which terminal can execute the ls2 command, it will be executed successfully
Release ls2 command, Method

If you do not want this ls2 command, there are two methods.

1. Method 1: assign a value again

'''Path =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin (remove:/tmp /) at this time, when the ls2 command is executed, it will invalidate '''

1. Method 2: re-edit the file/etc/profile

'''Shortcut key dd command, delete PATH = $ PATH:/tmp/and save: wq to create a terminal, execute echo $ PATH and you will find that the/tmp/directory disappears '''
2.11 cp command

Cp = copy

Usage
Copy the source file to the cp-r directory of the target file. When using cp and other commands, complete the path! $ Last parameter in the previous command, separated by space or exclamation point [root @ hf-01 ~] # Which cpalias cp = 'cp-I '/usr/bin/cp here we will see that the cp command has a-I option by default, which is a security option, ask whether the operation to perform the next step if you do not want to copy, to ask every day, you can copy as follows [root @ hf-01 ~] #/Usr/bin/cp/etc/passwd/tmp/1.txt
Cp example
[Root @ hf-01 ~] # Cp/etc/passwd/tmp/1.txt copy the file and copy it directly. cp: overwrite "/tmp/1.txt "? Y [root @ hf-01 ~] # Cp-r/tmp/aminglinux // tmp/amning copy directory needs to add-r option [root @ hf-01 ~] # Cp-r/tmp/aminglinux // tmp/aming1/[root @ hf-01 ~] # Tree! $ This indicates the last parameter tree/tmp/aming1/tmp/aming1/── 2 ── 2.txt 1 directory, 1 file [root @ hf-01 ~] of the previous command #! Treetree/tmp/aming1 // tmp/aming1/── 2 ── 2.txt 1 directory, 1 file [root @ hf-01 ~] # Tree/tmp/aming1 // tmp/aming1/── 2 ── 2.txt 1 directory, 1 file [root @ hf-01 ~] # Cp-r/tmp/aminglinux // tmp/aming1/[root @ hf-01 ~] # Ls/tmp/aming1/2 aminglinux this indicates that when the target directory already exists, it will place the source directory under the target directory. If the target directory does not exist, he will copy the source directory and modify the name [root @ hf-01 ~] # Tree/tmp/aming1 // tmp/aming1/── 2 │ ── 2.txt ── aminglinux └ ── 2 ── 2.txt 3 directories, 2 files [root @ hf-01 ~] # Cp-r/tmp/aminglinux // tmp/aming1/cp: overwrite "/tmp/aming1/aminglinux/2/2.txt "? N when copying the same directory again, the system will prompt whether to overwrite the directory because the source directory already exists.
! $ And! The meaning of the tree Command! $ Execute the last parameter of the previous command! In the tree execution history, the last command to run the tree cp copies the Directory and adds/

When copying a directory in cp, add/after the directory, because adding/and not adding/in the following command has a very large area.

Summary

When the target directory already exists, it will put the source directory under the target directory. If the target directory does not exist, it will copy the source directory, and modify the name. When copying the same directory again, the system will prompt whether to overwrite the directory because the source directory already exists.

2.12 mv command mv Introduction

Mv = move mv is equivalent to moving the file to a place. If you change the file name in the same directory, you can use this command to move it to a directory and change the file name mv, by default, commands are run with a-I option, which is also a security option.

If you do not need a prompt, you can use the absolute path. If the directory to be moved is moved to a directory that does not exist, it will be changed, which is equivalent to renaming.

Mv example
[Root @ hf-01 ~] # Mv anaconda-ks.cfg anaconda-ks.cfg.1 here is the direct modification of the file name [root @ hf-01 ~] # Lsanaconda-ks.cfg.1 [root @ hf-01 ~] # Cd/tmp/[root @ hf-01 tmp] # ls1.txt aming1 aminglinux amning mysql. sock [root @ hf-01 tmp] # mv aming1/aming/[root @ hf-01 tmp] # lsaming aminglinux amning mysql. sock [root @ hf-01 tmp] # mv aming/aming2/if you move the directory to a non-existing directory, the name [root @ hf-01 tmp] # lsaming2 aminglinux amning mysql is modified. sock [root @ hf-01 tmp] # mv aming2/aminglinux/If the target directory exists, it will put the source directory under the target directory to [root @ hf-01 tmp] # ls aminglinux/2 aming2
Summary

Target file: if the "target file" is a file name, change it to "target file" while moving the file "; if the "target file" is the directory name, move the source file to the "target file. If the source is a directory, the target is also a directory, and the target directory already has the same directory as the source, moving fails. If the target file has the same name as the source file, the target file will be overwritten.

2.13 document view cat/more/less/head/tailcat/tac/more/wc usage
Cat: All files (including characters) in the "-A" command to view the content of the file-n "command line number (tac) in reverse order to view the content of the file. In contrast to cat, more is used to view the content of the file, but it will not be displayed in the same way as cat. Its display mode is a screen-by-screen display. (You can use the space key to view the next line or press ctrl + B to look forward, after the content is viewed, the command runs automatically.) wc-l can view the number of lines in the file [root @ localhost ~] # Wc-l anaconda-ks.cfg.151 anaconda-ks.cfg.1 shows the number of lines to change files
> Append redirection/more

Append redirection adds the content in the file to another file.

[Root @ localhost ~] # Wc-l anaconda-ks.cfg.151 anaconda-ks.cfg.1 [root @ localhost ~] # Cat/etc/passwd> anaconda-ks.cfg.1 this is to add the file content in/etc/passwd to the anaconda-ks.cfg.1 file [root @ localhost ~] # Cat/etc/passwd> anaconda-ks.cfg.1 [root @ localhost ~] # Wc-l anaconda-ks.cfg.193 anaconda-ks.cfg.1 [root @ localhost ~] # Cat/etc/passwd> anaconda-ks.cfg.1 [root @ localhost ~] # Cat/etc/passwd> anaconda-ks.cfg.1
More examples

More command to view text content

When there is a large amount of content, you can click "Space key" to go down one page by one until the content ends and it will automatically exit. To view the previous content, use the "ctrl + B" shortcut key.

[Root @ localhost ~] # More anaconda-ks.cfg.1 # version = DEVEL # System authorization ionionauth -- enableshadow -- passalgo = sha512 # Use CDROM installation mediacdrom # Use graphical install here omitted ....
Less usage

Less is just launched in the European style. It is similar to more.

Supports Blank Space key review on one screen

Shortcut Key ctrl + B forward view shortcut key ctrl + F backward view support direction keys "Up and down keys" view when viewing ends, exit, press "q" (quit) you can also search for the content in the document by adding the content to it with a slash (/) and = Highlight =, for example,/= root = search for and mark the content in the document.

Press the n key to find the next one, and highlight the shortcut key shift + n to search forward. Summary: in fact, it is an uppercase N key, view forward, and a lowercase n key to backward view the question mark? Add search content, search? = Chrony = It is until the end of the article, press the n key, and then search forward, press shift + g key to locate at the end of the line, and press g to locate at the beginning of the line

Summary

The usage of the less command includes all the functions of the more command, so you can use the less

Head and tail usage
Head: view the first 10 rows of the file (10 rows by default)-n number (specify the number of rows to view the file) tail: view the end of the file, last 10 rows-f dynamic display file-n number of lines in the unit of number (the first few lines, which are a few lines)
Head and tail examples
[root@localhost ~]# head anaconda-ks.cfg.1#version=DEVEL# System authorization informationauth --enableshadow --passalgo=sha512# Use CDROM installation mediacdrom# Use graphical installgraphical# Run the Setup Agent on first bootfirstboot --enableignoredisk --only-use=sda[root@localhost ~]# head -n 2 anaconda-ks.cfg.1#version=DEVEL# System authorization information[root@localhost ~]# tail -n 2 anaconda-ks.cfg.1sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinchrony:x:997:995::/var/lib/chrony:/sbin/nologin
Tail-f usage

Run the tail-f command to dynamically display files. Generally, press ctrl + c to exit when you view logs.

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.