Shell commands

A list of commands I’ve used over the years.

# Remove deleted or moved files from `svn`:
svn status --ignore-externals | grep ! | tr -s ' ' | cut -d ' ' -f2 | xargs svn rm
# Get contents of file from line 5 to line 13:
sed -n -e 5,13p [FILE]
# Find all .php files and search/replace string
find -name "*.php" -not -path ".svn" -print | xargs grep -l "require_lib( 'old' )" | xargs -I X sed -i -e "s|require_lib( 'old' )|require_lib( 'new' )|g" X
# Execute a command in every folder in current directory
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd {} && pwd" \;
# OpenWRT cron for switching changing LED color if pinging 8.8.8.8 fails
ping -q -c 5 8.8.8.8 && { echo 0 > /sys/devices/platform/gpio-leds/leds/inet:orange/brightness; echo 255 > /sys/devices/platform/gpio-leds/leds/inet:blue/brightness; } || { echo 255 > /sys/devices/platform/gpio-leds/leds/inet:orange/brightness; echo 0 > /sys/devices/platform/gpio-leds/leds/inet:blue/brightness; }
Tagged

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.