All commands (12,624)

  • Generate a random password quickly in CLI using openssl Show Sample Output


    0
    openssl rand -base64 12
    alikhalil · 2017-07-18 07:13:32 1
  • For example to add up the disk usage at several disjoint locations. The $[..] is for arithmetic evaluation in bash. Alternatively pipe to the bc command. Show Sample Output


    0
    numfmt --to=iec $[$(du -s /home/*/docs | cut -f 1 | paste -sd+)]
    odoepner · 2017-07-15 00:53:20 0
  • Some sites running on basic web servers don't support the HEAD request, so using "curl -I" on them doesn't work. This will automatically try "curl -I" at first and if that fails with a 4xx or 5xx status code, it falls back to "curl -i" and prints only the headers from that.


    0
    curlh() { x="$(curl -Is -w '%{http_code}' "$@")"; if [[ "$(tail -n 1 <<< "$x")" == [45]* ]]; then curl -is "$@" | awk '{ if (!NF) { exit }; print }'; else head -n -1 <<< "$x"; fi; }
    nyuszika7h · 2017-07-10 12:29:00 0

  • 0
    find . -name '*.log' | xargs ls -hlt > /tmp/logs.txt && vi /tmp/logs.txt
    zluyuer · 2017-07-07 05:13:51 1
  • Extrae los registros MX Show Sample Output


    0
    for domain in $(cat dominios.txt); do nslookup -type=mx $domain ; done >ejemplo.txt
    nedzoul · 2017-07-04 20:35:47 0
  • Obtener nombre de dominio de un archivo Show Sample Output


    0
    grep -oP '(?<=www\.)\s?[^\/]*' file | uniq
    nedzoul · 2017-07-04 20:18:40 1
  • Based / Inspired by malathion's below command http://www.commandlinefu.com/commands/view/20528/convert-csv-to-json Is written for python3 and is very easy to use csv2json *csv will convert all files ending in csv to json eg csv2json file.csv will output a file to file.json Validity of json tested in python3 and below site https://jsonformatter.curiousconcept.com/


    0
    csv2json() { for file in $@; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
    snipertyler · 2017-06-28 04:28:32 0

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

  • 1
    echo "http://commandlinefu.com" | curl -F-=\<- qrenco.de
    malathion · 2017-06-22 22:27:16 0
  • The Piano Phase piece, by Steve Reich is a minimalist composition which is played on two pianos played at slightly different tempos, a task that's very difficult to accomplish by human players. The auditive effects produced by the cell displacement produce beautiful patterns. See https://en.wikipedia.org/wiki/Piano_Phase . My rendered version: https://ydor.org/SteveReich/piano_phase.mp3 Requires sox to be installed on the system. There are multiple videos on youtube showing different approaches and experiences to this interpretation. There is also a synthesized version. Even if Bash can behave as a powerful pianist, a simple threaded version leaves full room to several time glitches and even negative displacements, the same issues that human pianists experience when playing the piece. The older the computer, the better the chaos added to the result due to the CPU load. Apparently that's the reason Steve Reich composes pieces such as this. Without further ado, please give a warm welcome to the Bash minimalist player on synthesized two-threaded pianos. Please turn off your cellphones.


    0
    phase() { while :; do for n in E4 F#4 B4 C#5 D5 F#4 E4 C#5 B4 F#4 D5 C#5; do /usr/bin/play -qn synth $1 pluck $n; done; echo -n "[$1]"; done; }; phase 0.13 & phase 0.131 &
    rodolfoap · 2017-06-14 20:29:26 4
  • This function will encrypt a bash script and will only execute it after providing the passphrase. Requires mcrypt to be installed on the system. cat hello #!/bin/bash case "$1" in ""|-h) echo "This is the fantastic Hello World. Try this:" $(basename $0) "[entity]" ;; moon) echo Good night. ;; sun) echo Good morning. ;; world) echo "Hello, world!" ;; *) echo Hi, $@. ;; esac scrypt hello Enter the passphrase (maximum of 512 characters) Please use a combination of upper and lower case letters and numbers. Enter passphrase: Enter passphrase: Stdin was encrypted. cat hello.scrypt . <(echo "$(/usr/bin/tail -n+2 $0|base64 -d|mcrypt -dq)");exit; AG0DQHJpam5kYWVsLTEyOAAgAGNiYwBtY3J5cHQtc2hhMQAV34412aaE8sRzQPQzi09YaNQPedBz aGExAARvB6A/HYValW4txoCFmrlp57lmvhKBbM4p+OUiZcCxr6Y+Mm7ogg3Y14pHi0CrfT70Tubq 9g8/kNJrQr7W/ogHpVuOOdD0YfuRatrV7W2+OlNQ63KX780g4qTHrTqNnyLp8sF5RQ7GwxyZ0Oti kROtVIU4g4+QAtn/k/e7h7yt4404VF1zzCYRSw20wmJz1o/Z0XO7E/DFBr5Bau7bWjnF7CRVtims HGrDwv1miTtAcyB9PknymDxhSyjDUdNhqXGBIioUgqjX1CKgedtO0hQp050MiQd3I6HacpSrVUIW kuuS+BtMrxHDy+48Mh1hidV5JQFP7LP5k+yAVLpeHd2m2eIT1rjVE/Bp2cQVkpODzXcWQDUAswUd vulvj/kWDQ== ./hello This is the fantastic Hello World. Try this: hello [entity] ./hello.scrypt Enter passphrase: This is the fantastic Hello World. Try this: hello.scrypt [entity] ./hello world Hello, world! ./hello.scrypt world Enter passphrase: Hello, world! Show Sample Output


    2
    scrypt(){ [ -n "$1" ]&&{ echo '. <(echo "$(tail -n+2 $0|base64 -d|mcrypt -dq)"); exit;'>$1.scrypt;cat $1|mcrypt|base64 >>$1.scrypt;chmod +x $1.scrypt;};}
    rodolfoap · 2017-06-14 16:27:20 2

  • 0
    bosh deployments --json | jq '.Tables[0].Rows[][0]' --raw-output
    jim80net · 2017-05-23 21:08:01 1
  • Replace 'csv_file.csv' with your filename.


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

  • 1
    ps aux | awk '{if ($8 ~ "D") print $0}'
    unixoid · 2017-05-17 13:29:13 1
  • Show file count into directories. Usefull when you try to find hugh directories that elevate system CPU (vmstat -> sy) Show Sample Output


    0
    find / -type d | while read i; do ls $i | wc -l | tr -d \\n; echo " -> $i"; done | sort -n
    Zort · 2017-05-12 00:02:43 1
  • you can use any common video format. if you don't need to change the size of gif output, just remove `-vf scale=320:-1` btw, 320:-1 means width is 320px and height would be set automatically


    2
    ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
    hadifarnoud · 2017-05-04 16:28:48 1
  • This causes computer to never power off or go into sleep mode. Disables sleep mode linux.


    2
    sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
    symgryph · 2017-04-28 19:49:36 0
  • Remaining battery time is displayed in minutes Show Sample Output


    0
    pmset -g batt | awk '/^ /{print $5}'
    zlemini · 2017-04-21 20:46:00 1

  • 1
    printf "%x\n" $(seq 0 255) | xargs -n1 -IH echo -ne \\xH > test.dat
    sesom42 · 2017-04-19 21:55:42 0

  • 1
    youtube-dl --list-formats <URL>; youtube-dl -f <STREAM_ID> -g <URL>
    alikhalil · 2017-04-19 06:43:39 0
  • This will grab the controlling tty regardless of what STDOUT and STDERR are doing.


    1
    exec 0</dev/tty
    pdxdoughnut · 2017-04-12 21:23:40 1
  • Tests to see if stdin (0) is NOT a terminal. Tests to see if stdout (1) IS a terminal. Copies stdout (opened for write) to stdin (open for read). Show Sample Output


    0
    [ ! -t 0 ] && [ -t 1 ] && exec 0<&1
    pdxdoughnut · 2017-04-12 00:10:27 0
  • Uses soxi instead of mplayer


    0
    soxi -D * | awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
    hufman · 2017-04-08 17:37:03 0

  • 0
    function cdb() { select dir in $(find -type d -name "$1" -not -path '*/\.*' -prune); do cd "${dir}" && break; done }
    odoepner · 2017-04-08 14:40:11 1
  • Use `security list-keychains` to find possible keychains, and `security dump-keychain` to look for certificates. `sudo security delete-certificate` without arguments shows options for removing: by common name or by SHA-1 hash. This is especially useful if a certificate locks up Keychain Access.app, which happens for certificates with many SANs in macOS 10.12. Found via: http://stackoverflow.com/a/16019443


    0
    sudo security delete-certificate -c 1000-sans.badssl.com
    lgarron · 2017-04-06 01:40:04 0
  • ‹ First  < 7 8 9 10 11 >  Last ›

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



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: