当前位置:网站首页>Linx link, first level directory, redirection, CP and MV
Linx link, first level directory, redirection, CP and MV
2022-07-24 00:55:00 【.98℃】
Catalog
4. Creation and deletion of files and directories
1. Hard links and soft links
Symbolic links are also called soft links
- And the original file is not a file for example Windows Shortcut to , If the original file is deleted , all
- The symbolic links pointing to it are also destroyed .
- Soft links have their own node, yes linux A kind of special document , As a document , Its data is the path of the file to which it is connected . Symbolic links can span file systems , You can also create a directory .
- Format :ln -s Source file Target file
Hard links
- Only files in the same file system can be referenced . It refers to the physical index of the file in the file system ( Also known as inode).
- When the original file is moved or deleted , Hard links will not be broken , Because it refers to the physical data of the file, not the location of the file in the component structure .
- Create format : ln The original document Target file

create a file file1 And create soft links for it soft_file1、 And hard links hard_file1
[[email protected] home]# touch file1
[[email protected] home]# ln -s file soft_file1
[[email protected] home]# ln file hard_file1
[[email protected] home]# ls -li
total 5
27446429 drwxr-xr-x. 2 root root 6 Jul 14 10:46 data
27446447 -rw-r--r--. 2 root root 0 Jul 14 18:15 file1
27446447 -rw-r--r--. 2 root root 0 Jul 14 18:15 hard_file1
18732229 drwx------. 15 rhcsa rhcsa 4096 Jul 12 17:45 rhcsa
27446463 lrwxrwxrwx. 1 root root 5 Jul 14 18:19 soft_file1 -> file1
1875985 drwxr-xr-x. 2 root root 6 Jul 14 10:46 sub_dataDelete file1 Then check the contents of each document
[[email protected] home]# echo "123456" > file1
[[email protected] home]# echo "999999" >> hard_file1
[[email protected] home]# cat file1
123456
[[email protected] home]# cat soft_file1
123456
[[email protected] home]# cat hard_file1
123456
999999
[[email protected] home]# rm file1
rm: remove regular file 'file1'? y
[[email protected] home]# cat file1
cat: file1: No such file or directory
[[email protected] home]# cat soft_file1
cat: soft_file1: No such file or directory
[[email protected] home]# cat hard_file1
999999
2. First level directory
- /bin/ Store system commands , Ordinary users and root Can be executed . Put it in /bin The command under can also be executed in single user mode
- /boot/ System boot directory , Save files related to system startup , Such as kernel files and boot loader (grub) Documents, etc.
- /dev/ Device file storage location
- /etc/ Where to save the configuration file . The default installation mode is adopted in the system (rpm install ) The service configuration files of are all saved in this directory
- /home/ Home directory for ordinary users ( Also known as home directory )
- /lib/ The function library of the system call is saved in
- /lib64 Deposit 64 Bit file
- /media/ Mount Directory . The system is recommended to mount media devices , Such as floppy disk and CD
- /mnt/ Mount Directory . The system suggests that this directory be used to mount additional devices , Such as U disc 、 Partition of mobile hard disk and other operating systems
- /opt/ Storage location of software installed by a third party . This directory is where other software is placed and installed , Manually installed source package software can be installed into this directory
- /proc/ Virtual file system . The data in this directory is stored in memory . It mainly stores the kernel of the system 、 process 、 External device status and network status etc
- /root/ root The home directory . The home directory of ordinary users is in /home/ Next ,root The home directory is directly in “/” Next
- /sbin/ Save commands related to system environment settings , Only root You can use these commands to set the system environment , There are also commands that allow ordinary users to view
- /srv/ Service data directory . After some system services are started , You can save the required data in this directory
- /sys/ Virtual file system . and /proc/ The catalog is similar to , The data in this directory is stored in memory , It mainly stores kernel related information
- /tmp/ Temporary directory . The directory where the system stores temporary files , Under the directory , All users can access and write
- /tmp This directory is where some temporary files are stored .
- /usr Its full name is Unix Software Resource, This directory is used to store system software resources
- /var Used to store dynamic data , For example, caching 、 Log files 、 Files generated during software operation, etc
3.I/O flow 、 Redirect
| Field | describe | File descriptor |
|---|---|---|
| stdin | Standard input stream | 0 |
| stdout | Standard output stream | 1 |
| stderr | Standard error output stream | 2 |
Redirection operator
- Redirection operators can redirect command input and output data streams from the default device to other locations . The redirection operator itself is not a command , It is a special symbol attached to the command that can change the input and output objects of the command .
- Output redirection operator : >( Cover ) 、 >>( Additional )
- Enter the redirection operator : < 、 <<( end )
Redirect standard output and standard error output to the same file
[[email protected] ~]# date &> file
[[email protected] ~]# cat file
Thu Jul 14 19:54:09 CST 2022
[[email protected] ~]# data &> file
[[email protected] ~]# cat file
bash: data: command not found...
[[email protected] ~]# date >& file
[[email protected] ~]# cat file
Thu Jul 14 19:55:16 CST 2022
[[email protected] ~]# data >& file
[[email protected] ~]# cat file
bash: data: command not found...
[[email protected] ~]# date 1> file 2>file
[[email protected] ~]# cat file
Thu Jul 14 19:56:19 CST 2022
[[email protected] ~]# data 1> file 2>file
[[email protected] ~]# cat file
bash: data: command not found...
take 1 Redirect to 2
[[email protected] ~]# date 2> file 1>&2
[[email protected] ~]# cat file
Thu Jul 14 20:00:36 CST 2022
[[email protected] ~]# data 2> file 1>&2
[[email protected] ~]# cat file
bash: data: command not found...
[[email protected] ~]# date 1>& file
[[email protected] ~]# cat file
Thu Jul 14 20:02:16 CST 2022
[[email protected] ~]# data 1>& file
[[email protected] ~]# cat file
bash: data: command not found...
take 2 Redirect to 1
[[email protected] ~]# data 1>file 2>&1
[[email protected] ~]# cat file
bash: data: command not found...
[[email protected] ~]# date 1>file 2>&1
[[email protected] ~]# cat file
Thu Jul 14 20:04:19 CST 2022
Redirect files to 0
[[email protected] ~]# ecoh "hello world" >data
[[email protected] ~]# sort <data
hello world
[[email protected] ~]# cat <<EOF
> 123
> 456
> 789
> hello world!
> EOF
[[email protected] ~]# cat > data <<EOF
> 111
> 222
> 777
> EOF
[[email protected] ~]# cat data
111
222
777
4. Creation and deletion of files and directories
Catalog :
Create directory (make directory)
- The grammar is : mkdir [-p] [/ route /] Directory name
- -p You can quickly create each directory specified in the directory structure , Existing directories will not be overwritten
- -v Displays the detailed process of creating a directory
Statistics of space occupation of directory and file ——du command
- function : View the amount of disk space occupied by subdirectories at all levels in a directory .
- Command format : du [ Options ] [ Directory name ]
-a Include all files when calculating disk space usage , It's not just catalogues .
-s Only count the total space occupied by each file , Instead of counting every subdirectory 、 File size .
-h With K,M,G Displays disk usage in units , To improve the readability of information .
[[email protected] data]# mkdir -p /home/data/cont1
[[email protected] cont1]# pwd
/home/data/cont1
[[email protected] cont1]# echo "hello world!">>cont1
[[email protected] cont1]# du -h cont1
4.0K cont1
[[email protected] cont1]# mkdir -p cont2/cont3
[[email protected] data]# ls -R
.:
cont1
./cont1:
cont2
./cont1/cont2:
cont3
Delete directory files
Grammar format : rm -r [-f] Directory file name
[[email protected] data]# rm -r cont1/cont2/cont3
rm: remove directory 'cont1/cont2/cont3'? y
Only deleted cont3
[[email protected] data]# rm -r cont1
rm: descend into directory 'cont1'? y
rm: descend into directory 'cont1/cont2'? y
rm: remove directory 'cont1/cont2/cont3'? y
rm: remove directory 'cont1/cont2'? y
rm: remove directory 'cont1'? y
Deleted cont1、2、3file
Create a normal file : touch [OPTION]... FILE...
touch In two ways :
- If the file already exists , Three times when the file will be updated , stat You can view the details of the file
- If the file doesn't exist , It means to create a file
Create multiple normal files :
- Method 1: touch file name 1 file name 2 file name 3
- Method 2: touch { file name 1, file name 2, file name 3}
Delete normal files : rm [-f] file name
[[email protected] data]# touch file11 file22 file33
[[email protected] data]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jul 14 21:35 file11
-rw-r--r--. 1 root root 0 Jul 14 21:35 file22
-rw-r--r--. 1 root root 0 Jul 14 21:35 file33
[[email protected] data]# stat file33
File: file33
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 27446851 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2022-07-14 21:25:35.549327296 +0800
Modify: 2022-07-14 21:25:35.549327296 +0800
Change: 2022-07-14 21:25:35.549327296 +0800
Birth: 2022-07-14 21:25:35.549327296 +0800
[[email protected] data]# touch file33
[[email protected] data]# stat file33
File: file33
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 27446851 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2022-07-14 21:32:28.028280247 +0800
Modify: 2022-07-14 21:32:28.028280247 +0800
Change: 2022-07-14 21:32:28.028280247 +0800
Birth: 2022-07-14 21:25:35.549327296 +0800[[email protected] data]# rm file11
rm: remove regular file 'file11'? y
[[email protected] data]# rm file22
rm: remove regular empty file 'file22'? y
[[email protected] data]# rm file33
rm: remove regular empty file 'file33'? y
[[email protected] data]# ls -l
total 0
5. Copy 、 Move
1、 Copy files or directories
Format : cp [ Options ] Source file Target file
- -a Usually used when copying directories , Keep all its contents . It retains links 、 File attribute , And copy directories recursively
- -d Keep links when copying
- -f Force copying of files or directories , Whether the target directory or file exists or not
- -i You will be prompted to confirm before overwriting the target file . answer y When the target file will be overwritten , It's an interactive copy
- -p -preserve, Keep its properties , In addition to copying the contents of the source file , It will also copy its modification time and access rights to the new file
- -r/g Recursive replication , Copy all the files in the specified directory together with the sub files
Copy files to the current directory rename ../ Represents the current directory
[[email protected] data]# cp file11 ./file11-1
[[email protected] data]# ls -l
total 16
-rw-r--r--. 1 root root 13 Jul 14 21:51 file11
-rw-r--r--. 1 root root 13 Jul 14 21:56 file11-1Copy the file to the directory without changing the file properties
[[email protected] data]# cp -p file22 /home/data/cont2/Copy to the specified directory cont1
[[email protected] data]# cp file11 /home/data/cont1/
[[email protected] data]# ls -la cont1
total 4
-rw-r--r--. 1 root root 13 Jul 14 22:04 file11
Put the table of contents cont3 And the files under it are copied to cont4, If you only move the directory, remove cont3 hinder /*
[[email protected] data]# cp -r /home/data/cont3/* /home/data/cont4/
cp: overwrite '/home/data/cont4/cont3'? y
[[email protected] data]# ls -l cont4
total 4
-rw-r--r--. 1 root root 45 Jul 14 22:32 cont3
drwxr-xr-x. 2 root root 6 Jul 14 22:32 count3.3
drwxr-xr-x. 2 root root 6 Jul 14 22:22 count4.4
Copy, paste and rename under the current directory
[[email protected] data]# echo "hello world!" >>file11
[[email protected] data]# cp file11 file22
[[email protected] data]# cat file44
hello world!
Move files or directories
- Format : mv [ Options ] Source file name Target file name
- mv The command is used to cut or rename files
- The cut operation is different from the copy operation , Because it will delete the source file , Keep only the cut file . If you cut a file in the same directory and paste it into the current directory , In fact, the essence is to rename the file .
[[email protected] cont4]# mv /home/data/cont3 /home/data/cont5
[[email protected] cont4]# ls -l cont5
[[email protected] data]# ls -l cont5
total 0
drwxr-xr-x. 3 root root 35 Jul 14 22:27 cont3
边栏推荐
- PostgreSQL snapshot optimization globalvis new system analysis (greatly enhanced performance)
- Off screen rendering & FBO
- Expérience du système réseau: résoudre les problèmes de ping
- 如何使用 SAP Intelligent Robotic Process Automation 自动操作 Excel
- vim常用命令
- Intelligent OCR identification of express documents helps the logistics industry to upgrade Digitalization
- Pbootcms database conversion tutorial (SQLite to MySQL detailed tutorial)
- About redis: there is still a risk of data loss after redis sets data persistence
- How can dbcontext support the migration of different databases in efcore advanced SaaS system
- [QNX hypervisor 2.2 user manual]9.1 configuration variables
猜你喜欢

Project scenario: NVIDIA SMI unable to datemine the device handle for GPU 0000:01:00.0: unknown error

網絡系統實驗:ping不通的問題解决
![[the 83rd fortnight of leetcode]](/img/41/411dc235a34f9dde06a41323628648.png)
[the 83rd fortnight of leetcode]

黑馬程序員-接口測試-四天學習接口測試-第四天-Postman讀取外部數據文件,讀取數據文件數據,iHRM項目實戰,員工管理模塊,添加員工,批量運行測試用例,生成測試報告,

Classic example of C language - loan balance

Centernet target detection model and centerfusion fusion target detection model

Classic examples of C language - use 4 × The matrix displays all integers from 1 to 16 and calculates the sum of each row, column, and diagonal

Testers who have been employed for 3 months are facing employment confirmation. Leaders: 1 year of work experience is packaged into 5 years, and the probation period is eliminated
![[STM32] basic knowledge of serial communication](/img/0f/7cc59fea9b1edf721c9d06b419896a.png)
[STM32] basic knowledge of serial communication

工作3年的测试员跳槽后工资是原来的2倍,秘诀原来是......
随机推荐
Scroll view realizes drop-down refresh (to avoid the drop-down problem triggered by the initial refresh triggered value of true when onload enters the page)
MySQL table field quantity limit and row size limit
Tutorial on principles and applications of database system (051) -- MySQL query (XIII): using queries in DML statements
C language writing specification
Introduction to QT (2.1 the first procedure for the beginning of QT)
Tutorial on the principle and application of database system (044) -- MySQL query (VI): using the limit option to realize paging query
Dark horse programmer - interface test - four day learning interface test - day 4 - postman reads external data files, reads data files, IHRM project practice, employee management module, adds employe
暑假第四周总结
AWS Part 4 one machine and one secret
[QNX hypervisor 2.2 user manual]9 VM configuration reference
Treatment of particle boundary collision
AVX instruction set accelerated matrix multiplication
黑馬程序員-接口測試-四天學習接口測試-第四天-Postman讀取外部數據文件,讀取數據文件數據,iHRM項目實戰,員工管理模塊,添加員工,批量運行測試用例,生成測試報告,
Dataframe.groupby learning materials
MySQL's heart index
Memory forensics nssctf otterctf 2018 (replay)
Reverse linked list drawing demonstration
Bean validation usage article ----05
Design details related to sap e-commerce cloud Spartacus UI store
Tutorial on principles and applications of database system (047) -- MySQL query (IX): connection query