Linux environment variable CP MV and several commands for document viewing

Source: Internet
Author: User

1. Environment Variables

In the literal sense, the environment can be understood as the environment of the entire Linux system, while the variables are either a variable amount or a command.

Then, we can understand the environment variables for Linux, that is, for the entire system of Linux, files or commands .

since it is an environment, then nature can be understood as a path, as well as a file or command that exists in the directory of this path.

Then we can sum it up as:

1, environment variables, is the whole system can be used.

2, environment variable, is a file or command stored in a directory of the system (path).

A such as viewing environment variables;

Echo $PATH

Such as:

[Email protected]:~$ Echo $PATH
/home/nfyx/bin:/home/nfyx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/ Usr/local/games:/snap/bin

Then all the files under the path (directory) shown above can be used anywhere in the system.

(The advantage is that you don't need to enter an absolute path to execute a command, which is a bit like alias)

When you enter a command, it will automatically go to this path to search, if there is a direct execution, if not, it will pop up (not found command) such as:

[Email protected]:~$ DDADASD
DDADASD: Command not found
[Email protected]:~$
If we have some command files ourselves, we need to use them as environment variables.

Then we have to add the path (directory) of these command files to the path of the environment variable;

such as: (We change a CP command to a CPP command)

[Email protected]:~$ cp/bin/c (copy the CP under Bin to the test directory)
Cat Chacl chgrp chmod chown chvt CP cpio
[Email protected]:~$ cp/bin/cp./test/ (Copy the CP under Bin to the test directory)

[Email protected]:~$ cd test/
[Email protected]:~/test$ ls (enter and view)
cp
[Email protected]:~/test$ cp-r/66./88 (copy 66 directory to 88 directory)

[Email protected]:~/test$ ls
cp
[Email protected]:~/test$ MV CP CCP (renamed CP to CCP)
[Email protected]:~/test$ ls (view)

The CCP
[Email protected]:~/test$ CCP (command to run after change)
' CCP ' command not found, with 28 similar commands
CCP: no Command found

[Email protected]:~/test$ pwd
/home/nfyx/test

[Email protected]:~/test$ export path= $PATH:/home/nfyx/test(Add a current path after the environment variable and broadcast)
[Email protected]:~/test$ CCP (re-run, the effect will be different)
CCP: The number of file operands is missing
Try ' CCP--help ' for more information.
[Email protected]:~/test$ ls
The CCP
[Email protected]:~/test$ ccp-r (so we can run the CCP command directly)
[Email protected]:~/test$ ls
The CCP
[Email protected]:~/test$

But the above operation is only temporary, add the environment variable a directory or path, once restarted, will be the message.

To join permanently, you have to do the following:

A:

Vim/etc/profile add in the appropriate location

Path= $PATH:/home/nfyx/test

B:

Add a

customer.sh text files to

/etc/profile.d/ directory, open it and write

Export path= $PATH:/home/nfyx/test

Save exit, to take effect immediately input

Source/etc/profile

After this is saved, it will remain in effect for all users of this operating system.

C:

If you are targeting only one user, do the following

Vim ~/.bash_profile

Add /home/nfyx/test to the back of path

Path= $PATH: $HOME/.local/bin: $HOME/bin:/home/nfyx/test
Export PATH

Save the exit and you're ready.


CP Command (copy files or directories)

To copy a file:

CP soure Destination (soure= source file, destination= target file)

CP file1 File2

Copy directory with parameter-r (single or multiple)

CP soure soure1 ... Destination

Cp-r Dir1 Dir2 (single)

Cp-r dir1 dir2 ... dest_dir (multiple)


MV Command (move or rename)

If you move under the current file, you can change the name in disguise.

Like what:

[Email protected]:~/test/99$ ls
A +-AA bb cc
[Email protected]:~/test/99$ MV (77 renamed to 66)
[Email protected]:~/test/99$ ls
$ A-AA BB cc
[Email protected]:~/test/99$ mv AA./66 (move AA here to 66 below)
[email protected]:~/test/99$ ls./66
Aa
[Email protected]:~/test/99$ ls
BB cc
[Email protected]:~/test/99$
This command is relatively straightforward.

Cat more less Head tail command

This is the command to view the file (but the cat command is often used with more or less)

Such as:

cat/etc/passwd

This is a display of the whole, cannot be seen in part, to see parts that need to be used together with more or less

For example: cat/etc/passwd | less or cat/etc/passwd | more
This way you can look at one screen at a glance.

And the head and tail functions are relatively strong.

The head command looks at the number of rows in front of a file (the default is 10 lines).

Such as:

head/etc/passwd

[Email protected]:~/test/99/88$ head/etc/passwd
Root:x:0:0:root:/root:/bin/bash
Daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
Bin:x:2:2:bin:/bin:/usr/sbin/nologin
Sys:x:3:3:sys:/dev:/usr/sbin/nologin
Sync:x:4:65534:sync:/bin:/bin/sync
Games:x:5:60:games:/usr/games:/usr/sbin/nologin
Man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
Lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
Mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
News:x:9:9:news:/var/spool/news:/usr/sbin/nologin

To see multiple lines, you can use the

Head-#/etc/passwd (#= digit )

Such as:

[Email protected]:~/test/99/88$ head-5/etc/passwd
Root:x:0:0:root:/root:/bin/bash
Daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
Bin:x:2:2:bin:/bin:/usr/sbin/nologin
Sys:x:3:3:sys:/dev:/usr/sbin/nologin
Sync:x:4:65534:sync:/bin:/bin/sync

The tail command, instead of the head command, is the number of rows after a file is viewed

Such as:

[Email protected]:~/test/99/88$ tail/etc/passwd
DNSMASQ:X:112:65534:DNSMASQ,,,:/var/lib/misc:/bin/false
Colord:x:113:123:colord Colour Management daemon,,,:/var/lib/colord:/bin/false
Speech-dispatcher:x:114:29:speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
Hplip:x:115:7:hplip System user,,,:/var/run/hplip:/bin/false
Kernoops:x:116:65534:kernel Oops Tracking Daemon,,,:/:/bin/false
Pulse:x:117:124:pulseaudio Daemon,,,:/var/run/pulse:/bin/false
Rtkit:x:118:126:realtimekit,,,:/proc:/bin/false
Saned:x:119:127::/var/lib/saned:/bin/false
Usbmux:x:120:46:usbmux Daemon,,,:/var/lib/usbmux:/bin/false
Nfyx:x:1000:1000:nfyx,,,:/home/nfyx:/bin/bash

Similarly

Tail-#/etc/passwd (#= digit)

is the same.

Some of these simple commands can be used.

2017.10.25

This article is from the "cow dung also incense" blog, please be sure to keep this source http://ainfyx.blog.51cto.com/724466/1976018

Linux environment variable CP MV and several commands for document viewing

Related Article

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.