All commands (13,439)


  • 1
    curl https://www.domain.com/ | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*.*(doc|docx|xls|xlsx|ppt|pptx|pdf)" | sort | uniq > list.txt | wget list.txt
    Repie · 2018-10-16 08:54:45 0
  • Dumping man pages to text typically retains certain formatting such as foo^H^H^H___ for underscoring, and reverse-line feeds (not sure why). 'col -bx' removes these. Show Sample Output


    0
    man2txt() { man "$@" | col -bx ;}
    bartonski · 2018-10-14 01:38:04 0
  • 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: https://github.com/stedolan/jq/issues/1110


    2
    diff <(jq . -M -S < old.json) <(jq . -M -S < new.json)
    malathion · 2018-10-11 20:59:48 0
  • The previous alternative dont work (the cd command was missing).


    2
    mkdir [[folder]] && cd $_
    mlinoba · 2018-10-11 16:40:53 0

  • 0
    while true; do sleep .15; head /dev/urandom | tr -dc A-Za-z0-9; done
    allyman17 · 2018-10-10 18:57:34 0
  • This will allow you to ensure you don't get nagged by updates and also protects you from watering hole attacks! Please be sure to make sure your plugins don't have any security issues! Backups are manifext.jason.bak credit @Jay https://chat.counterpoint.info


    0
    find / -iname "manifest.json" -exec sed 's/\"update_url\": \"http/\"update_url\": \"hxxp/g' -i.bak '{}' \;
    operat0r · 2018-10-09 19:50:31 0
  • Create and access directory


    0
    mkdir [folder-name] && $_
    ehmuidifici · 2018-10-09 18:48:16 2

  • 0
    tp=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') && tp=$((tp==0)) && synclient TouchpadOff=$tp
    jny · 2018-10-09 07:42:32 0
  • a bit shorter, parenthesis not needed but added for clarity Show Sample Output


    1
    nslookup -q=TXT _netblocks.google.com | grep -Eo 'ip4:([0-9\.\/]+)' | cut -d: -f2
    jseppe · 2018-10-05 18:19:15 2

  • 0
    knife role create role-name --description "this is a role that does cool stuff"
    niko47 · 2018-10-05 16:00:41 0

  • 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
  • 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 https://stedolan.github.io/jq/download/ This alternative to the original avoids the useless use of cat Show Sample Output


    0
    jq < file.json
    malathion · 2018-10-03 18:46:46 0
  • Use this function with bash version 4+ to convert arbitrary hexadecimal sequences to binary. If you don't have bash 4+ then modify the lowercase to uppercase demangling statement s=${@^^} to set s equal to the uppercase hex input or the bc command throws an input parser error. Show Sample Output


    0
    hex2bin () { s=${@^^}; for i in $(seq 0 1 $((${#s}-1))); do printf "%04s" `printf "ibase=16; obase=2; ${s:$i:1};\n" | bc` ; done; printf "\n"; }
    RiskNerd · 2018-10-02 22:02:33 0
  • the `jq` tool can also be used do validate json files and pretty print output `cat file.json | jq` available on several platforms, including newer debian-based systems via `#sudo apt install jq`, mac via `brew install jq`, and from source https://stedolan.github.io/jq/download/ Show Sample Output


    2
    cat file.json | jq
    daemeon · 2018-10-01 23:05:27 0
  • -X Send the specified command to a running screen session. -S Option to specify the screen session if you have several screen sessions running. screen -ls for listing current screens and its sessionname


    1
    screen -X -S [sessionname] quit
    FanMix · 2018-10-01 14:30:01 0
  • Also ignoring "sshd" server is necessary since you should not kill ssh server processes.


    1
    ps aux | grep ssh | grep -v grep | grep -v sshd | awk {'print $2'} | xargs -r kill -9
    user2390 · 2018-10-01 04:49:09 2
  • 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
  • use '*' instead of 'ls'


    -2
    for f in *;do echo $f;done
    famaral · 2018-09-21 14:27:23 1
  • 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
  • Unlock your VMS to avoid problems after some failed tasks ended. Show Sample Output


    0
    for i in $(qm list | awk '{ print $1 }' | grep -v VMID); do echo "Unlocking:" $i; qm unlock $i; echo "Unlocked"; done
    arkalira · 2018-09-13 08:35:12 0

  • 1
    rpm -qa --last | head -n 16
    sparsile · 2018-09-13 02:55:51 0
  • Display a list of the 16 most recently installed RPM packages with newest first. Show Sample Output


    0
    rpm -qa --queryformat '%{INSTALLTIME} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16 | awk '{printf("%3d %s %s\n", $1,strftime("%c",$2),$3)}'
    mpb · 2018-09-12 17:47:26 1
  •  1 2 3 >  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


Check These Out

GZip all files in a directory separately

Prefix command output with duration for each line
Prefixes each output line with time between it and the previous one.

Capture video of a linux desktop

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Create a listing of all possible permissions and their octal representation.

list files by testing the ownership
Alternative to mnikhil's ls/awk solution

Press a key automatically
Press a key automatically via xvkbd.

list files recursively by size

Print the contents of $VARIABLE, six words at a time
Print out the contents of $VARIABLE, six words per line, ignoring any single or double quotes in the text. Useful when $VARIABLE contains a sentence that changes periodically, and may or may not contain quoted text.

du with colored bar graph
i'm using gawk, you may get varying mileage with other varieties. You might want to change the / after du to say, /home/ or /var or something, otherwise this command might take quite some time to complete. Sorry it's so obsfucated, I had to turn a script into a one-liner under 255 characters for commandlinefu. Note: the bar ratio is relative, so the highest ratio of the total disk, "anchors" the rest of the graph. EDIT: the math was slightly wrong, fixed it. Also, made it compliant with older versions of df.


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: