All commands (26)

  • List out all the names from the zip file and pass it to xargs utility to delete each one of them

    unzip -Z -1 <> | xargs -I{} rm -v {}
    praton · 2018-08-19 20:49:25 0
  • Displays last month, current month, and next month side by side. Show Sample Output

    cal -3
    arglborps · 2018-08-28 20:37:33 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 1
  • 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).

    find ~/Notes -type f -iname '*.md' -print0 | xargs -0 rename --no-overwrite .md .txt {}
    Sommerfalke · 2018-08-24 09:41:51 1
  • 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

    tr : \\n <<<$PATH
    haivu · 2018-08-28 20:01:04 0
  • Good old bracket expansion :-) For large numbers of files, "rename" will spare you the for-loop, or the find/exec...

    mv {,prefix_}yourfile.txt
    joedhon · 2018-08-30 18:18:50 0

  • 2
    pstree -plants $(pidof -s firefox)
    cbrchrt · 2018-09-04 12:22:57 1
  • 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

    sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python2.7
    emphazer · 2018-09-04 17:30:47 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

    xrandr --output < interface-name > --auto
    praton · 2018-08-23 17:51:20 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

    time usleep 100000
    emphazer · 2018-09-06 10:28:26 1
  • 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

    getJavaFullClassName SpringComponent
    glaudiston · 2018-09-06 18:22:02 1

  • 1
    comm -12 <(sort -u File1) <(sort -u File2)
    guillaume1306 · 2018-09-07 11:36:15 1

  • 1
    tcpdump -nnvvXSs 1514 -i <device> <filters>
    25killer · 2018-09-09 10:37:19 1

  • 1
    rpm -qa --last | head -n 16
    sparsile · 2018-09-13 02:55:51 1
  • Pluralize a word, aka change from single to multiple; text formatting. echo hamburgler | pluralize Show Sample Output

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

    paste <(cal 8 2018) <(cal 9 2018)
    haivu · 2018-08-28 19:54:05 0
  • Find and Convert all libre office files to PDF without libreoffice GUI Show Sample Output

    find /home/foo/Documents/ -type f -iname "*.odt" -exec libreoffice --headless --convert-to pdf '{}' \;
    switch · 2018-08-29 21:44:26 1

    lynx -dump -nonumbers|grep '/USER/'|cut -d'/' -f1,2,3,4,5|uniq|xargs -L1 git clone
    wuziduzi · 2018-09-01 06:03:23 1

  • 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 1
  • 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.

    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
  • Display a list of the 16 most recently installed RPM packages with newest first. Show Sample Output

    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 2
  • Unlock your VMS to avoid problems after some failed tasks ended. Show Sample Output

    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 1
  • 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 1
  • 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 2

  • -1
    cal -A 1 8 2018
    jscolaire · 2018-08-28 20:23:03 0
  •  1 2 > 

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

find external links in all html files in a directory list
Just a handy way to get all the unique links from inside all the html files inside a directory. Can be handy on scripts etc.

Exclude inserting a table from a sql import
Starting with a large MySQL dump file (*.sql) remove any lines that have inserts for the specified table. Sometimes one or two tables are very large and uneeded, eg. log tables. To exclude multiple tables you can get fancy with sed, or just run the command again on subsequently generated files.

Copy a directory recursively without data/files

Safely remove old unused kernels in Ubuntu/Debian
Removes piling kernels from /boot, save the current one. This command DOES NOT remove the 'linux-image-generic' package, so you'll continue getting kernel updates

Like top, but for files

Recover username and password for Technicolor TC7200 admin page (vulnerability)
The router Technicolor TC7200 has an exploit where the file is open for unauthenticated access. Even though it is binary, the 2 last strings are the username and password for the pages for router management. It can be read using the 'strings' command, 'hexdump -C' or a hexadecimal editor. (default user/password = admin/admin) Reveals more configuration, including SSID name and Key for the wifi network: $wget -q -O - Hexadecimal dump of the file: $wget -q -O - | hexdump -C

Download all PDFs from an authenificated website
Replace *** with the appropiate values

for x in `psql -e\l | awk '{print $1}'| egrep -v "(^List|^Name|\-\-\-\-\-|^\()"`; do pg_dump -C $x | gzip > /backups/$x-back.gz
Ran as the postgres user, dumps each database individually. It dumps with the create statements as well, so you can just 'zcat $x-nightly.dmp.gz | psql' to reimport/recreate a database from a backup.

Do a command but skip recording it in the bash command history
Note the extra space before the command (I had to put it as an underscore since the website eats up preceding spaces). That's all it takes. Now if you check your history with "$ history", it wont show up.

Extract tarball from internet without local saving
Use `tar xj` for bzip2 archives.

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: