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

Linux file and directory operation command 01

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

2.1 pwd (5*)

(print work directory) Printing the working directory (showing the current path) can be followed by-L by default and-L (logical). In this case, the logical path (equivalent to win)-P (physical) is displayed, and all the real physical paths are displayed.

[root@oldbody local] # pwd/usr/local [root@oldbody local] # cd-returns the last path / root [root@oldbody ~] # [root@oldbody home] # pwd/home [root@oldbody home] # echo $PWD/home [root@oldbody ~] # ls-l / etc/init.dlrwxrwxrwx. 1 root root 11 June 15 00:26 / etc/init.d-> rc.d/init.d soft connection file [root@oldbody] # cd / etc/init.d [root@oldbody init.d] # pwd Why pwd is more sufficient to output the current working directory because of the environment variable $PWD / etc/init.d [root@oldbody init.d] # pwd-L gets the corresponding value of the environment variable PWD is echo $PWD/etc/init.d [root@oldbody init.d] # pwd-P displays the directory path of the link corresponding to the source file / etc/rc.d/init.d [root@oldbody init.d] # 2.2 cd (5*)

(change directory) change directory path example: if the parameters-L and-P after cd / etc, one is logical and the other is physical

Absolute path: path from / start / root/test/a/b

Relative path: path that does not start from / test/a/b

Cd.. /.. Superior directory

Cd.. /.. /.. Superior directory

Cd / directly to / directory

Cd-- the last directory actually-- because there is an environment variable of $OLDPWD.

Cd represents the home directory because there is an environment variable of $HOME.

Cd.. Return to the previous directory, if it is a dot, it represents the current directory

For example, the [root@oldbody oldboy] # pwd pwd command takes / oldboy [root@oldbody oldboy] # cd / tmp/ [root@oldbody tmp] # cd-cd from the variable PWD to obtain the pathname / oldboy [root@oldbody oldboy] # env from the corresponding value of the environment variable OLDPWD | grep-I oldpwd OLDPWD=/tmpOLDPWD=/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 the case-insensitive OLDPWD=/oldboy [root@oldbody tmp] # [root@key ~] # cd / etc/sysconfig/ [root@key sysconfig] # cd gets the path / root [root@key ~] # cd / etc/sysconfig/ [root@key sysconfig] # cd from the environment variable HOME without any parameters. Take the path / root2.3 tree (4 times)

Tree tree means to display a directory structure in the form of a tree. If tree does not take any parameters, it will show the directory structure of all tree.

Tree-a view hidden files. The first files are hidden files.

Tree-d represents only the table of contents

Tree-L where L represents the meaning of the level level to display the specified level

Tree-I does not show branches are often used in conjunction with the-f parameter

Tree-f displays the full path of each file

The method used by tree-F to distinguish between files and directories is the directory ending with /.

You can use the rpm-qa tree command to check whether tree is installed. If 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/ `--liangli31 directory, 0 files [root@oldbody key] # tree. |-- 1 |-- key1 | |-- 4 |`-- 5 |-- key2 | |-- 4 | `--5`-- key3 |-- 4`-- 510 directories, 0 files [root@oldbody key] # tree-L 1. |-- 1 |-- key1 |-- key2`-- key34 directories 0 files [root@oldbody key] # tree-dL 1. |-- 1 |-- key1 |-- key2`-- key34 directories [root@oldbody key] # shows the complete path for each path f full complete [root@oldbody key] # tree-dLf 1. | -. / 1 | -. / key1 | -. / key2` -. / key34 directories [root@oldbody key] # [root@oldbody sysconfig] # tree-L 1-fi / boot/ indentation indentation Not the front branch / 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_643 directories 5 files [root@oldbody sysconfig] # [root@oldbody key] # tree-F is followed by /. |-- 1 / |-- key1/ | |-- 4 / | `--5 / |-- key2/ | |-- 4 / |`-- 5 / `--key3/ |-- 4 /`-- 5 directories, 0 files [root@oldbody key] # 2.4 mkdir (5*)

The path style under windows is c:\ data\ test, while the path style under Linux is / data/test. The difference is that under windows system, there is a disk such as DMague E, which is the only one under Linux. It is the make directorys of all directories. Example: mkdir / data creates a data directory under root /.

The-p parameter if the directory exists in the creation directory, another function of the-p parameter without error is that you can create multi-level directories continuously.

The-v parameter shows what the process of creating a directory looks like.

Or cd /; mkdir data switch to the root, and then create a data directory in it, which is the delimiter of the command

