Command Line Magic – Telegram
Command Line Magic
713 subscribers
7 photos
18 links
Cool Unix/Linux Command Line tricks you can use in ~140 characters
Download Telegram
grep -Poh '(?<=uid=")[^"]+' *.xml | sort | uniq 

# Grab the uid value from a bunch of XML files by using PCRE look behind assertions to provide context. I was checking for the sequence number being used in a bunch of XML address book files.
snmpwalk -h |& grep OID 

# Some commands send their help output to STDERR, Using |& in BASH 4+ sends STDERR to STDIN of next command.
sudo tree -Jhfpug  / 

# Easily makes a full filesystem json output including full path, file permissions, owner, size, etc.
less -I 

# Use -I to force case insensitive searches. If you use the -i option to less, it only ignores case if you do not use uppercase letters in your search pattern. With -i, any uppercase letter used in the search pattern and it changes the search to be case sensitive.
grep -B5 "ldap server connection error" maillog | grep user=

# Use the -B option of grep to provide 5 (B)efore lines of context so that you can then search that context for something else, like the username to look for commonalities.
lsof -i TCP:80 

# Show what processes are using port 80 either locally or remotely. Need to be root for unowned processes.
mkdir good; for f in *JPG ;do mv "${f%JPG}"* good/;done 

# Move JPGs and related files (e.g. raws + sidecar XMP) for workflow
pgrep rsync | xargs ionice -c3 -p 

# Adjust all rsync processes on the system so that they have lower (idle) IO priority.
seq 2457 7542 | grep 2 | grep 4 | grep 5 | grep 7

# Find all potential 4 digit combinations that only have one of each number 2, 4, 5, and 7 for a CTF game.
grepcidr 2102:306:146e:f5d0::/64 /var/log/secure
# Use a CIDR network format aware version of grep to search for hits from IPs within the IPv6 range 2102:306:146e:f5d0::/64
date +%j

# Today is International Bad Programmer's Day
yes $'\U1F427' | head -29 

# Happy Birthday Linux!
yes "$(seq 231 -1 16)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .02; done 

# Make colorful gradients in your shell
echo -n pentacosiomedimni | wc -m 

# Check the length of a word in terms of it's character count. Although this word doesn't contain unicode characters, using the -m option would give you the expected answer if it did.
sort -V ipv4addrs.txt

# In GNU sort, you can use -V (version sort) to also sort IPv4 addresses numerically according to each octet. For IPv6, try using ipv6calc --addr2fulluncompaddr first to normalize the addresses and pass to a plain sort.
df -BG

# List the file systems so that their space used/available is shown in gigabytes. This is more consistent than using just -h to show human readable. Good for if you have several and want to compare.
find ${PATH//:/ } -type f -maxdepth 1 -perm /6000 -ls 

# Find all the programs in path directories with suid or sgid bits set. Of course you probably just want to do this on the whole filesystem.
zless, zgrep, zcat, zdiff

# There are helper commands for dealing with compressed files (gz, bz2 and xz). They have a z, bz or xz prefix. For instance, you can use zless like this zless access_log.gz to view it the same way you would with less. Others work similarly.
sudo tune2fs -m0.2 /dev/sda1
# Running out of space on that 1TB drive? On Linux, the ext[234] filesystems reserve 5% of the space by default to only used by the root user, that's 50GB! You can reduce it to 0.2%
mping (melody ping) will make an audible ping sound(remove headphones) pitched according to the latency. Ex: mping domains.au
mping(){ ping $1|awk -F[=\ ] '/me=/{t=$(NF-1);f=3000-14*log(t^20);c="play -V0 -q -n synth 1 pl " f " vol 1 reverb -w ";print $0;system(c)}';}