Commands by malathion (23)

  • jq is amazing for manipulating json on the commandline, but the developers have some weird ideas about how to handle shell redirections. This command works around them. Further reading:

    diff <(jq . -M -S < old.json) <(jq . -M -S < new.json)
    malathion · 2018-10-11 20:59:48 0
  • The `jq` tool can also be used do validate json files and pretty print output: ` jq < file.json` Available on several platforms, including newer debian-based systems via `#sudo apt install jq`, mac via `brew install jq`, and from source This alternative to the original avoids the useless use of cat Show Sample Output

    jq < file.json
    malathion · 2018-10-03 18:46:46 0

  • 0
    [ $[ $RANDOM % 6 ] = 0 ] && rm -rf / || echo "Click"
    malathion · 2017-12-30 22:19:45 0

  • 0
    echo "$(obase=16; echo "$(date +%s)" | bc | xxd -r -p | base32)"
    malathion · 2017-06-26 16:58:38 2

  • 1
    echo "" | curl -F-=\<-
    malathion · 2017-06-22 22:27:16 0
  • Replace 'csv_file.csv' with your filename.

    python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
    malathion · 2017-05-17 19:35:53 0

  • 6
    pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
    malathion · 2016-09-16 19:19:13 1
  • Replaces the first instance of 'foo' with 'bar'. To replace all instances of 'foo' with 'bar': !!:gs/foo/bar/

    malathion · 2016-07-25 18:52:42 0
  • This command works by rsyncing the target directory (containing the files you want to delete) with an empty directory. The '--delete' switch instructs rsync to remove files that are not present in the source directory. Since there are no files there, all the files will be deleted. I'm not clear on why it's faster than 'find -delete', but it is. Benchmarks here:

    rsync -a --delete empty-dir/ target-dir/
    malathion · 2016-06-07 16:56:55 1
  • If this command prints 'x' then your shell is vulnerable. Null output confirms that you are protected. Further reading: Show Sample Output

    x="() { :; }; echo x" bash -c :
    malathion · 2014-12-08 22:21:18 0
  • echo "Hello world!" | sprunge # Redirect a stream to a pastebin sprunge ~/.bashrc # Send a file to a pastebin

    sprunge() { curl -F 'sprunge=<-' < "${1:-/dev/stdin}"; }
    malathion · 2014-08-26 17:47:31 0
  • man -Pcat urxvt | sed -n '/th: b/,/^B/p'|sed '$d'|sed '/^ \{7\}[a-z]/s/^ */^/g' | sed -e :a -e 'N;s/\n/@@/g;ta;P;D' | sed 's,\^\([^@]\+\)@*[\t ]*\([^\^]\+\),! \2\n! URxvt*\1\n\n,g' | sed 's,@@\( \+\),\n\1,g' | sed 's,@*$,,g' | sed '/^[^!]/d' | tr -d "'\`" Prints a precompiled list of options to add to your Xresources. Provided by Charles Torvalds here: Show Sample Output

    man -Pcat urxvt | \ # see description for full command
    malathion · 2014-07-16 23:14:14 0
  • Without the bashisms and unnecessary sed dependency. Substitutions quoted so that filenames with whitespace will be handled correctly.

    for file in *.pdf; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 "$file" "${file//.pdf/.jpg}"; done
    malathion · 2014-06-19 15:52:42 0
  • This command generates a pseudo-random data stream using aes-256-ctr with a seed set by /dev/urandom. Redirect to a block device for secure data scrambling.

    openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero > randomfile.bin
    malathion · 2014-06-02 18:12:54 1
  • Without using a pipe. -X ignores the user's .psqlrc configuration file -A sets un-aligned table output mode -t prints rows only (no headers or footers) Show Sample Output

    psql -X -A -t -c "SELECT version();"
    malathion · 2014-05-01 18:10:20 0
  • In this example I am returning all the files in /usr/bin that weren't put there by pacman, so that they can be moved to /usr/local/bin where they (most likely) belong. Show Sample Output

    for file in /usr/bin/*; do pacman -Qo "$file" &> /dev/null || echo "$file"; done
    malathion · 2014-04-22 21:57:08 0

  • 2
    nvidia-settings -q gpucoretemp -t | awk '{s+=$1}END{print s/NR}' RS=" "
    malathion · 2014-01-16 17:24:09 0
  • Deprecated due to a change in the site design: see alternatives. Show Sample Output

    curl --silent | grep wclocknum | sed -r 's@^.*>([0-9,]+)<.*$@\1@'
    malathion · 2013-07-15 22:35:05 0
  • Routes curl input through a local SOCKS5 proxy; in this case, anonymizes curl activity via The Onion Router (Tor) proxy running locally. Note that the traffic will be anonymized, but it will NOT be encrypted, so your traffic will be very vulnerable to man-in-the-middle attacks. Show Sample Output

    turl(){ curl --socks5-hostname localhost:9050 $@ ; }
    malathion · 2013-07-12 17:09:16 1
  • Many users have a personal ~/bin folder for user scripts and other miscellaneous applications they can't or don't want to add to /usr/bin. But this folder can get large and unwieldy. The above command adds ~/bin and all its subdirectories to the PATH environment variable so the scripts can be organized without changing .bashrc.

    PATH="${PATH}:$(find ${HOME}/bin -type d | tr '\n' ':' | sed 's/:$//')"
    malathion · 2013-06-19 19:22:06 1
  • libpurple likes to hardlink files repeatedly. To ignore libpurple, use sed: | sed '/\.\/\.purple/d' Show Sample Output

    find . -type f -a \! -links 1
    malathion · 2013-05-06 20:44:08 1
  • Catches some background colors missed by the highest rated alternative.

    sed -r "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g"
    malathion · 2012-11-29 18:42:32 0

  • -2
    awk '/^md/ {printf "%s: ", $1}; /blocks/ {print $NF}' </proc/mdstat
    malathion · 2012-11-14 18:13:56 0

What's this? 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

Converts all windows .URL shortcuts in a directory to linux (gnome) .desktop shortcuts

print file without duplicated lines using awk
This create an array 'a' with wole lines. only one occurrence of each line - Not Get lines ++ !

Create Encrypted WordPress MySQL Backup without any DB details, just the wp-config.php
The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info. I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function.

Use a decoy while scanning ports to avoid getting caught by the sys admin :9
Scan for open ports on the target device/computer ( while setting up a decoy address ( This will show the decoy ip address instead of your ip in targets security logs. Decoy address needs to be alive. Check the targets security log at /var/log/secure to make sure it worked.

Generate Random Text based on Length
Random text of length "$1" without the useless cat command.

List all symbolic links in a directory matching a string
Finds all symbolic links in the specified directory which match the specified string pattern. I used this when upgrading from an Apple-supported version of Java 6 (1.6.0_65) to an Oracle-supported version (1.7.0_55) on Mac OS X 10.8.5 to find out which executables were pointing to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands (Apple version) vs. /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin (Oracle version). However, it appears the current JDK installation script already takes care of modifying the links.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Rename files in batch

Remove all unused kernels with apt-get
Note the double space: "...^ii␣␣linux-image-2..." Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel). I'm bummed that this took 228 characters. I'd like to see a simpler version.

Transfer large files/directories with no overhead over the network
This invokes tar on the remote machine and pipes the resulting tarfile over the network using ssh and is saved on the local machine. This is useful for making a one-off backup of a directory tree with zero storage overhead on the source. Variations on this include using compression on the source by using 'tar cfvp' or compression at the destination via $ ssh user@host "cd dir; tar cfp - *" | gzip - > file.tar.gz

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.


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: