Find

Find files that owns by user cage

find / -user cage 2> /dev/null

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 redirection.

2>/dev/null

This is a STDERR redirection to the 'null device', which we will come back to in the next section. This redirection ensures that no errors are displayed in the terminal. This redirection must not be an option of the 'find' command.

find / -type f -name *.conf -user root -size +25k -size -28k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/null

This will find how many files it returns based on the name

find / -type f -name *.log 2>/dev/null | wc -l

This will find the total package installed in the system

dpkg --get-selections | grep -c -v deinstall

This will find some files that has document extensions

for ext in $(echo ".xls .xls* .xltx .csv .od* .doc .doc* .pdf .pot .pot* .pp*");do echo -e "\nFile extension: " $ext; find / -name *$ext 2>/dev/null | grep -v "lib\|fonts\|share\|core" ;done

Last updated