Skip to content

09/09/26 HTB: Linux Fundamentals

Which

Returns the path or link will be executed with a specified command. If the program does not exist then no result will be displayed.

Find

Searches recursively with user provided parameters. Find searches the filesystem live.

Option Description
-type f Hereby, we define the type of the searched object. In this case, f stands for file.
-name *.conf With -name, we indicate the name of the file we are looking for. The asterisk (*) stands for all files with the .conf extension.
-user root This option filters all files whose owner is the root user.
-size +20k We can then filter all the located files and specify that we only want to see the files that are larger than 20 KiB.
-newermt 2020-03-03 With this option, we set the date. Only files newer than the specified date will be presented.
-exec ls -al {} \; This option executes the specified command, using the curly brackets as placeholders for each result. The backslash escapes the next character from being interpreted by the shell because otherwise, the semicolon would terminate the command and not reach the find command.
2>/dev/null This is a STDERR redirection to the null device. This redirection ensures that no errors are displayed in the terminal. This redirection is not an option of the find command.

Locate

Searches a pre-built database of filenames. Locate does not search the filesystem directly. Instead it searches a database containing paths that were indexed previously. Locate is much faster than find but the trade off is that the database may not be up to date.

File Descriptors

There are three file descriptors.

0 = STDIN, data stream input

1 = STDOUT, data stream output

2 = STDERR, data stream errors

So if using the terminal, your command would be STDIN, the response would be STDOUT, and any errors are STDERR.

This is important to understand so that we can accurately use commands such as 2>/dev/null, which moves all data stream errors into the null device, i.e. it removes the errors from the output.

A single arrow > redirects the data stream, this typically means replacing the file at the output location if it is a file path. Double greater than arrows >> will append the output, add the output to the file.

wc

wc stands for word count, it is a terminal application we can use to count lines, words, characters, or bytes.

-c, bytes

-m, characters

-l, lines

-w, words