Security article
HTB Academy - Fundamentals - Find Files and Directories
HTB Academy - Fundamentals - Find Files and Directories: 🎯 Tasks 1) Find the config file created after 2020-03-03 whose size is >25 KiB and <28 KiB. 2) Count how many files on the system have the .bak extension. • HTB Academy • htb-academy, linux-fundamentals
🎯 Tasks
- Find the config file created after
2020-03-03whose size is >25 KiB and <28 KiB. - Count how many files on the system have the
*.bakextension.
✅ Recommended Commands
1) Locate the matching “.conf” file
Use GNU find with clear size units, date filtering, and a tidy printout:
# Fast & tidy (stays on current filesystem only; drop -xdev if you want to traverse all mounts)
sudo find / -xdev -type f -name "*.conf" -size +25k -size -28k -newermt "2020-03-03" -printf "%p %k KiB %TY-%Tm-%Td %TH:%TM
" 2>/dev/null | sortNotes
-type f→ files only.-size +25k -size -28k→ strictly greater than 25 KiB and strictly less than 28 KiB.-newermt "2020-03-03"→ modified after this date (mtime).- If your lab means “on 2020‑03‑04 only”, add an upper bound:
... -newermt "2020-03-03" ! -newermt "2020-03-04" ...-printfshows: path, size (KiB), and timestamp so you can confirm quickly.2>/dev/nullhides permission errors; keep it outsidefindoptions (as you did).
Answer 1 (fill from output):
_______________________________
2) Count files ending with “.bak” (case‑insensitive)
sudo find / -xdev -type f -iname "*.bak" 2>/dev/null | wc -lFaster variant (avoids spawning wc on long lines):
sudo find / -xdev -type f -iname "*.bak" -printf "." 2>/dev/null | wc -cAnswer 2 (number):
_______
💡 Extra Tips
- Creation vs modification time: Linux generally tracks modification (mtime), access (atime), and status change (ctime). “Created after” in labs usually means filtering by mtime (
-newermt). If you truly need ctime (status changes), GNUfindsupports:-newerct "2020-03-03" - Traverse all mounts: remove
-xdevif you need to search across/proc,/sys,/run, extra disks, etc. Expect it to be slower. - Skip noisy trees without
-xdev:sudo find / -path /proc -prune -o -path /sys -prune -o -path /run -prune -o -type f -iname "*.bak" -print 2>/dev/null | wc -l - Preview with
ls: if you want a long listing for each hit:sudo find / -type f -name "*.conf" -size +25k -size -28k -newermt "2020-03-03" -exec ls -al {} + 2>/dev/null
🧪 Your one‑liners (from the lab)
- Sized range sample:
find . -type f -size +30k -size -40k -exec ls -l {} + - Your tailored filter (good!):Add
find / -iname "*.conf" -size +25k -size -28k -newermt 2020-03-03 2>/dev/null-type fand consider-printffor clean answers as shown above.
Good luck! Once you paste the outputs, I can sanity‑check them and format the final answers for you.