Basic knowledge of linux (5)

Supplement the previous chapter about alias, the method to cancel alias is, unalias + alias
user login process
1. When a user logs in, some files will be called (note here, it is user login, not boot)
/etc/profile
/etc/ profile.d/
~/.bash_profile
~/.bashrc
/etc/bashrc
where profile, profile.d/
and bashrc are global variables (all users can read)
.bashrc and .bash_profile (local variables, generally placed in below the user's home directory)

Reading order (that is, the order in which the files are listed above, if the defined variables conflict, the last file to be read is the main one)

PATH variable (can simplify command length)

 [root@localhost boke]# echo $PATH(读取PATH变量时,按顺序读取)
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin/mysql:/root/bin
[root@localhost boke]# which touch
/bin/touch
[root@localhost boke]# /bin/touch 1(因为有了变量,才可以直接touch文件)
[root@localhost boke]# touch 2
[root@localhost boke]# ls
1  2
[root@localhost boke]# echo "bie xiang chuang jian" > /sbin/touch(我们在/bin前面在创建个一模一样的文件)
[root@localhost boke]# chmod a+x /sbin/touch (给权限)
[root@localhost boke]# export PATH(刷新变量)
[root@localhost boke]# touch 3(意思完全变了,因为按照顺序读的事/sbin下面的touch)
[root@localhost boke]# /bin/touch 3(这时候只能你手动来指定了)
[root@localhost boke]# ls
1  2  3
/sbin/touch: line 1: bie: command not found
[root@localhost boke]# rm -f /sbin/touch 
[root@localhost boke]# touch 4(光删除文件是第一步)
-bash: /sbin/touch: No such file or directory
[root@localhost boke]# export PATH(刷新变量,完成复原)
[root@localhost boke]# touch 4
[root@localhost boke]# ls
1  2  3  4
[root@localhost boke]# alias touch='echo hello'(别名也能影响PATH)
[root@localhost boke]# alias touch
alias touch='echo hello'
[root@localhost boke]# touch 5
hello 5
[root@localhost boke]# unalias touch
[root@localhost boke]# touch 5
[root@localhost boke]# ls
1  2  3  4  5

Compression and packaging
https://iask.sina.com.cn/b/17713465.html (I don't understand the principle here...)
There are four kinds of compression in linux

Create a large file
dd if=/dev/zero (extract from the remaining space of=/path/file name bs=1M count=30

 [root@localhost boke]# dd if=/dev/zero of=/usr/local/boke/大文件 bs=1M count=30
30+0 records in
30+0 records out
31457280 bytes (31 MB) copied, 0.144625 s, 218 MB/s
[root@localhost boke]# stat 大文件 
  File: `大文件'
  Size: 31457280    Blocks: 61440      IO Block: 4096   regular file
Device: 802h/2050d  Inode: 937638      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-04-24 13:10:02.272290603 +0800
Modify: 2018-04-24 13:10:02.413290814 +0800
Change: 2018-04-24 13:10:02.413290814 +0800
[root@localhost boke]# 
[root@localhost boke]# zip 大文件.zip 大文件 
  adding: 大文件 (deflated 100%)
[root@localhost boke]# ls
1  2  3  4  5  大文件  大文件.zip
[root@localhost boke]# ll
total 30752
-rw-r--r--. 1 root root        0 Apr 24 12:21 1
-rw-r--r--. 1 root root        0 Apr 24 12:21 2
-rw-r--r--. 1 root root        0 Apr 24 12:26 3
-rw-r--r--. 1 root root        0 Apr 24 12:29 4
-rw-r--r--. 1 root root        0 Apr 24 12:32 5
-rw-r--r--. 1 root root 31457280 Apr 24 13:10 大文件
-rw-r--r--. 1 root root    30704 Apr 24 13:12 大文件.zip
[root@localhost boke]# ll -h
total 31M
-rw-r--r--. 1 root root   0 Apr 24 12:21 1
-rw-r--r--. 1 root root   0 Apr 24 12:21 2
-rw-r--r--. 1 root root   0 Apr 24 12:26 3
-rw-r--r--. 1 root root   0 Apr 24 12:29 4
-rw-r--r--. 1 root root   0 Apr 24 12:32 5
-rw-r--r--. 1 root root 30M Apr 24 13:10 大文件
-rw-r--r--. 1 root root 30K Apr 24 13:12 大文件.zip(因为是空文件,所以压缩的很高)
[root@localhost boke]# unzip -l 大文件.zip (查看zip里的文件有哪些)
Archive:  大文件.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
 31457280  04-24-2018 13:10   ???
---------                     -------
 31457280                     1 file
[root@localhost boke]# 

zip -r + compressed file filename (if the compressed file does not exist, it is recursively compressed for the file, if it already exists, it is added to the compressed file for the file)

[root@localhost boke]# zip -r 大文件.zip 1 
  adding: 1 (stored 0%)
[root@localhost boke]# unzip -l 大文件.zip 
Archive:  大文件.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
 31457280  04-24-2018 13:10   ???
        0  04-24-2018 12:21   1
---------                     -------
 31457280                     2 files

zip -d + zip file filename (delete file)

[root@localhost boke]# zip -d 大文件.zip 1
deleting: 1
[root@localhost boke]# unzip -l 大文件.zip 
Archive:  大文件.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
 31457280  04-24-2018 13:10   ???
---------                     -------
 31457280                     1 file

*(zip can compress a directory, that is to say, after you decompress it, it will also be decompressed for you together with the directory)

unzip + zip file -d /path (specify where to unzip)

The notes are quoted directly. .
gzip the file to be compressed
gzip bigfile //compress the file, delete the source file
gzip -l bigfile.gz //view the contents of the compressed file
gzip -d bigfile.gz //decompress the file
gunzip bigfile.gz //decompress the file No difference with gzip -d

bzip2 the file to be compressed
bzip2 bigfile //compress the file, delete the source file
bzip2 -k bigfile //compress the file and keep the source file
bzip2 -d bigfile.bz2 //decompress the file
bunzip2 bigfile.bz2 //decompress the file No difference from bunzip2 -d

xz file to be compressed
xz bigfile //compress the file, delete the source file
xz -k bigfile //compress the file and keep the source file
xz -d bigfile.xz //decompress the file
unxz bigfile.xz //decompress the file No difference from xz -d

Package
tar -cvf The name of the package needs to be packaged in the file or directory
-c //represents the creation of a package
-v //display process
-f //package name, note that f must be followed by the name of the package
-z //gzip compression
-j //bzip2 compression
-J //xz compression-
x //unpack-
t //query -
r //add a file to the package
--delete //delete a file in the package

Example: tar -cvf root.tar /root //Package /root
tar -r install.log -f root.tar //Append the install.log file to the root.tar package
tar --delete install.log -f root.tar //Delete the install.log file from the root.tar package
tar -tf root.tar //Check what's in the package
tar -xvf root.tar //Unpack the package

tar -zcf root.tar.gz /root //Package and compress /root into gzip format
tar -jcf root.tar.bz2 /root //Package and compress /root into bzip2 format
tar -Jcf root.tar.xz /root //Package and compress /root into xz format
tar -zxf root.tar.gz //Unpack and unpack
root.tar tar -jxf root.tar.bz2 //Unpack and unpack root.tar
* (Additionally, when decompressing, follow the -C / path to decompress to the specified / path)

standard input and standard output

// stdout redirection
> // stdout append redirection

2> //Error output redirection
2>> //Error output additional redirection

&> //All output redirection
&>> //All output append redirection

ll /etc > /tmp/shadow 2> /tmp/out //correct and incorrect use two files to save

ll /etc &> /tmp/out
ll /etc > /tmp/out 2>&1 //The result of both writing methods is the same

< //Standard input
example: cat < /etc/hosts //View /etc/hosts file

cat > /tmp/file < /etc/hosts //input the /etc/hosts file to cat and output it to the /tmp/file file to
cat /etc/hosts > /tmp/file //the effect of this command is the same as above

<< //Followed by a terminator (any terminator), all data before the terminator becomes input

例:
cat << END

lkasdfuiouqwe
zc,mvnlasdkjf
qweoriu,mcnva
end
END
lkasdfuiouqwe
zc,mvnlasdkjf
qweoriu,mcnva
end

cat > /tmp/file << OUT

echo hello
OUT



Software installation
1. Source package installation
2. Binary installation 3. RPM 4.
YUM


Advantages of source code package : can be customized
Disadvantages: complicated operation, long compilation time, very prone to problems or errors
Installation:
1. Download and decompress the source code package
2. Enter the decompressed directory and execute the "./configure" command to do Configuration of the local environment.
3. After the configuration is successful, execute the "make" command to compile the software.
4. After the compilation is successful, execute the "make install" command to complete the installation.
5. Finally, execute the "make clean" command to delete the temporary files generated during installation.
Uninstall:
enter the installation directory and execute the uninstall command "make uninstall" to uninstall.
Note: Not all software packages provide the uninstall function. If it is not provided, it can only be deleted manually.
"./configure --prefix=/usr/local/dir" Install the software to the specified directory, generally installed in /usr/local by default

Binary installation
can be used directly by decompressing

RPM: redhat package management
command syntax
rpm option parameter
requires rpm package, which is generally
a structure named rpm package ending with .rpm

ntfsprogs-2.0.0-13.el6.x86_64.rpm
software name-version number-operating system platform.rpm

Using the rpm command, the software can be installed, inquired, uninstalled, upgraded, and the software that displays the required dependencies

Dependency: A software depends on other software.

Steps to install software by
rpm 1. Download the rpm package
2. Use the rpm command to install "rpm -ivh the full name of the package"
rpm
-i //installation
-v //display process
-h //display the flags listed during installation

Query
-a //Query all software packages
-q //Ask mode
-f //File name, see which software the file is generated by
-l //Display package list
-i //Detailed information of the software package

Upgrade
-U //Upgrade, if the file is not installed, install
-F //Upgrade, if the file is not installed, give up (do not install)

uninstall
-e //uninstall the software
--nodeps -e //do not uninstall dependencies

yum
yum features
1. Automatically solve dependency problems
2. Group packages, you can group RPM packages and install them in the form of group packages
3. yum introduces the concept of warehouse, yum source. Multiple repositories are supported.
4. Simple configuration

/etc/yum.repos.d/ //This directory is the storage directory for the configuration file of the yum warehouse. Note: The configuration file must end with .repo
vim /etc/yum.repos.d/server.repo
[server] //Warehouse Name
name = rhel6.5 repos //Description information of the warehouse
baseurl = http://classroom.example.com/content/rhel6.5/x86_64/dvd/ //The location of the warehouse
enable=1 //Whether the warehouse is enabled (0 It means not enabled, 1 means enabled)
gpgcheck=0 //Whether to enable detection (0 means not enabled, 1 means enabled)

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release //If the detection is 1, then there must be corresponding key parameters.

The location of the warehouse:
local: file:///mnt/ //The first two slashes after the local use format file represent the format The third slash represents the "root"
remote: ftp://
nfs://
http:/ // see what protocol is used

After the configuration is complete, you need to clear the yum cache. After the clearing is complete, create a cache
yum clean all //Clear the cache
yum makecache //Create a cache

Create a local yum repository
1. Download the system image file
wget http://classroom.example.com/content/rhel6.5/x86_64/isos/rhel-server-6.5-x86_64-dvd.iso
2. Mount the image to a local directory
mount -o loop /root/rhel-server-6.5-x86_64-dvd.iso /mnt
3. Create a repository configuration file (must end with .repo)
vim /etc/yum.repos.d/iso.repo
4. Modify the config file
[iso]
name=file repos
baseurl=file:///mnt
enable=1
gpgcheck=0

5. Clear cache, build cache
yum clean all
yum makecache
6. Installation verification

vim advanced use
normal mode insert mode (edit mode) end mode

Normal mode
yy Copy one line (where the cursor is)
p Paste
3yy Copy three lines
dd Delete or move a line Use p to move
G Jump to the last line of
the document gg Jump to the first line of the document
5gg Jump to the 5th line
u Undo
ctrl+r Undo (restore)
0 Move to the beginning of the line
$ Move to the end of the line
/under the keyword search cursor
? Above the keyword search cursor
ZZ Save and exit

i Insert at the current position of the
cursor I Insert at the beginning of the line of
the cursor o Insert a new line below the line
where the cursor is located O Open a new line above the line at the cursor location for insertion
a Insert at the next character position of the
cursor A Insert at the end of the line at the cursor

:set nu //Display line number
:set nonu //Turn off line number display
: nohl //Turn off highlighting:!
Command //Temporarily switch to bash to use the command (command alias is not recognized), any key returns to the document
.! Command//Insert the result of the execution of the command into the edited file
: 3 //Jump to the 3rd line
: s/w/o //The first occurrence of "w" in the line where the cursor is located is replaced by "o"
:s/w/o/g //All "w" in the line where the cursor is located is replaced with "o", g stands for the entire line replacement
: %s/w/o/g //Ignore the cursor position to replace the full text, all Replace "w" with "o"
:% //represents the following substitution to all lines
:w absolute path //save as this file
:r filename //read another document in this document, the display location is Cursor position
: e! // Abandon the modification and reload the original file



Process
pstree //View the process tree

Parent process PPID
child process PID

rhel6: father of all processes init
rhel7: father of all processes systemd

ps aux //Static view, a stands for all, u stands for user, x stands for process without controlling terminal

The state of the process
S: sleep state
R: waiting to run
I: idle state
Z: zombie state
<: the priority of the process is higher
N: the priority of the process is lower
s: the leader of the process
l: multithreaded
+: in the foreground process Group

daemon

ps -ef //Static view, -e represents all processes, -f represents full format list

ps -le //View the priority of the process, focus on the NI column to indicate the priority

pgrep init //Only display the process ID (PID) of the init process
-l //Display the process name
-U username //Display the process ID generated by the user
-t ttyID //Display the process ID generated by the terminal

pidof process name//only display process ID

Dynamic view process
top //Dynamic view process
refreshes every 3 seconds by default, spaces can be refreshed immediately, enter "d" and enter the number of seconds to change the default refresh time

"P" sorts according to CPU occupancy rate
"M" sorts according to memory occupancy rate
"N" sorts according to startup time
"n" Enters the number of processes you want to display on one page
"<" ">" Turn left and right Page
"c" switch of command name, detailed path, command name. The details also include the parameter
"k" to end the process, and the default signal 15 is used

ctrl+c Terminate viewing dynamic process

End the process
kill signal Process ID (PID)
-1 Reset signal, generally used to let the service reload its own configuration file, let the process reload the new configuration information including the configuration file
-9 Force close a process
-15 Wait for the process to be normal The difference between the exit signal and the 9 signal is the write-back of the data stream.

killall process name//end all processes with the same name

pkill //End the corresponding process according to the conditions
-t terminal number
-U username

xkill // point who will die, where not to point where



The priority of the process
ps -le //View the priority
of the NI priority number, the smaller the priority, the higher
the priority number range: -20-19

1. Specify the priority when creating a process
2. Modify the priority of an existing process

nice -n 20 ping 127.0.0.1 //Specify the priority when creating a process
renice -n 0 PID
Example: renice -n 0 26715 //Modify the priority of an existing process

Note: The root user can modify the priority at will.
Ordinary users can only lower the priority. Ordinary users cannot specify a priority less than 0.

Foreground job When the background job
is created, the command is followed by "&" to create the background job
jobs //View the background job
fg background job number //transfer the background job to the foreground
ctrl+z //transfer the triggered foreground job to the background, background Job pause
bg //Let the background job continue to run

Example:
ping 127.0.0.1 > /dev/null & //Create
jobs //View
fg 3 //Move job No. 3 to the foreground
ctrl+z //Move job No. 3 to the background and suspend job
jobs // View the running status
bg //Let the background job continue to run
jobs //Check the running status

Continue tomorrow. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324767063&siteId=291194637