Skip to main content

find secrets

LPI E - Scripting

4.3 Where Data is Stored

Finding The Data


Here are just a few examples of the many parameters and switches that can be used with the "find" command to locate configuration files for Linux programs and binaries.
 
By understanding these basic parameters, a Linux learner can begin to effectively search for files and directories using the terminal. 

👇👽💦

  • This command searches the "/etc" directory and all its subdirectories for files with the ".conf" extension.
    • $ find /etc -name "*.conf"
  • This will search for the file named "nginx.conf" starting in the "/etc/" directory.
    • $ find /etc/ -name nginx.conf
  • ... to find the configuration files for the Apache web server, you can use the following command
    • $ find /etc -name "apache*"
  • This command searches the "/usr" directory and all its subdirectories for files of type "f" (regular file) with the ".txt" extension.
    • $ find /usr -type f -name "*.txt"
  • This command searches the "/var/log" directory and all its subdirectories for directories with the name "apache2".
    • $ find /var/log -type d -name "apache2"
  • This command searches the "/home" directory and all its subdirectories for files modified within the last 7 days.
    • $ find /home -type f -mtime -7
  • This command searches the "/var/log" directory and all its subdirectories for files larger than 1 megabyte.
    • $ find /var/log -type f -size +1M
  • This will search for all regular files that are executable in the /usr/bin directory and its subdirectories
    • $ find /usr/bin -type f -executable
  • This will search for all symbolic links in the /usr/bin directory and its subdirectories and return their full path
    • $ find /usr/bin -type l
  • This command searches for all files with a ".conf" extension under the "/etc/httpd" directory, which is the default location for Apache HTTP server configuration files
    • $ find /etc/httpd -type f -name "*.conf"
  • This command searches for all files with a ".cnf" extension or with the name "my.cnf" under the "/etc/mysql" directory, which is the default location for MySQL database configuration files
    • $ find /etc/mysql -type f -name "*.cnf" -o -name "my.cnf"
  • This command searches for all files with a ".conf" extension or under the ".conf.d" directory, but excludes files under any "sites-*" subdirectories, under the "/etc/nginx" directory, which is the default location for Nginx web server configuration files
    • $ find /etc/nginx -type f \( -name "*.conf" -o -name "*.conf.d" \) -not -path "*/sites-*/*"
  • Find all files in the current directory and its subdirectories modified within the last 24 hours, and delete them:
    • $ find . -type f -mtime -1 -delete
  • Find all files larger than 100MB in the /home directory and print their names and sizes in human-readable format
    • $ find /home -type f -size +100M -printf "%s %p\n" | numfmt --to=iec-i --field=1 --suffix=B
  • Find all files that are not owned by the user "john" in the /var/log directory and change their ownership to "john"
    • $ find /var/log ! -user john -exec chown john {} +