Skip to content

Instantly share code, notes, and snippets.

@clok
Last active April 11, 2017 12:49
Show Gist options
  • Save clok/47ee44d076999033926c to your computer and use it in GitHub Desktop.
Save clok/47ee44d076999033926c to your computer and use it in GitHub Desktop.
useful shell oneliners
#!/bin/bash
# List most recently modified files (will take time)
find $1 -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head -20
# get file permissions for a file
perl -e 'printf "%o\n", (stat shift)[2]&07777' SOME-FILE
# Convert INT to IPv4
perl -MSocket=inet_ntoa -le "print inet_ntoa(pack(\"N\", shift))"
# Convert IPv4 to INT
perl -MSocket=inet_aton -le "print unpack(\"N\",inet_aton(shift))"
# Clean Docker images
docker rm -v $(docker ps -a -q -f status=exited) && docker rmi $(docker images -f "dangling=true" -q)
# List all installed Perl Modules
perl -MFile::Find=find -MFile::Spec::Functions -lw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
# get date for 3 months ago
date -d '3 months ago' +%Y-%m-%d
# List SG in use on EC2
aws ec2 describe-instances --output text | grep sg- | grep SECURITYGROUPS | sort -k 2 | uniq |awk -F "\t" '{print $2 "\t" $3}'
# List ALL SG in region
aws ec2 describe-security-groups --output text | grep SECURITYGROUPS | awk -F "\t" '{print $3 "\t" $2}'
# get container image hash ID
cat /proc/1/cgroup | grep 'docker/' | tail -1 | sed 's/^.*\///' | cut -c 1-12
# find 20 largest files
find . -type f -print0 | xargs -0 du -h | sort -hr | head -20
# sync ntp ubuntu
sudo apt-get update
sudo apt-get install -y ntp
sudo service ntp stop
sudo ntpdate -s time.nist.gov
sudo service ntp start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment