Source: https://foxhop.net/f348124b-2f95-11f1-a15f-e86a64d24d78/advanced-bash-techniques
Snapshot: 2026-05-25T01:38:02Z
Generator: Remarkbox 1527ef7

This is a thread snapshot. The living document lives at the source URI above — it may have been edited, extended, or replied-to since.

Scan for living source

advanced bash techniques

find and change all files

sudo find . -type f -print0 | xargs -0 ls -hal

sudo find . -type f -print0 | xargs -0 sudo chown www-data:www-data

sudo find . -type f -print0 | xargs -0 sudo chmod 0644

find and change all directories:

sudo find . -type d -print0 | xargs -0 sudo chmod 0775

Remove a particular line from all files in a directory

for file in /tmp/test/*
  do
    cp -p $file $file.tmp
    egrep -v "RegexToRemove" $file.tmp > $file
    rm -rf $file.tmp
  done

apache logs count unique ip addresses

sudo cat access.log | awk '{ print $1; }' | sort | uniq -c | sort -n

Bash Perl search and replace multiple files one liner

perl -pi -w -e 's/search/replace/g;' *.extension

explanation:

-e

means execute the following line of code.

-i

means edit in-place

-w

write warnings

-p

loop

Bash sed search and replace multiple files one liner

sed -i'' -e 's/search/replace/g' *

Get a coma separated list of libvirt guests

virsh list | egrep -v 'Domain|Name|----|^$' | awk '{printf "%s," , $2}' > /tmp/virthosts

Source: https://foxhop.net/f348124b-2f95-11f1-a15f-e86a64d24d78/advanced-bash-techniques
Snapshot: 2026-05-25T01:38:02Z
Generator: Remarkbox 1527ef7