Commands by emphazer (18)


  • 1
    curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ipv6_prefix/ {print $4}'
    emphazer · 2018-10-05 13:01:03 0

  • 1
    curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | awk -F'"' '/ip_prefix/ {print $4}'
    emphazer · 2018-10-05 12:59:33 0

  • 2
    nslookup -q=TXT _netblocks.google.com | grep -Po '\b([0-1]?\d{1,2}|2[0-4]\d|25[0-5])(\.([0-1]?\d{1,2}|2[0-4]\d|25[0-5])){3}(/\d{1,2})\b'
    emphazer · 2018-10-05 12:50:48 0
  • requires imagemagick. -background transparent is of course optional. Show Sample Output


    1
    convert -background transparent input.png -define icon:auto-resize=16,32,48,64,128 favicon.ico
    emphazer · 2018-09-27 13:12:03 0
  • wget http://nginx.org/download/nginx-1.15.3.tar.gz && tar -xzf 1.15.3.tar.gz && cd nginx-1.15.3 Show Sample Output


    1
    ./configure --help | grep -P "^ +--with-(?!(poll|select))[^=]+(_module( |$)| (module|support)$)" | sed -r 's/((dis|en)able|build) /# /'
    emphazer · 2018-09-14 12:54:06 0
  • opposite of https://www.commandlinefu.com/commands/view/10014/urldecoding-with-one-pure-bash-builtin ;-) Show Sample Output


    0
    function URLEncode { local dataLength="${#1}"; local index; for ((index = 0;index < dataLength;index++)); do local char="${1:index:1}"; case $char in [a-zA-Z0-9.~_-]) printf "$char"; ;; *) printf "%%%02X" "'$char"; ;; esac; done; }
    emphazer · 2018-09-14 12:08:10 0
  • sleep in microseconds instead of seconds Alternatively to usleep, which is not defined in POSIX 2008 (though it was defined up to POSIX 2004, and it is evidently available on Linux and other platforms with a history of POSIX compliance), the POSIX 2008 standard defines nanosleep Show Sample Output


    1
    time usleep 100000
    emphazer · 2018-09-06 10:28:26 0
  • Binding a server to privileged port on Linux w/o running as root This is applicable to any service using privileged ports (< 1024), for instance to run a HTTP server on port 80 or a LDAP directory server on port 389 for example. Show Sample Output


    3
    sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python2.7
    emphazer · 2018-09-04 17:30:47 0

  • 0
    mknod -m 0666 /dev/null c 1 3
    emphazer · 2018-08-16 12:10:16 0
  • https://stackoverflow.com/questions/10768160/ip-address-converter Show Sample Output


    1
    awk {'print rshift(and($1, 0xFF000000), 24) "." rshift(and($1, 0x00FF0000), 16) "." rshift(and($1, 0x0000FF00), 8) "." and($1, 0x000000FF)'}
    emphazer · 2018-08-16 11:46:26 0
  • (echo "https://example.com/"; echo "https://example.com/"; echo "https://example.com/"; echo "https://example.com/") | parallel -k 'ab -n 10000 -c 15 {}'


    0
    cat url_list.txt | parallel -k 'ab -n 10000 -c 15 {}'
    emphazer · 2018-05-17 11:23:28 0
  • # 4 cores with 2500 pi digits CPUBENCH 4 2500 . every core will use 100% cpu and you can see how fast they calculate it. if you do 50000 digitits and more it can take hours or days Show Sample Output


    1
    CPUBENCH() { local CPU="${1:-1}"; local SCALE="${2:-5000}"; { for LOOP in `seq 1 $CPU`; do { time echo "scale=${SCALE}; 4*a(1)" | bc -l -q | grep -v ^"[0-9]" & } ; done }; echo "Cores: $CPU"; echo "Digit: $SCALE" ;}
    emphazer · 2018-05-14 17:30:37 0

  • 1
    find /var/www/ -type f -name '*.[jJ][pP][gG]' -print0 | xargs -n 1 -P 8 -0 jpegoptim --strip-all --preserve --preserve-perms --quiet
    emphazer · 2018-05-14 16:39:21 0

  • 0
    find /var/www/ -type f -name '*.[pP][nN][gG]' -print0 | xargs -L 1 -n 1 -P 8 -0 optipng -preserve -quiet -o7 -f4 -strip all
    emphazer · 2018-05-14 16:38:11 0
  • Explanation It creates dnsmasq-com-blackhole.conf file with one line to route all domains of com zones to 0.0.0.0 You might use "address=/home.lab/127.0.0.1" to point allpossiblesubdomains.home.lab to your localhost or some other IP in a cloud. Show Sample Output


    0
    echo "address=/com/0.0.0.0" | sudo tee /etc/dnsmasq.d/dnsmasq-com-blackhole.conf && sudo systemctl restart dnsmasq
    emphazer · 2018-05-14 16:28:18 0
  • a quick function for searching changed files. just copy it in the bash Show Sample Output


    0
    FINDDATE() { LOCATION="${1:-.}"; find ${LOCATION} -type f -print0 | xargs -0 stat -c "%y %n" | sort | sed 's/.\([0-9]\)\{9,\} +0[1-2]00/\t/' | sed 's/ /\t/g' }
    emphazer · 2018-05-14 14:27:41 0
  • Check whether hyperthreading is enabled or not. a better solution as nproc should work on all OS with awk Show Sample Output


    1
    awk -F: '/^core id/ && !P[$2] { CORES++; P[$2]=1 }; /^physical id/ && !N[$2] { CPUs++; N[$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo
    emphazer · 2018-05-14 14:17:33 0
  • this is good for variables if you have many script created files and if you want to know which one is the last created/changed one..


    1
    find . -type f -print0 | xargs -0 stat -c '%y %n' | sort -n -k 1,1 | awk 'END{print $NF}'
    emphazer · 2018-05-14 08:47:41 2

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Not a kismet replacement...
If you're like some individuals who rely on ndiswrapper and cannot use kismet, this command may be of service. watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption'" Or... watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption' | egrep 'linksys'" :-) Hopefully you'll find some dd-wrt compatible routers.

list files recursively by size

Install pip with Proxy
Installs pip packages defining a proxy

Expand shortened URLs
curl(1) is more portable than wget(1) across Unices, so here is an alternative doing the same thing with greater portability. This shell function uses curl(1) to show what site a shortened URL is pointing to, even if there are many nested shortened URLs. This is a great way to test whether or not the shortened URL is sending you to a malicious site, or somewhere nasty that you don't want to visit. The sample output is from: $ expandurl http://t.co/LDWqmtDM

cleanup /tmp directory
Cleans all files in /tmp that have been accessed at least 2 days ago.

get some information about the parent process from a given process

Decode base64-encoded file in one line of Perl
Another option is openssl.

Search inside a folder of jar/zip files
Great for finding which jar some pesky class is hiding in!

use mplayer to watch Apple Movie Trailer instead of quicktime player
http://trailers.apple.com/trailers/ just copy the .mov link and use mplayer to stream

Function to output an ASCII character given its decimal equivalent
I've corrected the function. My octal conversion formula was completely wrong. Thanks to pgas at http://mywiki.wooledge.org/BashFAQ/071 for setting me straight. The new function is from pgas and is very fast.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: