Linux file and directory operation command 01

2.1 pwd(5*****)

(print work directory) print the working directory (display the current path) followed by - L, which is also - L (logical) by default. If the logical path (equivalent to win's) - P (physical) is displayed, the real physical path will be displayed

[root@oldbody local]# pwd
/usr/local
[root@oldbody local]# cd - return to the last path
/root
[root@oldbody ~]# 
[root@oldbody home]# pwd
/home
[root@oldbody home]# echo $PWD
/home
[root@oldbody ~]# ls -l /etc/init.d
lrwxrwxrwx. 1 root root 11 6 Month 1500:26 /etc/init.d -> rc.d/init.d    Soft connect file
[root@oldbody ~]# cd /etc/init.d
[root@oldbody init.d]# Why does PWD output the current working directory better because of the environment variable $PWD
/etc/init.d  
[root@oldbody init.d]# pwd -L gets the value corresponding to PWD, which is echo $PWD
/etc/init.d
[root@oldbody init.d]# pwd -P shows the directory path of the source file corresponding to the link
/etc/rc.d/init.d
[root@oldbody init.d]#

2.2 cd(5*****)

(change directory) example of changing directory path: if the parameters - L and - P after cd /etc are logical and physical
Absolute path: path starting from / root/test/a/b
Relative path: path not starting from / test/a/b
cd.. /.. parent directory
cd.. /.. /.. upper level directory
cd / direct to / directory
cd - last directory actually - because there is an environment variable of $OLDPWD
cd ~ represents HOME directory because there is a $HOME environment variable
cd.. return to the previous directory. If it is a point, it represents the current directory

such as[root@oldbody oldboy]# The PWD PWD command gets the
/oldboy
[root@oldbody oldboy]# cd /tmp/
[root@oldbody tmp]# CD - CD will get the pathname from the corresponding value of environment variable OLDPWD
/oldboy
[root@oldbody oldboy]# env | grep -i oldpwd     
OLDPWD=/tmp
OLDPWD=/tmp
[root@oldbody oldboy]# 
[root@oldbody oldboy]# cd -
/tmp
[root@oldbody tmp]# env | grep -i oldpwd because you are in the tmp directory, your environment variable OLDPWD=/oldboy where - i is case insensitive
OLDPWD=/oldboy
[root@oldbody tmp]#
[root@key ~]# cd /etc/sysconfig/
[root@key sysconfig]# cd takes the path / root from the environment variable HOME without any parameters
[root@key ~]# cd /etc/sysconfig/
[root@key sysconfig]# cd ~ get path / root from environment variable HOME

2.3 tree(4****)

Tree tree means to display a directory structure in the form of tree. If tree does not take any parameters, it will display the directory structure of all trees
tree -a view hidden files. The first files are all hidden files
tree -d for show directory only
tree -L where l stands for level level
tree -i does not show tree branches are often used with - f parameter
tree -f shows the full path of each file
The method tree-f uses to distinguish files and directories
You can use the rpm -qa tree command to check whether the tree is installed. If the tree is not installed, you can use yum install tree -y to install the tree package LANG=en to adjust the character set to English

[root@oldbody /]# tree /liangli2/
/liangli2/
`-- liangli3

1 directory, 0 files

[root@oldbody key]# tree
.
|-- 1
|-- key1
|   |-- 4
|   `-- 5
|-- key2
|   |-- 4
|   `-- 5
`-- key3
    |-- 4
    `-- 5

10 directories, 0 files
[root@oldbody key]# tree -L 1
.
|-- 1
|-- key1
|-- key2
`-- key3

4 directories, 0 files
[root@oldbody key]# tree -dL 1
.
|-- 1
|-- key1
|-- key2
`-- key3

4 directories
[root@oldbody key]# 

Show full path for each path f full full

[root@oldbody key]# tree -dLf 1
.
|-- ./1
|-- ./key1
|-- ./key2
`-- ./key3

4 directories
[root@oldbody key]#
[root@oldbody sysconfig]# Tree - L 1 - FI / boot / indentation
/boot
/boot/System.map-2.6.32-573.el6.x86_64
/boot/config-2.6.32-573.el6.x86_64
/boot/efi
/boot/grub
/boot/initramfs-2.6.32-573.el6.x86_64.img
/boot/lost+found
/boot/symvers-2.6.32-573.el6.x86_64.gz
/boot/vmlinuz-2.6.32-573.el6.x86_64

3 directories, 5 files
[root@oldbody sysconfig]#
[root@oldbody key]# Tree-f distinguishes files from directory files, and then adds/
.
|-- 1/
|-- key1/
|   |-- 4/
|   `-- 5/
|-- key2/
|   |-- 4/
|   `-- 5/
`-- key3/
    |-- 4/
    `-- 5/

10 directories, 0 files
[root@oldbody key]# 

2.4 mkdir(5*****)

In windows, the path style is c:\data\test, while in Linux, the path style is / data/test. The difference is that there are D and E disks in windows. In Linux, there is only /, which is the example of creating directory at the top of all directories: mkdir /data creates data directory at the root /
-If the directory is being created, the other function of the - p parameter is to create multi-level directories continuously
-The v parameter is to see the process of creating a directory
Or cd /; mkdir data to the root, and then create the data directory, which is the separator of the command
Continuously create directory mkdir -p /liangli/liangli1 create two directories, one is Liangli and the other is liangli1, where liangli1 is under the Liangli directory

[root@oldbody /]# mkdir -pv Tech/{1..3}/{4..6}
mkdir: created directory `Tech/1'
mkdir: created directory `Tech/1/4'
mkdir: created directory `Tech/1/5'
mkdir: created directory `Tech/1/6'
mkdir: created directory `Tech/2'
mkdir: created directory `Tech/2/4'
mkdir: created directory `Tech/2/5'
mkdir: created directory `Tech/2/6'
mkdir: created directory `Tech/3'
mkdir: created directory `Tech/3/4'
mkdir: created directory `Tech/3/5'
mkdir: created directory `Tech/3/6'

[root@oldbody /]# tree /tmp
/tmp
`-- Tech
    |-- 1
    |   |-- 4
    |   |-- 5
    |   `-- 6
    |-- 2
    |   |-- 4
    |   |-- 5
    |   `-- 6
    `-- 3
        |-- 4
        |-- 5
        `-- 6

13 directories, 0 files   
[root@oldbody /]# mkdir /Tech/dir{1..5} five consecutive dir1 dir2 dir3 dir4 dir5 directories
[root@oldbody /]# ls /Tech/
dir1  dir2  dir3  dir4  dir5  liangli.txt  oldboy.txt

Create multiple directories at the same time

[root@oldbody tmp]# mkdir -p test/dir{1..5}  oldboy/{a..g}
[root@oldbody tmp]# tree test oldboy/
test
|-- dir1
|-- dir2
|-- dir3
|-- dir4
`-- dir5
oldboy/
|-- a
|-- b
|-- c
|-- d
|-- e
|-- f
`-- g

12 directories, 0 files
[root@oldbody tmp]#

Clone directory structure

[root@oldbody ~]# tree -if liangli2018/      
liangli2018
liangli2018/dir1
liangli2018/dir1/4
liangli2018/dir1/5
liangli2018/dir1/6
liangli2018/dir1/7
liangli2018/dir2
liangli2018/dir2/4
liangli2018/dir2/5
liangli2018/dir2/6
liangli2018/dir2/7
liangli2018/dir3
liangli2018/dir3/4
liangli2018/dir3/5
liangli2018/dir3/6
liangli2018/dir3/7

15 directories, 0 files
[root@oldbody ~]# Tree - if liangli2018 / -- noreport liangli2018 -- noreport does not display the last line of Statistics
liangli2018
liangli2018/dir1
liangli2018/dir1/4
liangli2018/dir1/5
liangli2018/dir1/6
liangli2018/dir1/7
liangli2018/dir2
liangli2018/dir2/4
liangli2018/dir2/5
liangli2018/dir2/6
liangli2018/dir2/7
liangli2018/dir3
liangli2018/dir3/4
liangli2018/dir3/5
liangli2018/dir3/6
liangli2018/dir3/7
liangli2018
liangli2018/dir1
liangli2018/dir1/4
liangli2018/dir1/5
liangli2018/dir1/6
liangli2018/dir1/7
liangli2018/dir2
liangli2018/dir2/4
liangli2018/dir2/5
liangli2018/dir2/6
liangli2018/dir2/7
liangli2018/dir3
liangli2018/dir3/4
liangli2018/dir3/5
liangli2018/dir3/6
liangli2018/dir3/7

[root@oldbody ~]# tree -if liangli2018/ --noreport liangli2018 >oldboy.txt 
[root@oldbody ~]# cat oldboy.txt 
liangli2018          This is a directory that must exist
liangli2018/dir1
liangli2018/dir1/4
liangli2018/dir1/5
liangli2018/dir1/6
liangli2018/dir1/7
liangli2018/dir2
liangli2018/dir2/4
liangli2018/dir2/5
liangli2018/dir2/6
liangli2018/dir2/7
liangli2018/dir3
liangli2018/dir3/4
liangli2018/dir3/5
liangli2018/dir3/6
liangli2018/dir3/7
liangli2018
liangli2018/dir1
liangli2018/dir1/4
liangli2018/dir1/5
liangli2018/dir1/6
liangli2018/dir1/7
liangli2018/dir2
liangli2018/dir2/4
liangli2018/dir2/5
liangli2018/dir2/6
liangli2018/dir2/7
liangli2018/dir3
liangli2018/dir3/4
liangli2018/dir3/5
liangli2018/dir3/6
liangli2018/dir3/7
[root@oldbody ~]# cd /tmp
[root@oldbody tmp]# mkdir - p 'cat / root / Oldboy. TXT' first execute the contents in the 'back quote' and then execute the mkdir command
[root@oldbody tmp]# ll
total 4
drwxr-xr-x 5 root root 4096 Sep 29 10:42 liangli2018
[root@oldbody tmp]# tree
.
`-- liangli2018
    |-- dir1
    |   |-- 4
    |   |-- 5
    |   |-- 6
    |   `-- 7
    |-- dir2
    |   |-- 4
    |   |-- 5
    |   |-- 6
    |   `-- 7
    `-- dir3
        |-- 4
        |-- 5
        |-- 6
        `-- 7

16 directories, 0 files
[root@oldbody tmp]#

2.5 touch(5*****)

Create a file or update the time stamp view ls /Tech can see the file you created. If the file does not exist, create a new file. If it exists, change the access time of the file, such as atime
Create 10000 files in a row touch stu{1..10000}
-a parameter only changes the last access time of the specified file
-m parameter only changes the last modification time of the specified file
-Tparameter sets the time property of the file
-d parameter sets the time attribute of the specified file
-The r parameter specifies that the time attribute of the file is the same as that of the template file
You can create two files at the same time, touch a.txt b.txt and touch {1..4}.txt
Through the command, you can see that access (- a) modification (- m) changes the time state of (- c) file

[root@oldbody 1]# stat 1.txt 
File: `1.txt'
Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 784979      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2018-06-21 20:16:43.546093627 +0800
Modify: 2018-06-21 20:16:43.546093627 +0800
Change: 2018-06-21 20:16:43.546093627 +0800
[root@oldbody 1]# 
[root@oldbody 1]# If touch-a 1.txt is used, it means that only access and Change timestamps will be changed, and the Change time will be changed no matter what the situation
touch -m 1.txt   Indicates that only the modified and changed timestamps are changed Change Time will change no matter what
[root@oldboy liangli]# stat  -c  %a  a.txt 
644
[root@oldboy liangli]#
-c    Use the specified format instead of the default format  %a Octal authority

//Specify the time attribute to create / modify files (learn)
[root@oldbody tmp]# Touch - D 20201001 1.txt D specifies the file modification time after file creation
[root@oldbody tmp]# ll -h 1.txt 
-rw-r--r-- 1 root root 11 Oct  1  2020 1.txt
[root@oldbody tmp]# ll -h 2.txt 
-rw-r--r-- 1 root root 0 Sep 29 10:57 2.txt     10:57 This time refers to the modification time of the file
[root@oldbody tmp]# Touch - R 2.txt 1.txt r make it consistent with other file time attributes
[root@oldbody tmp]# ll -h 1.txt           
-rw-r--r-- 1 root root 11 Sep 29 10:57 1.txt
[root@oldbody tmp]# Touch - t 201809291110.00 1.txt tset file format
[root@oldbody tmp]# ll -h --full-time  1.txt 
-rw-r--r-- 1 root root 11 2018-09-29 11:10:00.000000000 +0800 1.txt
[root@oldbody tmp]#

2.6 ls(5*****)

List directory file example: ls / column root / directory and file ls -l display time as file or directory modification time
-L long format (the displayed time is the last modification time)
-D directorysview directory
-A all - a lists all files, including hidden files, but excluding. And.. which are directories
-t sort according to the last modified time mtime, and sort by file name by default
-r reverse sort
-i show inode nodes
-h human readable
--Full time output in full time format
-p add only after the directory/
--Time style = long ISO displays the full time attribute parameter (year)
-The F parameter distinguishes between files and directories (add type indicator at the end / @ etc.) understand that adding "" represents executable ordinary files
Add "/" for directory
Add "=" for sockets
Add "|" for FIFOs
Add "@" for symbolic link

[root@oldbody oldboy]# touch oldboy.txt
[root@oldbody oldboy]# LS - LRT R is the meaning of flashback t sorted by modification time 
total 20
-rw-r--r-- 1 root root    0 Jun 26 21:53 yingsui.gz
-rw-r--r-- 1 root root    0 Jun 26 21:53 wodi.gz
-rw-r--r-- 1 root root    0 Jun 26 21:53 oldboy
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xiaofan
-rw-r--r-- 1 root root    0 Jun 26 23:40 oldboy.txt
[root@oldbody oldboy]# 
[root@oldbody ~]# date view system time
Wed Jun 27 20:28:45 CST 2018
[root@oldbody ~]#
ls -l --color=auto   Display color
[root@oldbody oldboy]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldbody oldboy]# The ls -l directory will display the color
total 20
drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext
-rw-r--r-- 1 root root    0 Jun 26 21:53 jeacen
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xingfujie
-rw-r--r-- 1 root root    0 Jun 26 21:53 yingsui.gz
[root@oldbody oldboy]# \ls -l block aliases
total 20
drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext
-rw-r--r-- 1 root root    0 Jun 26 21:53 jeacen
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xiaofan
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xingfujie
-rw-r--r-- 1 root root    0 Jun 26 21:53 yingsui.gz
[root@oldbody oldboy]# 
[root@oldbody oldboy]# \ls -l --color=auto directory will display color
total 20
drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext
-rw-r--r-- 1 root root    0 Jun 26 21:53 jeacen
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xiaofan
drwxr-xr-x 2 root root 4096 Jun 26 21:56 xingfujie
-rw-r--r-- 1 root root    0 Jun 26 21:53 yingsui.gz
[root@oldbody oldboy]# 
[root@oldbody oldboy]# cat 123.log 
key
[root@oldbody oldboy]# grep --color=auto key 123.log we can also color the filtered content
key
[root@oldbody oldboy]# 
[root@oldbody oldboy]# grep --color=auto 3306 /etc/services
mysql           3306/tcp                        # MySQL
mysql           3306/udp                        # MySQL
[root@oldbody oldboy]#
ls -a  Can show hidden and unhide files all
[root@oldbody test]# ls -a shows all files
.  ..  dir1  dir2  dir3  file1.txt  file2.txt  file3.txt

ls -l can display the properties and modification time of the file

L l is equivalent to an alias of ls-l

[root@oldbody test]# ls -l
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldbody test]# 

-The function of H human is to see the size of the file intuitively

[root@oldbody test]# ls -lh
total 12K
drwxr-xr-x 2 root root 4.0K Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4.0K Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4.0K Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]#

-The D directory parameter indicates that only directories are displayed

[root@oldbody test]# ls -l | grep dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
[root@oldbody test]# ll -d dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
[root@oldbody test]# 

-F classify is to add/

[root@oldbody test]# ls -F
dir1/  dir2/  dir3/  file1.txt  file2.txt  file3.txt
[root@oldbody test]#

Production case: find the latest updated file ll RT equals LS LRT

-R reverse reverse sort or reverse sort
-t sorting by modification time is by default sorted by file name
By default, the most recently created files and directories are placed first

[root@oldbody test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]# 
[root@oldbody test]# ll -rt
total 12
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
[root@oldbody test]# 

-i parameter view inode node

[root@oldbody test]# ll -i
total 12
915788 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
915789 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
915790 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
915785 -rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
915786 -rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
915787 -rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]#
[root@oldbody tmp]# Ll -- time style = long ISO -- time style = long ISO parameter use
total 12
-rw-r--r-- 1 root root   21 2018-09-29 11:39 1.txt
-rw-r--r-- 1 root root    0 2018-09-29 11:21 123.txt
-rw-r--r-- 1 root root    0 2018-09-29 10:57 2.txt
drwxr-xr-x 2 root root 4096 2018-09-29 11:19 key
-rw-r--r-- 1 root root    0 2018-09-29 11:18 key.txt
drwxr-xr-x 5 root root 4096 2018-09-29 10:42 liangli2018

2.7 cp(5*****)

You can only copy files without parameters
-a is equivalent to - dpr
-d if the source file is a link file, copy the link file properties instead of the file itself
-p copies the past with the properties of the file instead of using the default properties
-r recursion for copying directories
If there is a test.txt file in the tmp directory and a test.txt file in the mnt directory, then copying the test.txt file in the tmp directory to the mnt directory will prompt by default
Enter the command \ cp /mnt/test.txt /tmp / do not prompt for aliases
Or the path of / bin/cp /mnt/test.txt /tmp / complement cp command is not prompted
Because cp mv rm is a dangerous operation command, which may cause damage to files. We can check the existing alias alias of the system. Alias can be deleted directly by entering the command unalias cp, which can also achieve the effect (not recommended)

[root@oldbody test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
[root@oldbody test]# cp file3.txt file4.txt
[root@oldbody test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 12:17 file4.txt    Time attribute changed
[root@oldbody test]# 
cp    -a      -a Be equal to-pdr      Function: when copying a file or directory in the past, it can ensure that the properties do not change. Copying a file or directory keeps the soft connection of the source file or directory unchanged
[root@oldbody test]# cp file3.txt file5.txt
[root@oldbody test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 12:17 file4.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file5.txt
[root@oldbody test]# 
[root@oldbody test]# Prompt before alias cp-i overwrite
alias cp='cp -i'
[root@oldbody test]# 
[root@oldbody test]# cp -a file3.txt file5.txt
cp: overwrite `file5.txt'? 
[root@oldbody test]# \cp -a file3.txt file5.txt mask aliases
[root@oldbody test]#
[root@oldbody test]# cp -a dir3 dir4 can copy directory
[root@oldbody test]# ll
total 16
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir4
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 12:17 file4.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file5.txt
[root@oldbody test]# 
A{B,C}  Equivalent to AB  AC
[root@oldbody test]# cp -a dir{3,5}
[root@oldbody test]# ll
total 20
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
drwxr-xr-x 3 root root 4096 Jun 28 12:30 dir4
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir5
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 12:17 file4.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file5.txt
[root@oldbody test]# 
cp /etc/ssh/sshd_config {,.ori}  Amount to
cp /etc/ssh/sshd_config cp /etc/ssh/sshd_config.ori   equally
[root@oldbody test]# CP / etc / sysconfig / network scripts / ifcfg-eth0 {,. Ori} backup network card information

2.8 mv(5*****)

Moving files and renaming moving files or directories moving is the meaning of cutting. For example, mv /Tech /liangli move s tech to the liangli directory and also has the function of renaming
mv move files and rename move (rename) files

[root@oldbody test]# The function of renaming mv file{4,6}.txt
[root@oldbody test]# ll
total 20
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3
drwxr-xr-x 3 root root 4096 Jun 28 12:30 dir4
drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir5
-rw-r--r-- 1 root root    0 Jun 28 11:47 file1.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file2.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file3.txt
-rw-r--r-- 1 root root    0 Jun 28 11:47 file5.txt
-rw-r--r-- 1 root root    0 Jun 28 12:17 file6.txt
No such file or directory  There is no file or directory
[root@oldbody test]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'             mv  System Aliases  -i Parameters need prompt before overwriting
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldbody test]# 
//How to move multiple files (the directory / dir1 must exist)
[root@oldbody test]# mv file1.txt  file2.txt  file3.txt  file5.txt  file6.txt dir1/t  file6.txt  dir1/
[root@oldbody test]# ls
dir1  dir2  dir3  dir4  dir5
[root@oldbody test]# cd dir1/
[root@oldbody dir1]# ls
file1.txt  file2.txt  file3.txt  file5.txt  file6.txt
[root@oldbody test]# tree
.
|-- dir1
|   |-- file1.txt
|   |-- file2.txt
|   |-- file3.txt
|   |-- file5.txt
|   `-- file6.txt
|-- dir2
|-- dir3
|-- dir4
|   `-- dir3
`-- dir5

6 directories, 5 files
[root@oldbody test]# 
[root@oldbody test]# File dir1 use file dir1 to check whether dir1 is a file or a directory
dir1: directory
[root@oldbody test]# MV dir1 dir2 dir3 dir4 dir5 move directory move the first n-1 directory to the last directory (dir5 directory must exist)
[root@oldbody test]# tree
.
`-- dir5
    |-- dir1
    |   |-- file1.txt
    |   |-- file2.txt
    |   |-- file3.txt
    |   |-- file5.txt
    |   `-- file6.txt
    |-- dir2
    |-- dir3
    `-- dir4
        `-- dir3

6 directories, 5 files
[root@oldbody test]#

2.9 rm(5*****)

Remove (remove) delete directory and file - f (force) force, - r (recursion, used to delete directory) emphasizes that the delete command should be used with caution, which is very dangerous. Before deleting, you must make a backup first because it cannot be recovered after deleting
Correct delete file pose
1. Use mv command to move to / tmp (Recycle Bin) instead of deleting
2. Reach the destination directory through cd command

Then through find -type f (d) - name '| xargs RM - F
 Or find -type f (d) - name "*. txt" - mtime +7 -exec rm {} \;

Aliases take effect when you type this command. Those passed to it through some pipe characters will not take effect

2.10 rmdir(1*)

Used to delete an empty directory the command does not work when the directory is not empty

-p parameter recursively delete empty directory

[root@oldbody ~]# 
[root@oldbody ~]# mkdir -p oldboy/oldboy1/oldboy2
[root@oldbody ~]# rmdir -p oldboy/oldboy1/oldboy2/
[root@oldbody ~]#

2.11 ln(5*****)

link, you can create hard links and soft links
Hard link ln source file target file (common file character when hard link is generated)
Soft link Ln-S source file target file (the target file cannot exist in advance) (generated symbolic link l type)
Hard links:
In the linux file system, multiple file names pointing to the same inode are normal and allowed hard link files. One of the functions of another portal hard link is to allow a file to have multiple valid path names (multiple portals), so that users can establish a hard link to important files to prevent accidental deletion Source data note: directories cannot be hard links

[root@oldbody ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@oldbody ~]# Ln / etc / hosts hard link
[root@oldbody ~]# ll -ih /etc/hosts hard_link 
654109 -rw-r--r--. 3 root root 158 1 Month 122010 /etc/hosts
654109 -rw-r--r--. 3 root root 158 1 Month 122010 hard_link
[root@oldbody ~]# rm -f /etc/hosts delete
[root@oldbody ~]# cat /etc/hosts
cat: /etc/hosts: There is no file or directory
[root@oldbody ~]# cat hard_link 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@oldbody ~]# ln hard_link /etc/hosts
[root@oldbody ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@oldbody ~]# ll -ih /etc/hosts hard_link 
654109 -rw-r--r--. 3 root root 158 1 Month 122010 /etc/hosts
654109 -rw-r--r--. 3 root root 158 1 Month 122010 hard_link
[root@oldbody ~]#

Summary of hard link knowledge:

1. Multiple files with the same inode node number are hard linked to each other
2. Delete the hard link file or any of the source files. The file entity is not deleted
3. The file entity will be deleted only if the source file and all corresponding hard link files are deleted
4. When all hard link files and source files are deleted and new data is stored, the space of this file will be occupied. Or when fsck is checked, the deleted data will also be recycled by the system (form a good habit of deleting and multiple sets of environmental tests)
5. The hard link file is another entry of the file (equivalent to the front door and back door of the supermarket)
6. Hard link files can be set for files to prevent important files from being deleted by mistake
7. The hard link file can be created by executing the command ln source file hard link file
8. The hard link file is a common file, so you can delete it with rm command
9. For static files (files that are not being called by the process), when the number of corresponding hard links is 0 (I link), the viewing method of I link is deleted (the third column of ls-l result is as follows)

Soft link or symbolic link is equivalent to win shortcut note: directory can create soft link
Ln-S source file target file

Summary of soft link knowledge:

1. The soft link is like a win shortcut (you can view its point through readlink)
2. Soft link is similar to a text file, which stores the path of the source file and points to the entity of the source file
3. Delete the source file. The soft link file still exists, but the content of the path to the source file cannot be accessed
4. In case of failure, it is generally indicated by flashing white words and red background
5. Execute the command Ln-S source file soft link file to complete the creation of soft link (the target cannot exist)
6. Soft links and source files are different types of files, as well as different files, with different inode numbers
7. The type of soft link file is (l). You can use rm command

[root@oldbody ~]# ln -s /etc/hosts soft_link
[root@oldbody ~]# ll -ih /etc/hosts hard_link soft_link 
654109 -rw-r--r--. 3 root root 158 1 Month 122010 /etc/hosts
654109 -rw-r--r--. 3 root root 158 1 Month 122010 hard_link
915785 lrwxrwxrwx  1 root root  10 9 Month 2913:34 soft_link -> /etc/hosts

Overall conclusion:

Deleting the source file has no effect on the hard link, but it will lead to the failure of the soft link file, and the white words will flash on the red background
Delete the source file and hard link file. The whole file will be deleted
The snapshot function in many hardware devices is based on the principle of hard link

[root@oldbody liangli2018]# ll -ihd oldboy  oldboy/. oldboy/test/..
915805 drwxr-xr-x 3 root root 4.0K 9 Month 2913:44 oldboy
915805 drwxr-xr-x 3 root root 4.0K 9 Month 2913:44 oldboy/.
915805 drwxr-xr-x 3 root root 4.0K 9 Month 2913:44 oldboy/test/..

Summary of links to the table of contents:

1. Hard links can not be created for directories, but soft links can be created (because directories can cross file systems)
2. Soft link to directory is a common skill in production scenario operation and maintenance
3. The hard link of the directory cannot cross the file system (it can be understood from the hard link principle that the hard link needs the same inode value)
4. There is a hard link "." under each directory and a hard link ".." corresponding to the parent directory
5. Create a subdirectory in the parent directory. The number of links to the parent directory increases by 1 (each subdirectory has.. to point to the parent directory). However, the number of links to the parent directory will not increase when files are created in the parent directory

2.12 readlink(2**)

Viewing the contents of a symbolic link file

[root@oldbody ~]# readlink soft_link 
/etc/hosts

Keywords: Linux Attribute MySQL ssh

Added by Lind/swe on Wed, 11 Dec 2019 09:05:45 +0200