python|UNIX文件系统命令

I wrote this manual with the goal of making it easy to learn, remember and reference the main UNIX filesystem utilities. macOS and GNU/Linux are both UNIX systems, in practical terms. macOS is a certified UNIX, based on BSD UNIX, while GNU/Linux is UNIX-like, or a UNIX derivative.
我写此手册的目的是使它易于学习,记住和参考主要的UNIX文件系统实用程序。 实际上,macOS和GNU / Linux都是UNIX系统。 macOS是基于BSD UNIX的认证UNIX,而GNU / Linux是类UNIX或UNIX派生产品。
After an introduction to the filesystem and how it works, I will cover the details of the following commands:
在介绍了文件系统及其工作原理之后,我将介绍以下命令的详细信息:
Working with folders and files
使用文件夹和文件

  • mkdir
    mkdir
  • cd
    cd
  • pwd
    pwd
  • rmdir
    rmdir
  • ls
    ls
  • touch
    touch
  • mv
    mv
  • cp
    cp
  • ln
    ln
Permissions
权限
  • chmod
    chmod
  • chown
    chown
  • chgrp
    chgrp
Files content
文件内容
  • cat
    cat
  • less
    less
  • find
    find
  • cpio
    cpio
  • dd
    dd
  • wc
    wc
文件系统如何工作 (How the Filesystem works) Every modern computer system relies on a filesystem to store and retrieve programs. Not everything can be kept in memory, which is a precious and limited resource, and we need a safe place where to store data when the computer restarts or is shut off. Memory is completely wiped off any time the computer restarts, while the disk structure is persistent.
每个现代计算机系统都依赖于文件系统来存储和检索程序。 并非所有内容都可以保留在内存中,这是一种宝贵且有限的资源,因此我们需要一个安全的地方来在计算机重新启动或关闭时存储数据。 只要磁盘结构是永久性的,只要计算机重新启动,内存就会被完全擦除。
In this guide I examine in particular the UNIX filesystem, which can be found on macOS and GNU/Linux machines. The Windows filesystem is different, although Windows 10 with the Windows Subsystem for Linux installed allows you to use the same utilities that I describe here.
在本指南中,我将特别研究UNIX文件系统,该文件系统可在macOS和GNU / Linux计算机上找到。 Windows文件系统有所不同,尽管安装了Windows子系统(适用于Linux的Windows子系统)的 Windows 10允许您使用在此介绍的相同实用程序。
A filesystem starts from /. This is the root node which hosts the first level directories.
文件系统从/开始。 这是承载第一级目录的根节点。
Usual directories that you will find in a UNIX system are
在UNIX系统中可以找到的常用目录是
  • /bin contains the main system commands
    /bin包含主要系统命令
  • /etc contains the system configuration
    /etc包含系统配置
  • /dev contains the system devices
    /dev包含系统设备
  • /usr contains the user files
    /usr包含用户文件
  • /tmp contains the temporary files
    /tmp包含临时文件