Create a continuous directory mkdir-p / liangli/liangli1 create 2 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 | |`-- 6 `--3 |-- 4 |-- 5`-- 613 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 simultaneously create multiple directories [root@oldbody tmp] # mkdir-p test/dir {1.. 5} oldboy/ {a.. g} [root@oldbody tmp] # tree test oldboy/test |-- dir1 |-- dir2 |-- dir3 |-- dir4`-- dir5oldboy / |-- a |-- b |-- c |-- d |-- e |-- f`-- G12 directories 0 files [root@oldbody tmp] # Clone directory structure [root@oldbody ~] # tree-if liangli2018/ liangli2018liangli2018/dir1liangli2018/dir1/4liangli2018/dir1/5liangli2018/dir1/6liangli2018/dir1/7liangli2018/dir2liangli2018/dir2/4liangli2018/dir2/5liangli2018/dir2/6liangli2018/dir2/7liangli2018/dir3liangli2018/dir3/4liangli2018/dir3/5liangli2018/dir3/6liangli2018/dir3/715 directories 0 files [root@oldbody ~] # tree-if liangli2018/-- noreport liangli2018-- noreport does not display the last line of statistics liangli2018liangli2018/dir1liangli2018/dir1/4liangli2018/dir1/5liangli2018/dir1/6liangli2018/dir1/7liangli2018/dir2liangli2018/dir2/4liangli2018/dir2/5liangli2018/dir2/6liangli2018/dir2/7liangli2018/dir3liangli2018/dir3/4liangli2018/dir3/5liangli2018/dir3/6liangli2018/dir3/7liangli2018liangli2018/dir1liangli2018/dir1/4liangli2018/dir1/5liangli2018/dir1/6liangli2018/dir1/7liangli2018/dir2liangli2018/dir2/4liangli2018/dir2/5liangli2018/dir2/ 6liangli2018/dir2/7liangli2018/dir3liangli2018/dir3/4liangli2018/dir3/5liangli2018/dir3/6liangli2018/dir3/7 [root@oldbody ~] # tree-if liangli2018/-- noreport liangli2018 > oldboy.txt [root@oldbody ~] # cat oldboy.txt liangli2018 this is a must directory liangli2018/dir1liangli2018/dir1/4liangli2018/dir1/5liangli2018/dir1/6liangli2018/dir1/7liangli2018/dir2liangli2018/dir2/4liangli2018/dir2/5liangli2018/dir2/6liangli2018/dir2/7liangli2018/dir3liangli2018/dir3/4liangli2018/dir3/5liangli2018/dir3/ 6liangli2018/dir3/7liangli2018liangli2018/dir1liangli2018/dir1/4liangli2018/dir1/5liangli2018/dir1/6liangli2018/dir1/7liangli2018/dir2liangli2018/dir2/4liangli2018/dir2/5liangli2018/dir2/6liangli2018/dir2/7liangli2018/dir3liangli2018/dir3/4liangli2018/dir3/5liangli2018/dir3/6liangli2018/dir3/7 [root@oldbody ~] # cd / tmp [root@oldbody tmp] # mkdir-p `cat / root/ oldboy.txt` first execute the contents of ``backquotes and then execute the mkdir command [root@oldbody tmp] # lltotal 4drwxr- Xr-x 5 root root 4096 Sep 29 10:42 liangli2018 [root@oldbody tmp] # tree.`-- liangli2018 |-- dir1 | |-- 4 | |-- 5 |-- 6 | `--7 |-- dir2 | |-- 4 | |-- 5 | |`-- 7`-- dir3 |-- 4 |-- 5 |-- 6`-- 716 directories | 0 files [root@oldbody tmp] # 2.5 touch (5*)

Create a file or update a timestamp. Check ls / Tech to see the file you created. If the file does not exist, create a new file. If it does, change the timestamp such as the access time of the file, atime, etc.

Create 10000 files touch stu {1.. 10000} in succession

The-a parameter only changes the last access time of the specified file

The-m parameter only changes the last modification time of the specified file

The-t parameter sets the time property of the file

The-d parameter sets the time property of the specified file

The-r parameter specifies that the time attribute of the file is the same as that of the template file file

You can create two files at the same time, touch a.txt b.txt, or you can use touch {1.. 4} .txt.

Through the command, you can see that you can access (- a) modify (- m) change the time state of (- c) files.

[root@oldbody 1] # stat 1.txt File: `1.txt'Size: 0 Blocks: 0 IO Block: 4096 regular empty fileDevice: 803h/2051d Inode: 784979 Links: 1Access: (0644 Maxima RWHUR Muhammad -) Uid: (0 / root) Gid: (0 / root) Access: 2018-06-21 20 1.txt'Size 1643.546093627 + 0800Modify: 2018-06-21 20: 16root@oldbody 43.546093627 + 0800Change: 2018-06-21 20 touch 20 touch-a 1.txt words of 43.546093627 + 0800 [root@oldbody 1] # Indicates that only the access is changed and the timestamp is changed Do not change the modified timestamp where the Change time will change in any case touch-m 1.txt means that only the modified and changed timestamp will be changed in which the Change time will change in any case [root@oldboy liangli] # stat-c% an a.txt 644 [root@oldboy liangli] #-c uses the specified format instead of the default format an octal permission refers to Fixed time attribute create / modify file (understand) [root@oldbody tmp] # touch-d 20201001 1.txt d specify 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 means The modification time of the file [root@oldbody tmp] # touch-r 2.txt 1.txt r makes 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 t set the text format [root@oldbody tmp] # ll-h-- Full-time 1.txt-rw-r--r-- 1 root root 11 2018-09-29 1115 00.000000000 + 0800 1.txt [root@oldbody tmp] # 2.6ls (5*)

List (list) list directory file example: ls / column root / directory directory and file ls-l display time is the modification time of the file or directory

-l long long format (the time shown is the time of the last modification)

-d directorys view table of contents

-an all-A lists all files, including hidden files, but does not include. And... These two are catalogs.

-t is sorted according to the last modification time mtime, by default by file name

-r reverse sort

-I display the inode node

-h Human readable

-- full-time output in full time format

-p only add / to the directory

-- time-style=long-iso displays the full time attribute parameter (year)

The-F parameter distinguishes between files and directories (adding a type indicator / @, etc.) to understand that "" represents an executable ordinary file.

Add "/" to indicate the directory

Add "=" to indicate a socket (sockets)

Add "|" to indicate FIFOs

Add "@" to indicate a symbolic link

[root@oldbody oldboy] # touch oldboy.txt [root@oldbody oldboy] # ls-lrt r means flashback t sort by modification time total 20kuwkhok Jun-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 oldboydrwxr-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] # aliasalias 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] # ls-l directory showing colors total 20drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext-rw-r--r-- 1 root root 0 Jun 26 21:53 jeacendrwxr-xr-x 2 root root 4096 Jun 26 21:56 xingfujie-rw -RMurray root root-1 root root 0 Jun 26 21:53 yingsui.gz [root@oldbody oldboy] #\ ls-l block aliases total 20drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext-rw-r--r-- 1 root root 0 Jun 26 21:53 jeacendrwxr-xr-x 2 root root 26 21:56 xiaofandrwxr-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 show colors total 20drwxr-xr-x 3 root root 4096 Jun 26 21:56 ext-rw-r--r-- 1 root root 0 Jun 26 21:53 jeacendrwxr-xr-x 2 root root 4096 Jun 26 21:56 xiaofandrwxr-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 with key [root @ oldbody oldboy] # [root@oldbody oldboy] # grep-- color=auto 3306 / etc/services to color port 3306 mysql 3306/tcp # MySQLmysql 3306 / Udp # MySQL [root@oldbody oldboy] # ls-a can show hidden files and unhidden files all [root@oldbody test] # ls-a shows all files. .. Dir1 dir2 dir3 file1.txt file2.txt file3.txtls-l can display the attributes and modification time of the file.

Ll is equivalent to an alias that comes with a system like ls-l.

[root@oldbody test] # ls-ltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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] # lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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] # aliasalias 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] #-h human (human) is used to view files intuitively Size [root@oldbody test] # ls-lhtotal 12Kdrwxr-xr-x 2 root root 4.0K Jun 28 11:48 dir1drwxr-xr-x 2 root root 4.0K Jun 28 11:48 dir2drwxr-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] #-d directory parameter indicates that only the directory [root@oldbody test] # ls-l | grep dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1 [root@oldbody test] # ll-d dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1 [root@oldbody test] #-F classify is added / [root@oldbody test] # ls-Fdir1/ dir2/ dir3/ file1 after the directory. Txt file2.txt file3.txt [root@oldbody test] # production case: find the most recently updated file ll-rt equals ls-lrt

-r reverse reverse sort or reverse sort

-t sort by modification time by default by file name

By default, newly created files and directories are placed first.

