3 basic bash commands that will improve your life

#2: find command

TLDR: gimme the command

find / -iname "passwd" 2>/dev/null

Explanation

This command can be especially useful in CTF scenarios where you are trying to search for a file named flag.txt. However this can also be useful to everyday Linux enjoyers who have placed a file and cannot for the life of them remember where it is located. *IMPORTANT*: this command may require sudo privileges!

Going back to our previous example, let’s say that you want to check if your Linux system has a file called “passwd”. How would you do that?
Well, you could run a simple command find -iname "passwd", assuming you are in /etc directory, you will probably come up empty. This presents a problem: unless you are in the correct directory you will not find your file. But then how would you know which directory you need to be in ?

Enter the system wide search. if you use find / -iname "passwd" you will do a search from the room directory.

But now you you will still be met with a wall of text, this is not great. Here is the final solution you can use:

find / -iname "passwd" 2>/dev/null

Here is what we will see in our terminal:

Now this is a lot more managable and pleasant to look at. Let’s break down the commands below:

find unix command used to look for files and directories
/ specifies that we start our search at the root directory
-iname [FILE_NAME]iname flag tells the find command to be case incesitive
2 > /dev/null this command redirects error messages (more on this below)

More on redirection command

You will often see 2 > /dev/null command at the end of other commands. The point of this command is to send the errors away from the terminal. Here’s a breakdown of the syntax:

2 this is the description for standard erro
> this is the redirection operator
/dev/nullthis is a special file that discards all data written to it