All commands (13,445)

  • Finder compresses to ZIP but always includes extraneous metadata files (__MACOSX and .DS_Store) files and folders that may confuse other programs. One alternative is creating them and then editing the ZIP. This can work standalone or in an automator script accepting multiple selections (files or folders) and creating one zip per argument/selected file without that metada.

    echo "$@" for f in "$@"; do FILENAME=${f##*/};FILEPATH=${f%/*}; cd "${FILEPATH}"; zip -r "${f}".zip "${FILENAME}" -x "*.DS_Store" -x "__MACOSX"; done; afplay /System/Library/Sounds/Sosumi.aiff
    eduo · 2018-10-20 12:27:50 0
  • Just use '-' to use STDIN as an additional input to 'cat'

    echo "New first line" | cat - file.txt > newfile.txt; mv newfile.txt file.txt
    gpenguin · 2018-10-18 18:54:24 0
  • Yet another way to add a line at the top a of text file with the help of the tac command (reverse cat).

    tac myfile.txt > /tmp/temp; echo "my line" >> /tmp/temp; tac /tmp/temp > myfile.txt
    thargos · 2018-10-17 16:16:49 1

  • 3
    curl | 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

    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:

    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).

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

  • 0
    while true; do sleep .15; head /dev/urandom | tr -dc A-Za-z0-9; done
    allyman17 · 2018-10-10 18:57:34 1
  • 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

    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 (edited)

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

  • 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

    nslookup -q=TXT | 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 | awk -F'"' '/ipv6_prefix/ {print $4}'
    emphazer · 2018-10-05 13:01:03 1

  • 1
    curl -s | awk -F'"' '/ip_prefix/ {print $4}'
    emphazer · 2018-10-05 12:59:33 0

  • 2
    nslookup -q=TXT | 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 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
  • 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

    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 Show Sample Output

    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

    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.

    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

    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'

    for f in *;do echo $f;done
    famaral · 2018-09-21 14:27:23 2
  • wget && tar -xzf 1.15.3.tar.gz && cd nginx-1.15.3 Show Sample Output

    ./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 ;-) Show Sample Output

    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
  •  1 2 3 >  Last ›

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

Archive all folders in a directory into their own tar.bz2 file
Remove the "echo" to actually archive. Many similar commands are found on commandlinefu but I end up needing this very specific one from time to time. To extract any of them, use the standard tar.bz2 extract command: $tar xvjf folder1.tar.bz2

Convert mkv to SVCD/DivX
ffmpeg supports mkv

Change pidgin status
Changes pidgin status using its dbus interface. The status code can be obtained using command #4543.

Delete all files in a folder that don't match a certain file extension
Deletes all files in a folder that are NOT *.foo, *.bar or *.baz files. Edit the pattern inside the brackets as you like.

Get size of terminal

Get a facebook likes quantity from CLI
Replace the with your URL, for example and it will show likes number

Use a var with more text only if it exists
See "Parameter Expansion" in the bash manpage. They refer to this as "Use Alternate Value", but we're including the var in the at alternative.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

Show every subdirectory (zsh)

Bash logger

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: