>_ IzzyLab

Hands-on task

This task is step 6 of the course “Linux: everyday tasks”

Find every PHP script on the site

easy~3 min

You've inherited a server with an old website in /srv/www. Before touching anything, take inventory: find all files with the .php extension at any depth and write their full paths (starting with /srv/www), sorted, to /root/php_files.txt.

What you'll practise:
  • find
  • -name
  • glob patterns
  • sort
  • recursive traversal

Topic breakdown

find is a recursive traversal tool: the first argument is the starting point, followed by the selection conditions. The name condition takes a glob pattern, and it's important to protect it with quotes — otherwise the shell substitutes matches from the current directory before find even starts. The pattern is matched against the whole name, so *.php won't catch index.php.bak. The order in which find prints paths depends on the file system, so to get a stable list the output is sorted.

What's checked

  1. /root/php_files.txt created
  2. all .php listed, full paths, sorted

What it looks like