…there are more, but you get the idea.
…还有更多,但您明白了。
How many depends on the type of system used. Linux has standardised the folders using its Linux Standard Base effort, and you usually have:
多少取决于所使用的系统类型。 Linux使用Linux Standard Base努力对文件夹进行了标准化,并且您通常具有:
  • /bin the main system commands
    /bin主系统命令
  • /boot the files used to boot the machine (not existing on macOS)
    /boot用于引导计算机的文件(在macOS上不存在)
  • /dev system devices
    /dev系统设备
  • /etc system configuration files
    /etc系统配置文件
  • /etc/opt user programs configuration files
    /etc/opt用户程序配置文件
  • /home the home directories of users (/Users in macOS)
    /home用户的主目录(/ macOS中的用户)
  • /lib the system libraries (not existing on macOS)
    /lib系统库(在macOS上不存在)
  • /mnt mounted filesystems
    /mnt挂载的文件系统
  • /opt user programs
    /opt用户程序
  • /proc user by kernel and processes (not existing on macOS)
    /proc用户(按内核和进程)(在macOS上不存在)
  • /root the home folder of the root user (not existing on macOS)
    /root根用户的主文件夹(在macOS上不存在)
  • /run (not existing on macOS)
    /run (在macOS上不存在)
  • /sbin system binaries user for booting the system
    /sbin系统二进制文件用户,用于引导系统
  • /tmp temporary files
    /tmp临时文件
  • /usr holds user software, libraries and tools
    /usr拥有用户软件,库和工具
  • /usr/bin user binaries
    /usr/bin用户二进制文件
  • /usr/include user header files
    /usr/include用户头文件
  • /usr/lib user libraries
    /usr/lib用户库
  • /usr/local used by user software to store installations, like Homebrew on macOS
    用户软件使用/usr/local来存储安装,例如macOS上的Homebrew
  • /usr/sbin system binaries
    /usr/sbin系统二进制文件
  • /usr/share contains architecture-independent data. It can hold a lot of miscellaneous stuff including documentation and man pages
    /usr/share包含与体系结构无关的数据。 它可以容纳许多其他内容,包括文档和手册页
  • /usr/src contains the source code of installed packages (not existing in macOS)
    /usr/src包含已安装软件包的源代码(macOS中不存在)
  • /var contains temporary files, logs and more
    /var包含临时文件,日志等
macOS has various different folders, including
macOS具有各种不同的文件夹,包括
  • /Applications stores the users applications
    /Applications存储用户应用程序
  • /Library holds the library (settings and resources) used globally by users of the system
    /Library保存系统用户全局使用的库(设置和资源)
  • /System holds system files
    /System存放系统文件
  • /private holds system files, logs and more
    /private保存系统文件,日志等
Each folder contains files and directories, which in turn can contain other files and directories, and so on.
每个文件夹包含文件和目录,而文件和目录又可以包含其他文件和目录,依此类推。
All files and folders have a name.
所有文件和文件夹都有一个名称。
What makes a valid name? It can be long from 1 to 255 characters, and it must be composed from any alphanumeric character (a-z/A-Z/0-9), the underscore character (_), dot (.) and comma (,) characters.
什么叫有效名称? 它的长度可以从1到255个字符,并且必须由任何字母数字字符( az / AZ / 0-9 ),下划线字符( _ ),点( . )和逗号( , )字符组成。
You can also use space, although generally not recommended as space needs to be escaped with a backslash every time you must reference the file/folder.
您也可以使用空格,尽管通常不建议这样做,因为每次必须引用文件/文件夹时,都需要使用反斜杠来转义空格。
Depending on the system, the filesystem can be case sensitive. On macOS the filesystem is not case sensitive by default, so you can’t have a file/folder named test and another called Test. They are the same thing.
根据系统的不同,文件系统可能区分大小写。 在macOS上,文件系统默认情况下不区分大小写,因此您不能拥有名为test的文件/文件夹和另一个名为Test的文件/文件夹。 他们是一样的东西。
I am now going to introduce the various utility commands. Those are executed in the context of a shell, like Bash, Fish or Zsh. When you start a shell, you are going to be in your home directory. In macOS, that is found in the /Users// path.
我现在将介绍各种实用程序命令。 这些是在shell上下文中执行的,例如Bash,Fish或Zsh。 启动外壳程序时,您将位于主目录中。 在macOS中,可以在/Users//路径中找到。
The commands don’t change if you change the shell you use, because those are the basic, fundamentals commands of UNIX. You will likely use those commands for many decades unless some revolution in the computing world happens (and they happen, but those server-side things usually move slow). To give you some perspective, the mkdir command you will now see was introduced in UNIX AT&T Version 1, in the early 80s.
如果更改了所使用的Shell,则这些命令不会更改,因为它们是UNIX的基本基础命令。 除非计算世界发生某些革命(并且确实发生了,但是那些服务器端的事物通常运行缓慢),否则您可能会使用这些命令数十年。 为了给您一些视角,您现在将看到的mkdir命令是在80年代初的UNIX AT&T版本1中引入的。
使用文件夹和文件 (Working with folders and files) mkdir (mkdir)
You create folders using the mkdir command:
您可以使用mkdir命令创建文件夹:
mkdir fruits

You can create multiple folders with one command:
您可以使用一个命令创建多个文件夹:
mkdir dogs cars

You can also create multiple nested folders by adding the -p option:
您还可以通过添加-p选项来创建多个嵌套文件夹:
mkdir -p fruits/apples

Options in UNIX commands commonly take this form. You add them right after the command name, and they change how the command behaves. You can often combine multiple options, too.
UNIX命令中的选项通常采用这种形式。 您在命令名称后立即添加它们,它们会更改命令的行为。 您通常也可以组合多个选项。
You can find which options a command supports by typing man . Try now with man mkdir for example (press the q key to esc the man page). Man pages are the amazing built-in help for UNIX.
您可以通过输入man 来找到命令支持的选项。 例如,现在尝试使用man mkdir (按q键可退出手册页)。 手册页是UNIX的出色内置帮助。
cd (cd)
Once you create a folder, you can move into it using the cd command. cd means change directory. You invoke it specifying a folder to move into. You can specify a folder name, or an entire path.
创建文件夹后,可以使用cd命令将其移入该文件夹。 cd装置?焊割d irectory。 您调用它指定要移动到的文件夹。 您可以指定文件夹名称或整个路径。
Example:
例:
mkdir fruits cd fruits

Now you are into the fruits folder.
现在您进入了fruits文件夹。
You can use the .. special path to indicate the parent folder:
您可以使用..特殊路径来指示父文件夹:
cd .. #back to the home folder

The # character indicates the start of the comment, which lasts for the entire line after it’s found.
#字符表示注释的开始,在找到之后将持续整行。
You can use it to form a path:
您可以使用它来形成路径:
mkdir fruits mkdir cars cd fruits cd ../cars

There is another special path indicator which is ., and indicates the current folder.
还有另一个特殊的路径指示器是. ,并指示当前文件夹。
You can also use absolute paths, which start from the root folder /:
您还可以使用从根文件夹/开始的绝对路径:
cd /etc

pwd (pwd)
Whenever you feel lost in the filesystem, call the pwd command to know where you are:
每当您在文件系统中迷路时,请调用pwd命令以了解您的位置:
pwd

It will print the current folder path.
它将打印当前文件夹路径。
rmdir (rmdir)
Just as you can create a folder using mkdir, you can delete a folder using rmdir:
就像可以使用mkdir创建文件夹一样,也可以使用rmdir删除文件夹:
mkdir fruits rmdir fruits

You can also delete multiple folders at once:
您也可以一次删除多个文件夹:
mkdir fruits cars rmdir fruits cars

The folder you delete must be empty.
您删除的文件夹必须为空。
To delete folders with files in them, we’ll use the more generic rm command which deletes files and folders, using the -rf options:
要删除其中包含文件的文件夹,我们将使用更通用的rm命令,该命令使用-rf选项删除文件和文件夹:
rm -rf fruits cars

Be careful as this command does not ask for confirmation and it will immediately remove anything you ask it to remove.
请小心,因为此命令不会要求您确认,它会立即删除您要求删除的所有内容。
There is no bin when removing files from the command line, and recovering lost files can be hard.
从命令行删除文件时没有bin ,恢复丢失的文件可能很困难。
ls (ls)
Inside a folder you can list all the files that the folder contains using the ls command:
在文件夹内,您可以使用ls命令列出该文件夹包含的所有文件:
ls

If you add a folder name or path, it will print that folder contents:
如果添加文件夹名称或路径,它将打印该文件夹内容:
ls /bin


python|UNIX文件系统命令
文章图片
ls accepts a lot of options. One of my favorite options combinations is -al. Try it:
ls接受很多选择。 我最喜欢的选项组合之一是-al 。 试试吧:
ls -al /bin


python|UNIX文件系统命令
文章图片
compared to the plain ls, this returns much more information.
与普通的ls相比,它返回??的信息更多。
You have, from left to right:
您具有从左到右的位置:
  • the file permissions (and if your system supports ACLs, you get an ACL flag as well)
    文件权限(如果系统支持ACL,则也会获得ACL标志)
  • the number of links to that file
    指向该文件的链接数
  • the owner of the file
    文件的所有者
  • the group of the file
    文件组
  • the file size in bytes
    文件大小(以字节为单位)
  • the file modified datetime
    文件修改的日期时间
  • the file name
    文件名
This set of data is generated by the l option. The a option instead also shows the hidden files.
这组数据由l选项生成。 相反, a选项还会显示隐藏的文件。
Hidden files are files that start with a dot (.).
隐藏文件是指以点( . )开头的文件。
touch (touch)
You can create an empty file using the touch command:
您可以使用touch命令创建一个空文件:
touch apple

If the file already exists, it opens the file in write mode, and the timestamp of the file is updated.
如果文件已经存在,它将以写入模式打开文件,并且文件的时间戳将更新。
mv (mv)
Once you have a file, you can move it around using the mv command. You specify the file current path, and its new path:
有了文件后,可以使用mv命令在文件中移动。 您指定文件的当前路径及其新路径:
touch test mv pear new_pear

The pear file is now moved to new_pear. This is how you rename files and folders.
pear文件现在移至new_pear 。 这是重命名文件和文件夹的方式。
If the last parameter is a folder, the file located at the first parameter path is going to be moved into that folder. In this case, you can specify a list of files and they will all be moved in the folder path identified by the last parameter:
如果最后一个参数是文件夹,则位于第一个参数路径的文件将被移动到该文件夹??中。 在这种情况下,您可以指定文件列表,所有文件都将移至最后一个参数标识的文件夹路径中:
touch pear touch apple mkdir fruits mv pear apple fruits #pear and apple moved to the fruits folder

cp (cp)
You can copy a file using the cp command:
您可以使用cp命令复制文件:
touch test cp apple another_apple

To copy folders you need to add the -r option to recursively copy the whole folder contents:
要复制文件夹,您需要添加-r选项以递归方式复制整个文件夹的内容:
mkdir fruits cp -r fruits cars

ln (ln)
Let’s now introduce the concept of links. A link is a file that points to another file. We have those in all the major operating systems.
现在让我们介绍链接的概念。 链接是指向另一个文件的文件。 我们在所有主要操作系统中都有这些。
We can create two types of links: hard links and symbolic (soft) links. We can’t create a hard link to a directory, but we can create a symbolic one. For this reason, symbolic links (also called symlinks) are much more common.
我们可以创建两种类型的链接:硬链接和符号(软)链接。 我们无法创建指向目录的硬链接,但可以创建一个符号链接。 因此,符号链接(也称为符号链接 )更为常见。
We create a symbolic link using this syntax: ln -s original linkname. Example:
我们使用以下语法创建符号链接: ln -s original linkname 。 例:
mkdir fruits ln -s fruits newfruits


python|UNIX文件系统命令
文章图片
Notice how I used the ll command. This is not a standard command, but an alias for ls -al. In a shell, you can define aliases that are shortcuts to common command and arguments combinations.
注意我如何使用ll命令。 这不是标准命令,而是ls -al别名 。 在外壳程序中,您可以定义别名,这些别名是常见命令和参数组合的快捷方式。
权限 (Permissions) I mentioned permissions briefly before, when introduced the ls -al command.
在介绍ls -al命令时,我曾简要提到过权限。
The weird string you see on each file line, like drwxr-xr-x, defines the permissions of the file or folder.
您在每个文件行上看到的怪异字符串(例如drwxr-xr-x )定义了文件或文件夹的权限。
Let’s dissect it.
让我们对其进行剖析。
The first letter indicates the type of file:
第一个字母表示文件的类型:
  • - means it’s a normal file
    -表示它是普通文件
  • d means it’s a directory
    d表示它是目录
  • l means it’s a link
    l意思是链接
Then you have 3 sets of values:
然后,您有3组值:
  • The first set represents the permissions of the owner of the file
    第一组代表文件所有者的权限
  • The second set represents the permissions of the members of the group the file is associated to
    第二组代表与文件关联的组成员的权限
  • The third set represents the permissions of the everyone else
    第三组代表其他所有人的权限
Those sets are composed by 3 values. rwx means that specific persona has read, write and execution access. Anything that is removed is swapped with a -, which lets you form various combinations of values and relative permissions: rw-, r--, r-x, and so on.
这些集合由3个值组成。 rwx表示特定角色具有读取,写入和执行访问权限。 即删除任何被换了-它可以让你形成的价值观和相关权限的各种组合: rw- r--rx ,等等。
You can change the permissions given to a file using the chmod command.
您可以使用chmod命令更改授予文件的权限。
chmod can be used in 2 ways. The first is using symbolic arguments, the second is using numeric arguments. Let’s start with symbols first, which is more intuitive.
chmod可以以两种方式使用。 第一个使用符号参数,第二个使用数字参数。 让我们先从符号开始,这更加直观。
You type chmod followed by a space, and a letter:
您键入chmod后跟一个空格和一个字母:
  • a stands for all
    a代表所有人
  • u stands for user
    u代表用户
  • g stands for group
    g代表
  • o stands for others
    o代表他人
Then you type either + or - to add a permission, or to remove it. Then you enter one or more permissions symbols (r, w, x).
然后,键入+-添加或删除权限。 然后,输入一个或多个权限符号( rwx )。
All followed by the file or folder name.
全部后跟文件或文件夹名称。
Here are some examples:
这里有些例子:
chmod a+r filename #everyone can now read chmod a+rw filename #everyone can now read and write chmod o-rwx filename #others (not the owner, not in the same group of the file) cannot read, write or execute the file

You can apply the same permissions to multiple personas by adding multiple letters before the +/-:
您可以通过在+ / -前面添加多个字母来对多个角色应用相同的权限:
chmod og-r filename #other and group can't read any more

In case you are editing a folder, you can apply the permissions to every file contained in that folder using the -r (recursive) flag.
如果正在编辑文件夹,则可以使用-r (递归)标志将权限应用于该文件夹中包含的每个文件。
Numeric arguments are faster but I find them hard to remember when you are not using them day to day. You use a digit that represents the permissions of the persona. This number value can be a maximum of 7, and it’s calculated in this way:
数字参数速度更快,但是当您每天不使用它们时,我很难记住它们。 您使用一个数字代表角色的权限。 此数字值最多可以为7,它是通过以下方式计算的:
  • 1 if has execution permission
    如果具有执行权限,则为1
  • 2 if has write permission
    2如果有写权限
  • 4 if has read permission
    4如果具有读取权限
This gives us 4 combinations:
这给了我们4种组合:
  • 0 no permissions
    0没有权限
  • 1 can execute
    1可以执行
  • 2 can write
    2可以写
  • 3 can write, execute
    3可以编写,执行
  • 4 can read
    4可以阅读
  • 5 can read, execute
    5可以读取,执行
  • 6 can read, write
    6可以读写
  • 7 can read, write and execute
    7可以读写,执行
We use them in pairs of 3, to set the permissions of all the 3 groups altogether:
我们以3对的方式使用它们,以设置所有3个组的权限:
chmod 777 filename chmod 755 filename chmod 644 filename

所有者和组 (Owner and group)
You can change the owner of a file using the chown command:
您可以使用chown命令更改文件的所有者:
chown

You can change the group of a file using the chgrp command:
您可以使用chgrp命令更改文件组:
chgrp

管理文件内容 (Managing files content) less (less)
The less command is one I use a lot. It shows you the contents stored inside a file, in a nice and interactive UI.
less命令是我经常使用的命令。 它以漂亮的交互式UI向您显示文件中存储的内容。
Usage: less .
用法: less

python|UNIX文件系统命令
文章图片
Once you are inside a less session, you can quit by pressing q.
进入less会话后,可以按q退出。
You can navigate the file contents using the up and down keys, or using the space bar and b to navigate page by page. You can also jump to the end of the file pressing G and jump back to the start pressing g.
您可以使用updown键,或使用space barb来逐页浏览文件内容。 您也可以按G跳到文件末尾,然后按g跳回到文件头。
You can search contents inside the file by pressing / and typing a word to search. This searches forward. You can search backwards using the ? symbol and typing a word.
您可以通过按/并输入一个单词来搜索文件内的内容。 这向前搜索。 您可以使用?向后搜索? 符号并输入一个单词。
This command just visualises the file’s content. You can directly open an editor by pressing v. It will use the system editor, which in most cases is vim.
该命令仅可视化文件的内容。 您可以通过按v直接打开编辑器。 它将使用系统编辑器,在大多数情况下为vim
Pressing the F key enters follow mode, or watch mode. When the file is changed by someone else, like from another program, you get to see the changes live. By default this is not happening, and you only see the file version at the time you opened it. You need to press ctrl-C to quit this mode. In this case the behaviour is similar to running the tail -f command.
F键进入跟随模式观看模式 。 当其他人(例如从另一个程序)更改文件时,您可以实时看到更改。 默认情况下,这不会发生,并且您仅在打开文件时看到文件版本。 您需要按ctrl-C退出此模式。 在这种情况下,其行为类似于运行tail -f 命令。
You can open multiple files, and navigate through them using :n (to go to the next file) and :p (to go to the previous).
您可以打开多个文件,并使用:n (转到下一个文件)和:p (转到上一个)浏览它们。
tail (tail)
I just mentioned tail in the previous command, so let’s use this opportunity to explain what it does.
我在前面的命令中刚刚提到了tail ,所以让我们利用这个机会来解释它的作用。
Its best use case in my opinion is when called with the -f option. It opens the file at the end, and watches for file changes. Any time there is new content in the file, it is printed in the window. This is great for watching log files, for example:
我认为,最好的用例是使用-f选项调用。 它将在最后打开文件,并监视文件更改。 每当文件中有新内容时,它就会打印在窗口中。 这非常适合查看日志文件,例如:
tail -f /var/log/system.log

To exit, press ctrl-C.
要退出,请按ctrl-C
You can print the last 10 lines in a file:
您可以打印文件中的最后10行:
tail -n 10

You can print the whole file content starting from a specific line using + before the line number:
您可以使用行号之前的+ ,从特定行开始打印整个文件内容:
tail -n +10

tail can do much more and as always my advice is to check man tail.
tail可以做更多的事情,而且我的建议是检查man tail
cat (cat)
Similar to tail in some way, we have cat. Except cat can also add content to a file, and this makes it super powerful.
在某种程度上类似于tail ,我们有cat 。 除了cat也可以将内容添加到文件中,这使其功能非常强大。
In its simplest usage, cat prints a file’s content to the standard output:
cat最简单的用法是将文件的内容打印到标准输出中:
cat file

You can print the content of multiple files:
您可以打印多个文件的内容:
cat file1 file2

and using the output redirection operator > you can concatenate the content of multiple files into a new file:
并使用输出重定向运算符>您可以将多个文件的内容串联到一个新文件中:
cat file1 file2 > file3

Using >> you can append the content of multiple files into a new file, creating it if it does not exist:
使用>>可以将多个文件的内容附加到一个新文件中,如果不存在则创建它:
cat file1 file2 >> file3

When watching source code files it’s great to see the line numbers, and you can have cat print them using the -n option:
当看源代码文件也很高兴地看到行号,你可以有cat使用打印出来-n选项:
cat -n file1

You can only add a number to non-blank lines using -b, or you can also remove all the multiple empty lines using -s.
您只能使用-b将数字添加到非空白行,或者也可以使用-s删除所有多个空行。
cat is often used in combination with the pipe operator | to feed a file content as input to another command: cat file1 | anothercommand.
cat通常与管道运算符结合使用| 将文件内容作为输入输入到另一个命令: cat file1 | anothercommand cat file1 | anothercommand
wc (wc)
wc means word count. Here is the most common usage:
wc表示字数统计 。 这是最常见的用法:
  • wc -l file1 count lines
    wc -l file1计数行
  • wc -w file1 count words
    wc -w file1计数字
  • wc -c file1 count characters
    wc -c file1计数字符
  • wc -m file1 count characters with multibyte support (i.e. emojis count as 1, not as multiple characters)
    wc -m file1计算具有多字节支持的字符(即,表情符号计数为1,而不是多个字符)
You can run wc providing multiple files, in which case it will do the calculations on each file separately, and then print a summary:
您可以运行wc提供多个文件,在这种情况下,它将对每个文件分别进行计算,然后打印摘要:

python|UNIX文件系统命令
文章图片
find (find)
The find command can be used to find files or folders matching a particular search pattern. It searches recursively.
find命令可用于查找与特定搜索模式匹配的文件或文件夹。 它递归搜索。
Let’s learn it by example.
让我们通过示例来学习它。
Find all the files under the current tree that have the .js extension and print the relative path of each file matching:
查找当前树下所有扩展名为.js的文件,并打印每个匹配文件的相对路径:
find . -name '*.js'

It’s important to use quotes around special characters like * to avoid the shell interpreting them.
重要的是,在特殊字符(如*周围使用引号,以避免shell解释它们。
Find directories under the current tree matching the name “src”:
在当前树下找到与名称“ src”匹配的目录:
find . -type d -name src

Use -type f to search only files, or -type l to only search symbolic links.
使用-type f仅搜索文件,或使用-type l仅搜索符号链接。
-name is case sensitive. use -iname to perform a case-insensitive search.
-name区分大小写。 使用-iname执行不区分大小写的搜索。
You can search under multiple root trees:
您可以在多个根树下搜索:
find folder1 folder2 -name filename.txt

Find directories under the current tree matching the name “node_modules” or ‘public’:
在当前树下查找与名称“ node_modules”或“ public”匹配的目录:
find . -type d -name node_modules -or -name public

You can also exclude a path, using -not -path:
您还可以使用-not -path排除路径:
find . -type d -name '*.md' -not -path 'node_modules/*'

You can search files that have more than 100 characters (bytes) in them:
您可以搜索其中包含超过100个字符(字节)的文件:
find . -type f -size +100c

Search files bigger than 100KB but smaller than 1MB:
搜索大于100KB但小于1MB的文件:
find . -type f -size +100k -size -1M

Search files edited more than 3 days ago
搜索文件已在3天前进行了修改
find . -type f -mtime +3

Search files edited in the last 24 hours
搜索最近24小时内编辑的文件
find . -type f -mtime -1

You can delete all the files matching a search by adding the -delete option. This deletes all the files edited in the last 24 hours:
您可以通过添加-delete选项来删除与搜索匹配的所有文件。 这将删除最近24小时内编辑的所有文件:
find . -type f -mtime -1 -delete

You can execute a command on each result of the search. In this example we run cat to print the file content:
您可以对每个搜索结果执行命令。 在此示例中,我们运行cat打印文件内容:
find . -type f -exec cat {} \;

notice the terminating \; . {} is filled with the file name at execution time.
注意终止符\; {}在执行时用文件名填充。
【python|UNIX文件系统命令】翻译自: https://flaviocopes.com/unix-filesystem/

    推荐阅读