[root@oldbody test] # lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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-rttotal 12 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.txtdrwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1 [root@oldbody test] #-I Parameter View inode node [root@oldbody test] # ll-itotal 12915788 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1915789 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2915790 drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3915785-rw-r--r-- 1 root root 0 Jun 28 11:47 file1.txt915786-rw-r--r-- 1 root root 0 Jun 28 11:47 file2 .txt915787-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 using total 12RWMY-1 root root 21 2018-09-29 11:39 1.txtMuhashi-1 root root 0 2018-09-29 11:21 123.txt RWFI 1 root root 0 2018-09-29 10:57 2.txtdrwxr-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.txtdrwxr-xr-x 5 root root 4096 2018-09-29 10:42 liangli20182.7 cp (5 *)

You can only copy files without parameters.

-an is equivalent to-dpr

-d if the source file is a linked file (link file), copy the properties of the linked file instead of the file itself

-p is copied along with the properties of the file instead of using the default properties

-r Recursion is used to copy directories

If there is a test.txt file in the tmp directory and a test.txt file in the mnt directory, copying the test.txt file in the tmp directory to the mnt directory will prompt you by default

The reason why the command\ cp / mnt/test.txt / tmp/ does not prompt aliases is to block aliases.

Or the path of the / bin/cp / mnt/test.txt / tmp/ completion cp command is not prompted.

Because cp mv rm is a dangerous operation command, which may cause damage to the file, we can check the existing alias alias of the system. You can enter the command unalias cp to delete the alias of cp directly, or you can achieve its effect (not recommended).

[root@oldbody test] # lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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] # lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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-an equals-pdr action Copying a file or directory in the past can ensure that the properties of the copy file or directory remain unchanged. Keep the source file or source directory soft connection unchanged [root@oldbody test] # cp file3.txt file5.txt [root@oldbody test] # lltotal 12drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-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] # alias cp -I will prompt alias cp='cp-I'[root@oldbody test] # [root@oldbody test] # cp-a file3.txt file5.txtcp: overwrite `file5.txt'? before overwriting [root@oldbody test] #\ cp-a file3.txt file5.txt mask alias [root@oldbody test] # [root@oldbody test] # cp-a dir3 dir4 can copy directories [root@oldbody test] # lltotal 16drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir4-rw-r-- R root root-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} is equivalent to AB AC [root@oldbody test] # cp-a dir {3 AB AC 5} [root@oldbody test] # lltotal 20drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3drwxr-xr-x 3 root root 4096 Jun 28 12:30 dir4drwxr-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} is equivalent to cp / etc/ssh/sshd_config cp / etc/ssh/sshd_config.ori [root@oldbody test] # cp / etc/sysconfig/network-scripts/ifcfg-eth0 {, .ori} backup Nic information 2.8mv (5*)

Moving files and renaming move moving files or directories is an example of cutting: mv / Tech / liangli moving Tech to the liangli directory also has the function of renaming

Mv moves files and renames move (rename) files

[root@oldbody test] # mv file {4dir3drwxr-xr-x 6} .txt renamed function [root@oldbody test] # lltotal 20drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir1drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir2drwxr-xr-x 2 root root 4096 Jun 28 11:48 dir3drwxr-xr-x 3 root root 4096 Jun 28 12:30 dir4drwxr-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.txtNo such file or directory does not have that file or directory [root@oldbody test] # aliasalias 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 alias-I parameter needs to prompt alias rm='rm-i'alias which='alias before overwriting | / usr/bin/which-- tty-only-- read-alias-- show-dot-- show-tilde' [root@oldbody test] # how to move multiple files (the / dir1 directory must exist) [root@oldbody test] # mv file1.txt file2.txt file3.txt file5.txt file6.txt dir1/t file6.txt dir1/ [root@oldbody test] # lsdir1 dir2 dir3 dir4 dir5 [root@oldbody test] # cd dir1/ [root@oldbody dir1] # lsfile1.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`-- dir56 directories 5 files [root@oldbody test] # [root@oldbody test] # file dir1 use file dir1 to check whether the dir1 is a file or a directory dir1: directory [root@oldbody test] # mv dir1 dir2 dir3 dir4 dir5 Mobile Directory moves the previous NMu1 directory to the last directory (you must make sure that the dir5 directory exists) [root@oldbody test] # tree.`-- dir5 |-- dir1 | |-- file1.txt | | |-- file2.txt | |-- file3.txt | |-- file5.txt | `--file6.txt |-- dir2 |-- dir3`-- dir4 `--dir36 directories | 5 files [root@oldbody test] # 2.9 rm (5*)

Remove (remove) delete directories and files-f (force) force,-r (recursive, used to delete directories) emphasize that delete commands should be used carefully, very dangerous, be sure to back up a copy before deletion because it cannot be restored after deletion

