Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Environment variables and file operations

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

I. Environmental variables

Environment variables generally refer to some parameters used in the operating system to specify the operating environment of the operating system, such as: temporary folder location and system folder location.

An environment variable is an object with a specific name in the operating system that contains information that one or more applications will use. For example, the path environment variable in Windows and DOS operating systems. When the system is asked to run a program without telling it the full path where the program is located, the system should look for the program in addition to the current directory. The user sets environment variables to run processes better.

View the current system environment variables with the echo command:

[root@server02 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[root@server02 ~]#

You can modify the PATH environment variable by defining:

[root@server02 ~]# PATH=$PATH:/tmp/[root@server02 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/[root@server02 ~]#

PATH modified in the above way is only valid under the current window, and will be directly invalid after restarting or switching to other windows. By editing the/etc/profile file, redefining PATH at the end of the file will take effect permanently.

II. File operation

cp

1. Command function

Copy one file to another, or multiple files to another directory

2. Command format

cp [options] source dest

cp [options] source directory

3. Parameters

-r Copy directory. If the target directory exists, it will be placed under the target directory; if the target directory does not exist, it will be copied and renamed.

-i comes with parameters. If the target already exists, confirmation is required for operation. The command/usr/bin/cp does not require confirmation.

4. Examples

[root@server02 test]#cp1.txt 2.txtcp: Overwrite "2.txt"? n[root@server02 test]# which cpalias cp='cp -i' /usr/bin/cp[root@server02 test]# /usr/bin/cp1.txt 2.txt[root@server02 test]#[root@server02 test]# cp test1 test2cp: skip directory "test1"[root@server02 test]# cp -r test1 test2[root@server02 test]#

mv

1. Command function

Move one file to another, or multiple files to another directory

2. Command format

mv [options] source dest

mv [options] source directory

3. Parameters

-i comes with parameters. If the target already exists, confirmation is required for operation. The command/usr/bin/mv does not require confirmation.

4. Examples

[root@server02 test]# mv test1 test2[root@server02 test]# which mvalias mv='mv -i' /usr/bin/mv[root@server02 test]# [root@server02 test]# mv 1.txt 2.txtmv: Overwrite "2.txt"? n[root@server02 test]#

cat/tac

1. Command function

cat View the entire contents of the file sequentially

tac View the entire contents of the file in reverse order

2. Command format

cat [options] file

tac [options] file

3. Parameters

-A Displays all characters in the file.

-n Displays file contents with line numbers.

4. Examples

[root@server02 test]# cat 1.txtroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin[root@server02 test]# cat -A 1.txtroot:x:0:0:root:/root:/bin/bash$bin:x:1:1:bin:/bin:/sbin/nologin$daemon:x:2:2:daemon:/sbin:/sbin/nologin$adm:x:3:4:adm:/var/adm:/sbin/nologin$lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin$[root@server02 test]# cat -n 1.txt 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin 3 daemon:x:2:2:daemon:/sbin:/sbin/nologin 4 adm:x:3:4:adm:/var/adm:/sbin/nologin 5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin[root@server02 test]# tac 1.txtlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologinroot:x:0:0:root:/root:/bin/bash[root@server02 test]#

more/less

1. Command function

more/less One screen to view the contents of the file, use the space bar to turn pages

2. Command format

more [options] file

less [options] file

3. Usage

less support "/" sequential search highlight,"? "Reverse search highlighted.

Less can jump to the beginning of a file with g and to the end with G.

head/tail

1. Command function

head View the entire contents of the file sequentially, displaying 10 lines by default

tail View all the contents of the file in reverse order, showing 10 lines by default

2. Command format

head [options] file

tail [options] file

3. Parameters

-n 2 The number of rows displayed is 2.

-f tail command parameters. Dynamic display of file content. It is mainly used for dynamic observation of log changes.

4. Examples

[root@server02 test]# head -2 1.txtroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin[root@server02 test]# tail -2 1.txtmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin[root@server02 test]# tail -f 1.txtroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologin

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report