Issue
I am new to using Kali and I learned about the find command and wanted to try it out. I created a file called "Test" in my /home/kali/Documents Directory. Then I moved back to the [/] directory and used the command find -name Test
To my suprise, I recieved a plethora of errors and messages and I don't know what they mean or why they are popping up. Am I using the wrong command or using the wrong switches? In the examples I saw, the output was the directory of where the file was. What command and flags/switches do I use to find the exact location of the "Test" file i created in my Documents directory
This is the command I wrote to the terminal
This is the output I recieved (This is just a small piece of it)
Solution
The find command recursively search each file in each directory you provide:
find /home/kali /root -name test
This will search for a file or directory named test
in the directories /home/kali
and /root
. By default, if you don't provide any directory, find
will search in the current working directory named .
. So in your case, these 3 commands are equivalent (because you are in the directory /
):
find -name test
find . -name test
find / -name test
Now for your question. As I said, find
will recursively look in every directory in each directory you provide (in your case the implied CWD .
e.g. /
).
This means that find will look for test
in /
, /dev
, /root
, /proc
, ... and then in each subdirectory.
If you take /root
for example, it belongs to the root
user. If you look at the permissions on /root
, you will find the following:
$ ls -l /
...
drwxr-x--- 10 root root 4,0K 11 mai 20:17 root
...
As you can see, /root
belongs to the root
user and the root
group as indicated by root root
in the middle (the first refers to the owner and the second to the group). The letters at the left drwxr-x---
show the permissions on this directory:
d
means that it's a directoryrwx
means that the owner (root
in this case) has the right to read, write and execute this file.r-x
means that the grouproot
(users belonging to the grouproot
i.e. only root in practice) can read and execute this file.---
means that other users (i.e.kali
for example) have no right on this file
Now what does it means to have the read, write and execute rights. For a regular file, it's straight forward but for a directory it gets a bit tricky:
- read means that you can list the files/directories inside this directory
- write means that you can add file/directories in this directory
- execute means that you can
cd
into this directory or use this directory inside of a path
As other users (such as kali
) have no rights on /root
, find
will fail with a permission denied error.
If you have the sudo
rights on your machine, try:
sudo find / -name test
And this should work (although it will take some time to search your whole filesystem).
Answered By - Guillaume Courrier