Linux_ basic knowledge notes 3

1. -rm delete files or directories

删除指定文件或者目录
rm[选项]要删除的文件或目录
-f Delete files or directories without reminding them, but directly force deletion
-i Remind the user to confirm when deleting a file or directory, Y means delete, n means not delete
-r This option must be used when deleting a directory, which means that the entire directory tree is deleted recursively (use with caution)

Note: Do not directly delete the existing directories or configuration files in the system to avoid accidents

When deleting files in a directory, it is recommended to switch to the directory first and then execute the rm -rf command.
cd /etc/yum.repos.d/
rm -rf ./*

2. -mv to move files or directories

将指定的文件或者目录转移位置
如果目标位置与源位置相同,则相当于执行重命名操作
mv [选项]...源文件或目录...目标文件或目录

The mv command can only rename a single file, you can use the rename command to modify the file name
rename the target file
with the old character and the new character. Example: rename bo * .txt

3. -which finds the directory where the command file is stored

搜索范围由环境变量PATH决定(echo$PATH)
让系统能识别命令所在文件位置的环境变量PATH
root@localhost opt]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost opt]# 

Insert picture description here
Using which, when looking for internal commands, it will not be found

[root@localhost opt]# which history
/usr/bin/which: no history in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost opt]# which type
/usr/bin/which: no type in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost opt]# which help
/usr/bin/which: no help in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost opt]# 

Insert picture description here

which command/program name//default when the first target is found, do not continue to search
or
which -a command/program name//search in all search paths

[root@localhost opt]# which -a mkdir
/usr/bin/mkdir
[root@localhost opt]# 

Four. -find find files or directories

采用递归方式,根据目标的名称、类型、大小等不同属性进行精细查找
find [查找范围(文件或子目录的目录位置)] [查找条件表达式(条件类型)]

Common search types

Lookup type Keyword Description
Find by name -name Search based on the name of the target file, allowing the use of "*" and "?" wildcards
Find by file size -size Search according to the size of the target file, generally use the "+" and "-" signs to set the size greater than or less than the specified size as the search condition. Commonly used capacity units include kB (note that k is lowercase), MB, GB
Find by file owner -user Search based on whether the file belongs to the target user
Search by file type -type Search according to file type. File types include ordinary files (f), directories (d), block device files (b), character device files (c) and other block device files (b): devices that read data in blocks (hardware, Memory, optical drive) character device file (c): a device that reads data according to a single character (keyboard, mouse)
 各表达式之间使用逻辑运算符
“-a”表示而且(and)
“-o”表示或者(or)
例:find /boot -size +1024k -a -name "vm*"
       find /boot -size +1024k -o -name "vm*"
[root@localhost boot]# find /boot -size +1024k -a -name "vm*"
/boot/vmlinuz-3.10.0-693.el7.x86_64
/boot/vmlinuz-0-rescue-9cc3af631b4f41e79c67bb0952572003
[root@localhost boot]# find /boot -size +1024k -o -name "vm*"
/boot/grub2/fonts/unicode.pf2
/boot/System.map-3.10.0-693.el7.x86_64
/boot/vmlinuz-3.10.0-693.el7.x86_64
/boot/initrd-plymouth.img
/boot/initramfs-0-rescue-9cc3af631b4f41e79c67bb0952572003.img
/boot/vmlinuz-0-rescue-9cc3af631b4f41e79c67bb0952572003
/boot/initramfs-3.10.0-693.el7.x86_64.img
[root@localhost boot]# 

The exec usage of find-The exec
parameter is followed by the Linux command, which is a semicolon; as the end standard, since the semicolon has different meanings in various systems, the backslash escape character
{ } Represents the file name found by the previous find. The
find command matches all the ordinary files in the current directory, and uses the ls -l command in the -exec option to list them
find ./ -type f -exec ls -l {};

[root@localhost boot]# find /boot -name "vm*" -a -type f -exec ls -l {} \;
-rwxr-xr-x. 1 root root 5877760 8月  23 2017 /boot/vmlinuz-3.10.0-693.el7.x86_64
-rwxr-xr-x. 1 root root 5877760 1月  24 05:04 /boot/vmlinuz-0-rescue-9cc3af631b4f41e79c67bb0952572003
[root@localhost boot]# 
Five. Order execution priority

First priority: the command to specify the path. /Root/pwd.sh absolute path or a relative path ./pwd.sh
second priority: Specifies the alias command alias pwd = / root / pwd.sh
third priority: internal command
fourth priority: hash command
- There will be a hash table in the Linux system. This hash table is empty when you first boot up. Whenever you execute a command, the hash table will record the path of the command, which is equivalent to a cache. By default, the shell interpreter will look for the path of the command from the PATH when the command is executed for the first time. When you use the command for the second time, the shell interpreter will first look at the hash table. The hash table can improve the call rate of commands.
Fifth priority: Search through the search order defined by PATH.
If none of the above order is found, it will report the error "Command not found..."

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/113576906