Correct posture for deleting files

1. Use the mv command to move to / tmp (Recycle Bin) instead of deleting the action

2. Reach the destination directory through the cd command

Then pass 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, but those sent 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 is abbreviated to create hard links and soft links.

Hard link ln source file target file (normal file when hard link is generated-character)

Soft link ln-s source file target file (target file cannot exist in advance) (generated symbolic link l type)

Hard links:

Is linked through inode in the linux file system, multiple file names point to the same inode is normal and allow hard link file is equivalent to another entry of the file, one of the functions of hard link is to allow a file to have multiple valid pathnames (multiple entries), so that users can establish hard links to important files to prevent accidental deletion of source data Note: directories cannot be used as hard links

[root@oldbody ~] # cat / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [root@oldbody ~] # ln / etc/hosts hard_link create a hard link [root@oldbody ~] # ll-ih / etc/hosts hard_link 654109-rw-r--r--. 3 root root 158 January 12 2010 / etc/hosts654109-rw-r--r--. 3 root root 158 January 12 2010 hard_ Link [root @ oldbody ~] # rm-f / etc/hosts delete [root@oldbody ~] # cat / etc/hostscat: / etc/hosts: there is no such 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/hosts127.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 January 12 2010 / etc/hosts654109-rw-r--r--. 3 root root 158 January 12 2010 hard_ Link [root @ oldbody] # hard link knowledge summary:

1. Multiple files with the same inode node number are hard-linked files to each other

2. Delete the hard link file or any one of the source files, and the file entity has not been deleted.

3. Only when the source file and all the corresponding hard link files are deleted, the file entity will be deleted.

4. When all hard link files and source files are deleted, storing new data will take up the space of the file, or when the disk fsck is checked, the deleted data will also be reclaimed by the system (form the good habit of deletion and multiple sets of environmental tests)

5. The hard link file is another entrance to the file (equivalent to the front door of the supermarket, the same as the back door)

6. You can set up hard-link files to prevent important files from being mistakenly deleted

7. Create a hard link by executing the command ln source file hard link file

8. Hard-linked files are ordinary files, so you can delete them with the rm command

9. For static files (no files being called by the process), the viewing method of i_link is deleted when the corresponding hard-linked file is 0 (i_link) (the third column of ls-l result is)

Soft links or symbolic links are equivalent to shortcuts to win Note: directories can create soft connections

Ln-s source file target file

Summary of soft link knowledge:

1. Soft links are shortcuts similar to win (you can view their directions through readlink)

2. The soft link is similar to a text file, in which the path of the source file is stored and points to the source file entity.

3. Delete the source file, the soft link file still exists, but the contents of the path to the source file cannot be accessed.

4. when it fails, it is usually a white letter flashing on a red background.

5. Execute the command ln-s source file soft link file to complete the creation of the soft link file (the destination cannot exist)

6. Soft links and source files are different types of files, but also different files, and the inode number is also different

7. The soft link file type is (l), and you can use the 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 January 12 2010 / etc/hosts654109-rw-r--r--. 3 root root 158 January 12 2010 hard_link915785 lrwxrwxrwx 1 root root 10 September 29 13:34 soft_link-> / etc/hosts global conclusion:

Deleting the source file has no effect on the hard link, but it will cause the soft link file to fail and flicker in white and red background.

Delete source files and hard link files the whole file will actually be deleted

The snapshot function in many hardware devices makes use of the principle of hard link.

[root@oldbody liangli2018] # ll-ihd oldboy oldboy/. Oldboy/test/..915805 drwxr-xr-x 3 root root 4.0K September 29 13:44 oldboy915805 drwxr-xr-x 3 root root 4.0K September 29 13:44 oldboy/.915805 drwxr-xr-x 3 root root 4.0K September 29 13:44 oldboy/test/.. Summary of the links to the directory:

1. Hard links can not be created for directories, but soft links can be created (because directories can cross file systems)

2. the soft link to the directory is a common skill in the operation and maintenance of production scene.

3. Hard links to directories cannot span the file system (from the principle of hard links, it can be understood that hard links need to have the same inode value)

4. There is a hard link under each directory. Number and the hard link to the corresponding parent directory ".."

5. Create a subdirectory in the parent directory and increase the number of links in the parent directory by 1 (each subdirectory has.. To point to the parent directory) but if you create a file in the parent directory, the number of links to the parent directory will not increase

2.12 readlink (2cm *)

View the contents of a symbolic link file

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

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