All commands (13,399)

  • 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


    0
    ./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 2
  • 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
    tcpdump -nnvvXSs 1514 -i <device> <filters>
    25killer · 2018-09-09 10:37:19 0

  • 1
    comm -12 <(sort -u File1) <(sort -u File2)
    guillaume1306 · 2018-09-07 11:36:15 0
  • If you want to code without a IDE, using java may be painful to discover correct full class names to import. This script google it with javadoc word, then with some luck we got the javadoc as first item. next it curl the target javadoc and extract full name from it. Can by customized to extract other javadoc infos. Pre-reqs: bash, google-chrome, html2text and core-utils Show Sample Output


    1
    getJavaFullClassName SpringComponent
    glaudiston · 2018-09-06 18:22:02 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


    2
    sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python2.7
    emphazer · 2018-09-04 17:30:47 0
  • Don't want to log out but you do want to get rid of a stored .zip file password in Windows? This will do that.


    0
    FOR /f "tokens=2-3 delims==" %G IN ('cmdkey /list ^| find ".zip"') DO cmdkey /delete:"%G=%H"
    ayaksich · 2018-09-04 16:33:53 0

  • -1
    cal -n 2 8 2018
    actionless · 2018-09-04 13:31:03 0

  • 2
    pstree -plants $(pidof -s firefox)
    cbrchrt · 2018-09-04 12:22:57 0

  • 3
    cat databases.txt | while read db; do docker exec $container_name bash -c "mysqldump -uroot -p\$MYSQL_ROOT_PASSWORD ${db}" | gzip -9 > $HOME/backups/${db}_`date +%Y%m%d_%H%M%S`.sql.gz; done
    batandwa · 2018-09-02 15:23:32 0

  • 0
    mkdir -p src && chmod 777 src && docker run -v $(pwd)/src:/var/www/html wordpress:cli core download && chmod 755 src
    nabil_kadimi · 2018-09-01 18:06:42 0
  • https://wuseman.github.io/wcloner/


    0
    lynx -dump -nonumbers https://github.com/USER?tab=repositories|grep '/USER/'|cut -d'/' -f1,2,3,4,5|uniq|xargs -L1 git clone
    wuziduzi · 2018-09-01 06:03:23 0
  • Good old bracket expansion :-) For large numbers of files, "rename" will spare you the for-loop, or the find/exec...


    3
    mv {,prefix_}yourfile.txt
    joedhon · 2018-08-30 18:18:50 0
  • Find and Convert all libre office files to PDF without libreoffice GUI Show Sample Output


    0
    find /home/foo/Documents/ -type f -iname "*.odt" -exec libreoffice --headless --convert-to pdf '{}' \;
    switch · 2018-08-29 21:44:26 0
  • Displays last month, current month, and next month side by side. Show Sample Output


    3
    cal -3
    arglborps · 2018-08-28 20:37:33 0

  • -1
    cal -A 1 8 2018
    jscolaire · 2018-08-28 20:23:03 0
  • Here is another way to show the path, one directory per line. The command `tr` translates the colon into the new line, taking input from the $PATH variable Show Sample Output


    2
    tr : \\n <<<$PATH
    haivu · 2018-08-28 20:01:04 0
  • The Linux's `cal` command is nice, but there are times when I need to see two months side by side and this command will do it. Show Sample Output


    0
    paste <(cal 8 2018) <(cal 9 2018)
    haivu · 2018-08-28 19:54:05 0
  • Find recursively all files in ~/Notes with the extension '.md' and pipe that via xargs to rename command, which will replace every '.md' to '.txt' in this example (existing files will not be overwritten).


    2
    find ~/Notes -type f -iname '*.md' -print0 | xargs -0 rename --no-overwrite .md .txt {}
    Sommerfalke · 2018-08-24 09:41:51 1
  • HDMI-1 is the interface in the example, which can be obtained just by typing xrandr and surfing through the output. There are a hell lot of configurations that can be done but I prefer auto because it works in most cases. Lifesaver Show Sample Output


    1
    xrandr --output < interface-name > --auto
    praton · 2018-08-23 17:51:20 0
  • Pluralize a word, aka change from single to multiple; text formatting. echo hamburgler | pluralize Show Sample Output


    0
    pluralize() { if [ -n "$1" ]; then echo ${1}s else while read line; do pluralize $line done fi }
    cryptology_codes · 2018-08-21 22:49:21 0
  •  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

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" }

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Remove spaces from filenames - through a whole directory tree.
An example of zsh glob qualifiers.

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"

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Resume aborted scp file transfers
Put it into your sh startup script (I use alias scpresume='rsync --partial --progress --rsh=ssh' in bash). When a file transfer via scp has aborted, just use scpresume instead of scp and rsync will copy only the parts of the file that haven't yet been transmitted.

Recursive grep of all c++ source under the current directory
I like this better than some of the alternatives using -exec, because if I want to change the string, it's right there at the end of the command line. That means less editing effort and more time to drink coffee.

Generate a random password 30 characters long

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Find last reboot time
Specific to OSX.


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: