Commands by hugme (2)

  • This will strip out the relivent disk information from kvm. I'm using it to find disks on a SAN which are no longer in use. Show Sample Output

    while read X ; do printf "$X --"; virsh dumpxml $X | egrep "source dev|source file"; done< <(virsh list | awk '$1 ~ /^[1-9]/ { print $2 }')
    hugme · 2013-07-29 17:32:59 261
  • The find command can do this on it's own. This is a shorter faster version, it also includes more advanced regex (it will find .Jpg etc). Find doesn't need a pipe, you can run it directly from the command.

    find . -name '*.[Jj][Pp][Gg]' -exec mogrify -resize 1024">" -quality 40 {} \;
    hugme · 2013-06-21 13:27:25 0

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

Execute MySQL query send results from stdout to CSV
You can, of course, tell MySQL to output results to a file and dictate how to terminate lines, etc. But sometimes you don't have access to the file system MySQL is running on, complicating outputting your results to a CSV, necessitating either annoying hacks or this simple command :D

check open ports without netstat or lsof

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"

List just the executable files (or directories) in current directory
Does an 'ls' on just the files and directories in the current directory with an execute bit turned on. This version will list directories. Just tack on "-type f" to the start of the find to omit listing directories and list only files.

Recursively change permissions on files, leave directories alone.

Show a prettified list of nearby wireless APs

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"

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

move contents of the current directory to the parent directory, then remove current directory.
I think this is less resource consuming than the previous examples

Show interface/ip using awk
Interfaces like lo can be omitted from the beginning, there are probably better ways of doing this, i'm a noob at awk.

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: