file
当我们需要知道一个文件的类型时,我们可以使用file这个命令,去查看我们的源文件是什么类型。
Example:
xiandonghua@No:~/boring$ file like.html #这是一个html文档 like.html: HTML document, UTF-8 Unicode text xiandonghua@No:~/boring$ file student #这是一个二进制文件 student: ELF 64-bit LSB executable, x86-64, version 1 (SYSV)... xiandonghua@No:~/boring$ file *.cpp #也可以直接获取多个文件类型 problem.cpp: C source, UTF-8 Unicode text student.cpp: C++ source, UTF-8 Unicode text test_auto.cpp: C source, ASCII text vector.cpp: C source, ASCII text
文件查找命令
执行文档查找命令
就是你经常用到的命令可以执行的命令,且在path中设置的命令。但它不可用于shell内建命令查找。
#man which NAME which - locate a command DESCRIPTION which returns the pathnames of the files (or links) which would be exe‐ cuted in the current environment, had its arguments been given as com‐ mands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow symbolic links.
Example:
xiandonghua@No:~/boring$ echo $PATH #打印系统path中的地址 /home/xiandonghua/bin:/home/xiandonghua/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin xiandonghua@No:~/boring$ which cd #cd属于shell内建命令故而查无结果 xiandonghua@No:~/boring$ which file /usr/bin/file #PATH中有/usr/bin/这个目录地址,所以他会去在path中的地址去搜索要找的命令
whereis
可以查找特定的文件,返回一个文件地址
NAME whereis - locate the binary, source, and manual page files for a com‐ mand
whereis
有几个很好用的参数,比如同一个文件名有不同的类型,且在不同的目录下,那么你如果需要查找特定类型的文件时,便加上特定的参数,以便查找。
简单的几个参数:
-m : Search for manuals.
-b: Search for binaries.
-s: Search for sources.
具体参数可以通过man命令获取。
locate
一个常用的命令,用于通过一个本地数据库的内容去查找,例如如果你新下载了一个文件,那么需要更新这个数据库,才可以查找到这个文件的位置。所以速度很快,它返回的是所有关于你键入的关键字所在的各个目录。
更新数据库指令:updatedb
在执行这个命令后,系统会读取/etc/updatedb.conf
文件的一些设定,你可以通过cat去查看。然后系统会根据上面的那个文件的设定规则去全盘查找,然后更新updatedb
这个数据库。
Example:
#我查找了我当前的目录,locate会根据我输入的关键字去查找,然后罗列出所有与它有关的目录地址 xiandonghua@No:~/boring$ locate boring /home/xiandonghua/boring /home/xiandonghua/boring/.vector.cpp.swp /home/xiandonghua/boring/CSS_help.md /home/xiandonghua/boring/Linux_notebook.md /home/xiandonghua/boring/WebSpider /home/xiandonghua/boring/auto /home/xiandonghua/boring/calr.sh /home/xiandonghua/boring/cs.css /home/xiandonghua/boring/github_fangwen.md /home/xiandonghua/boring/helloworld.c .........
find 这个命令很强大,但和唯一不足就是太废时间,有时候超找一个文件,需要好久,足够你写完一个几百行代码了。
可以进行筛选,比如是时间参数。你可以通过加入时间参数进行查找:
Example:
我通过时间参数进行筛选,选出最近两天内访问过的文件。
还有很多参数,一般我是通过man来获取信息。
xiandonghua@No:~/boring$ ll -h --time=atime total 188K drwxrwxr-x 4 xiandonghua xiandonghua 4.0K 5月 25 21:47 ./ drwxr-xr-x 35 xiandonghua xiandonghua 4.0K 5月 25 21:39 ../ -rwxrwxr-x 1 xiandonghua xiandonghua 9.1K 5月 7 23:54 auto* -rwxrwxr-x 1 xiandonghua xiandonghua 86 5月 13 17:35 calr.sh* -rw-rw-r-- 1 xiandonghua xiandonghua 384 5月 1 22:23 cs.css -rw-rw-r-- 1 xiandonghua xiandonghua 2.4K 5月 23 23:15 CSS_help.md -rw-rw-r-- 1 xiandonghua xiandonghua 78 5月 23 23:14 github_fangwen.md -rw-rw-r-- 1 xiandonghua xiandonghua 71 5月 1 17:06 helloworld.c -rw-rw-r-- 1 xiandonghua xiandonghua 1.1K 5月 25 21:47 like.html -rw-rw-r-- 1 xiandonghua xiandonghua 694 5月 23 23:13 Linux_notebook.md -rw-rw-r-- 1 xiandonghua xiandonghua 1.2K 5月 2 18:08 login.html -rw------- 1 xiandonghua xiandonghua 0 5月 1 17:08 nohup.out -rw-rw-r-- 1 xiandonghua xiandonghua 2.1K 5月 14 00:02 outputing.file -rwxrwxr-x 1 xiandonghua xiandonghua 23K 5月 7 23:02 problem* -rw-rw-r-- 1 xiandonghua xiandonghua 652 5月 25 21:51 problem.cpp drwxrwxr-x 2 xiandonghua xiandonghua 4.0K 5月 25 22:28 script/ -rwxrwxr-x 1 xiandonghua xiandonghua 30K 5月 25 21:50 student* -rw-rw-r-- 1 xiandonghua xiandonghua 9.9K 5月 25 21:47 student.cpp -rw-rw-r-- 1 xiandonghua xiandonghua 122 5月 25 21:51 test_auto.cpp -rwxrwxrwx 1 xiandonghua xiandonghua 300 4月 23 23:29 test.sh* -rw-rw-r-- 1 xiandonghua xiandonghua 1.7K 5月 14 00:02 timing.file -rwxrwxr-x 1 xiandonghua xiandonghua 23K 5月 7 22:53 vector* -rw-rw-r-- 1 xiandonghua xiandonghua 191 5月 25 21:51 vector.cpp -rw-r--r-- 1 xiandonghua xiandonghua 12K 5月 7 22:52 .vector.cpp.swp drwxrwxr-x 2 xiandonghua xiandonghua 4.0K 5月 25 22:28 WebSpider/ xiandonghua@No:~/boring$ find ./ -atime -2 ./ ./student ./CSS_help.md ./WebSpider ./WebSpider/web crawler.md ./test_auto.cpp ./problem.cpp ./like.html ./vector.cpp ./script ./student.cpp ./github_fangwen.md ./Linux_notebook.md
在这里说一下atime、ctime、mtime
atime: 就是你最新一次获取文档内容的时间
ctime: 是你改变这个文件属性、权限的时间
mtime: 是你改变这个文件内容的时间
一步一步慢慢学,不怕学的比别人慢,就怕什么也没学。
----致自己