使用 find 与 locate 与 whereis
Using find vs. locate vs. whereis
我正在做 Linux 黑客基础知识(Starch Press)的第 1 章练习:
Create a new directory called hackerdirectory and create a new file in
that directory named hackedfile. Now copy that file to your /root
directory and then rename it secretfile.
所以我做了 mkdir hackerdirectory
然后 cd hackerdirectory
然后 touch hackedfile
然后 sudo mv hackedfile /root
我的理解是 /root
是顶级主目录,但是当我 cd ..
回到主目录 ls -l
时,它不在那里:
drwxrwxr-x 23 nobu nobu 4096 Jul 9 18:24 anaconda3
-rw-r--r-- 1 nobu nobu 4243 May 3 02:10 backblue.gif
-rw-rw-r-- 1 nobu nobu 25120 Mar 23 07:02 CERTIFICATE
drwxrwxr-x 3 nobu nobu 4096 Mar 30 05:01 client-configs
-rw-rw-r-- 1 nobu nobu 412 May 3 03:18 cookies.txt
-rw------- 1 root root 8560640 Apr 11 09:59 core
drwxr-xr-x 3 nobu nobu 4096 Sep 11 20:34 ctf
drwxr-xr-x 18 nobu nobu 4096 Sep 13 12:33 Desktop
drwxr-xr-x 4 nobu nobu 4096 Sep 8 18:59 Diamondhead
drwxrwxr-x 6 nobu nobu 4096 Sep 15 16:42 Documents
drwxr-xr-x 27 nobu nobu 12288 Sep 17 14:28 Downloads
-rw-r--r-- 1 nobu nobu 8980 Mar 20 06:44 examples.desktop
-rw-r--r-- 1 nobu nobu 828 May 3 02:10 fade.gif
drwxrwxr-x 4 nobu nobu 4096 Jun 27 02:38 fullstack
drwxrwxr-x 11 nobu nobu 4096 Jul 12 16:21 gym
drwxr-xr-x 2 nobu nobu 4096 Sep 17 15:37 hackerdirectory
drwx------ 2 nobu nobu 4096 May 3 03:18 hts-cache
-rw-rw-r-- 1 nobu nobu 2101 May 3 03:18 hts-log.txt
drwxr-xr-x 6 nobu nobu 4096 Sep 4 23:27 locust_k8s
drwxr-xr-x 10 nobu nobu 4096 Aug 28 11:44 mecab-ipadic-neologd
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Music
drwxr-xr-x 14 nobu nobu 4096 Aug 24 14:10 myapp
drwx------ 3 nobu nobu 4096 Mar 30 03:28 openvpn-ca
drwxr-xr-x 4 nobu nobu 4096 Aug 19 19:47 Pictures
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Public
drwxr-xr-x 3 nobu nobu 4096 Aug 15 12:34 repos
drwxr-xr-x 6 nobu nobu 4096 Sep 4 23:23 snap
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Templates
-rw-rw-r-- 1 nobu nobu 5477405 Jul 5 08:17 tf
-rwxrwxr-x 1 nobu nobu 4474932 Oct 24 2017 unetbootin-linux-latest
drwxr-xr-x 3 nobu nobu 4096 Apr 27 11:56 Videos
drwx------ 3 nobu nobu 4096 Jun 27 02:46 'VirtualBox VMs'
drwxrwxr-x 5 nobu nobu 4096 May 3 02:36 websites
drwxrwxr-x 2 nobu nobu 4096 Jul 9 21:15 work
现在我做到了:
nobu@nobu-ThinkPad-T420:~$ locate hackedfile
nobu@nobu-ThinkPad-T420:~$ whereis hackedfile
hackedfile:
这是什么意思?我已经尝试 sudo su
然后 ls
但仍然看不到它。
编辑:所以我根据下面的命令找到了它,但无法摆脱它。
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
/root/hackedfile
nobu@nobu-ThinkPad-T420:~$ sudo rm /root/hackedfile
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
nobu@nobu-ThinkPad-T420:~$ whereis hackedfile
hackedfile:
编辑(未列出)
nobu@nobu-ThinkPad-T420:~$ sudo ls -al /root
total 64
drwx------ 12 root root 4096 Sep 17 16:23 .
drwxr-xr-x 28 root root 4096 Sep 9 12:45 ..
drwx------ 2 root root 4096 Jul 10 07:31 .aptitude
-rw------- 1 root root 1124 Sep 17 16:30 .bash_history
-rw-r--r-- 1 root root 3106 Oct 23 2015 .bashrc
drwx------ 4 root root 4096 Apr 11 05:47 .cache
drwx------ 7 root root 4096 Apr 11 15:54 .config
drwx------ 3 root root 4096 Mar 22 02:47 .dbus
drwx------ 3 root root 4096 Apr 11 12:23 .gnupg
drwxr-xr-x 4 root root 4096 Aug 17 09:20 .java
drwxr-xr-x 3 root root 4096 Apr 1 08:12 .local
drwxr-xr-x 2 root root 4096 Mar 30 02:55 .nano
drwxr-xr-x 2 root root 4096 Aug 21 11:13 .oracle_jre_usage
-rw-r--r-- 1 root root 148 Aug 18 2015 .profile
drwx------ 2 root root 4096 Sep 4 22:58 .ssh
-rw-r--r-- 1 root root 220 Aug 8 14:02 .wget-hsts
编辑(当 sudo su
时)
root@nobu-ThinkPad-T420:/home/nobu# whereis hackedfile
hackedfile:
所以当我执行命令 whereis
时,它会显示文件。所以真的删了吗?
但现在当我尝试时:sudo find /root -type f -name hackedfile
我得到:
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
nobu@nobu-ThinkPad-T420:~$
因此它似乎已经消失了,除了执行 `whereis' 仍然用冒号显示它。
编辑:
请注意 whereis
returns 无论您要查找什么都说 filename:
然后在冒号后列出位置的 PATH。
下面是如何使用find
:
find
这是我上面列出的教科书。
尝试pwd
查看您在文件系统中的位置。您可能会使用 sudo ls -al /root
找到该文件
我正在做 Linux 黑客基础知识(Starch Press)的第 1 章练习:
Create a new directory called hackerdirectory and create a new file in that directory named hackedfile. Now copy that file to your /root directory and then rename it secretfile.
所以我做了 mkdir hackerdirectory
然后 cd hackerdirectory
然后 touch hackedfile
然后 sudo mv hackedfile /root
我的理解是 /root
是顶级主目录,但是当我 cd ..
回到主目录 ls -l
时,它不在那里:
drwxrwxr-x 23 nobu nobu 4096 Jul 9 18:24 anaconda3
-rw-r--r-- 1 nobu nobu 4243 May 3 02:10 backblue.gif
-rw-rw-r-- 1 nobu nobu 25120 Mar 23 07:02 CERTIFICATE
drwxrwxr-x 3 nobu nobu 4096 Mar 30 05:01 client-configs
-rw-rw-r-- 1 nobu nobu 412 May 3 03:18 cookies.txt
-rw------- 1 root root 8560640 Apr 11 09:59 core
drwxr-xr-x 3 nobu nobu 4096 Sep 11 20:34 ctf
drwxr-xr-x 18 nobu nobu 4096 Sep 13 12:33 Desktop
drwxr-xr-x 4 nobu nobu 4096 Sep 8 18:59 Diamondhead
drwxrwxr-x 6 nobu nobu 4096 Sep 15 16:42 Documents
drwxr-xr-x 27 nobu nobu 12288 Sep 17 14:28 Downloads
-rw-r--r-- 1 nobu nobu 8980 Mar 20 06:44 examples.desktop
-rw-r--r-- 1 nobu nobu 828 May 3 02:10 fade.gif
drwxrwxr-x 4 nobu nobu 4096 Jun 27 02:38 fullstack
drwxrwxr-x 11 nobu nobu 4096 Jul 12 16:21 gym
drwxr-xr-x 2 nobu nobu 4096 Sep 17 15:37 hackerdirectory
drwx------ 2 nobu nobu 4096 May 3 03:18 hts-cache
-rw-rw-r-- 1 nobu nobu 2101 May 3 03:18 hts-log.txt
drwxr-xr-x 6 nobu nobu 4096 Sep 4 23:27 locust_k8s
drwxr-xr-x 10 nobu nobu 4096 Aug 28 11:44 mecab-ipadic-neologd
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Music
drwxr-xr-x 14 nobu nobu 4096 Aug 24 14:10 myapp
drwx------ 3 nobu nobu 4096 Mar 30 03:28 openvpn-ca
drwxr-xr-x 4 nobu nobu 4096 Aug 19 19:47 Pictures
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Public
drwxr-xr-x 3 nobu nobu 4096 Aug 15 12:34 repos
drwxr-xr-x 6 nobu nobu 4096 Sep 4 23:23 snap
drwxr-xr-x 2 nobu nobu 4096 Mar 20 06:52 Templates
-rw-rw-r-- 1 nobu nobu 5477405 Jul 5 08:17 tf
-rwxrwxr-x 1 nobu nobu 4474932 Oct 24 2017 unetbootin-linux-latest
drwxr-xr-x 3 nobu nobu 4096 Apr 27 11:56 Videos
drwx------ 3 nobu nobu 4096 Jun 27 02:46 'VirtualBox VMs'
drwxrwxr-x 5 nobu nobu 4096 May 3 02:36 websites
drwxrwxr-x 2 nobu nobu 4096 Jul 9 21:15 work
现在我做到了:
nobu@nobu-ThinkPad-T420:~$ locate hackedfile
nobu@nobu-ThinkPad-T420:~$ whereis hackedfile
hackedfile:
这是什么意思?我已经尝试 sudo su
然后 ls
但仍然看不到它。
编辑:所以我根据下面的命令找到了它,但无法摆脱它。
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
/root/hackedfile
nobu@nobu-ThinkPad-T420:~$ sudo rm /root/hackedfile
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
nobu@nobu-ThinkPad-T420:~$ whereis hackedfile
hackedfile:
编辑(未列出)
nobu@nobu-ThinkPad-T420:~$ sudo ls -al /root
total 64
drwx------ 12 root root 4096 Sep 17 16:23 .
drwxr-xr-x 28 root root 4096 Sep 9 12:45 ..
drwx------ 2 root root 4096 Jul 10 07:31 .aptitude
-rw------- 1 root root 1124 Sep 17 16:30 .bash_history
-rw-r--r-- 1 root root 3106 Oct 23 2015 .bashrc
drwx------ 4 root root 4096 Apr 11 05:47 .cache
drwx------ 7 root root 4096 Apr 11 15:54 .config
drwx------ 3 root root 4096 Mar 22 02:47 .dbus
drwx------ 3 root root 4096 Apr 11 12:23 .gnupg
drwxr-xr-x 4 root root 4096 Aug 17 09:20 .java
drwxr-xr-x 3 root root 4096 Apr 1 08:12 .local
drwxr-xr-x 2 root root 4096 Mar 30 02:55 .nano
drwxr-xr-x 2 root root 4096 Aug 21 11:13 .oracle_jre_usage
-rw-r--r-- 1 root root 148 Aug 18 2015 .profile
drwx------ 2 root root 4096 Sep 4 22:58 .ssh
-rw-r--r-- 1 root root 220 Aug 8 14:02 .wget-hsts
编辑(当 sudo su
时)
root@nobu-ThinkPad-T420:/home/nobu# whereis hackedfile
hackedfile:
所以当我执行命令 whereis
时,它会显示文件。所以真的删了吗?
但现在当我尝试时:sudo find /root -type f -name hackedfile
我得到:
nobu@nobu-ThinkPad-T420:~$ sudo find /root -type f -name hackedfile
nobu@nobu-ThinkPad-T420:~$
因此它似乎已经消失了,除了执行 `whereis' 仍然用冒号显示它。
编辑:
请注意 whereis
returns 无论您要查找什么都说 filename:
然后在冒号后列出位置的 PATH。
下面是如何使用find
:
find
这是我上面列出的教科书。
尝试pwd
查看您在文件系统中的位置。您可能会使用 sudo ls -al /root