Commands by batandwa (6)


  • 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 574
  • Creates a git repository in a predefined location. Show Sample Output


    -3
    git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
    batandwa · 2013-05-09 21:44:24 21
  • Watches for file modifications in the current directory and tails the file.


    -4
    watch 'ls -tr1 | tail -n1 | xargs tail'
    batandwa · 2013-05-09 11:37:59 11
  • Monitors the current directory for changes to HAML files and converts them to HTML. Show Sample Output


    0
    while true; do filechanged=$(inotifywait -e close_write,moved_to --format "%w%f" .); haml $filechanged -q --no-escape-attrs > ${filechanged/.haml/.html}; done
    batandwa · 2013-05-01 21:15:26 9

  • 0
    git diff --name-only --diff-filter=AMXTCR HEAD~2 HEAD | xargs -l -I{} cp --parents --verbose "{}" target_dir
    batandwa · 2013-02-11 08:12:40 5

  • 0
    ngrep host 192.168.1.6 -O $(date +%Y%m%d_%H%M%S).pcap > $(date +%Y%m%d_%H%M%S).txt
    batandwa · 2012-10-03 13:09:19 6

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

Make the Mac OS X Dock 2D once more (10.5 and above only)
Mac OS X 10.5 (Leopard) introduced a new, 3D, reflective Dock. For those of us who prefer the Dock to be a little less distracting, this command is the answer. The Dock will be rendered in the same style as when pinned to the left- or right-hand side of the screen. Replace YES with NO to restore the 3D Dock.

Tail a log-file over the network
Netcat is used to serve a log-file over a network on port 1234. Point a browser to the specified server/port combo to view log-file updates in real-time.

Block an IP address from connecting to a server
This appends (-A) a new rule to the INPUT chain, which specifies to drop all packets from a source (-s) IP address.

Forwards connections to your port 2000 to the port 22 of a remote host via ssh tunnel

List processes playing sound
When trying to play a sound you may sometimes get an error saying that your sound card is already used, but not by what process. This will list all processes playing sound, useful to kill processes that you no longer need but that keep using your sound card.

Display screen window number in prompt
Add this to your $HOME/.bashrc file. It will only set this prompt if it is running inside screen ($WINDOW var is set) Looks like this... $ ion@atomos:~[2]$

randomize hostname and mac address, force dhcp renew. (for anonymous networking)
this string of commands will release your dhcp address, change your mac address, generate a new random hostname and then get a new dhcp lease.

Restart Xen XAPI
Restarts the XAPI service on the host, mostly used by Xen Center. It does not affect any running VMs, just the Xen client tools that may be connected. On my list as XAPI frustratingly keeps running out of memory and getting killed off.

Get length of current playlist in xmms2

FizzBuzz in one line of Bash
The (in)famous "FizzBuzz" programming challenge, answered in a single line of Bash code. The "|column" part at the end merely formats the output a bit, so if "column" is not installed on your machine you can simply omit that part. Without "|column", the solution only uses 75 characters. The version below is expanded to multiple lines, with comments added. for i in {1..100} # Use i to loop from "1" to "100", inclusive. do ((i % 3)) && # If i is not divisible by 3... x= || # ...blank out x (yes, "x= " does that). Otherwise,... x=Fizz # ...set x to the string "Fizz". ((i % 5)) || # If i is not divisible by 5, skip (there's no "&&")... x+=Buzz # ...Otherwise, append (not set) the string "Buzz" to x. echo ${x:-$i} # Print x unless it is blanked out. Otherwise, print i. done | column # Wrap output into columns (not part of the test).


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: