Blog Post

Did Not Know That - Redirecting CMD to the Clipboard

,

One of the items I frequently deal with as a Production DBA is drive alarms.  I have written previously about looking for space inside database files, but what if your problem is non-database files?

The goto tool in Windows for me has always been du (Disk Usage) created by Mark Russinovich (blog/@markrussinovich) as part of his Sysinternals project.

du is a very straightforward command tool the traverses the directory structure below the current path and returns the folder sizes of the given folders.  For example, the output for C:\Windows on a given server looks like this:

Fine to look at, but a bit onerous to manipulate - after all this is just a screenshot.
The first way I knew to deal with this was via the >> redirect:

du -l 1 >> Output4.txt

This would create a text file at the path being searched containing the output from the command, which can then be copy-pasted out to another site:
To clean it up for manipulation (in Excel for example), you can add a parameter to du to turn the output to comma- or tab-delimited format (either -c or -ct):

du -ct -l 1 >> output5.txt

--
The new trick I learned is that you can use a pipe - similar to Powershell - to redirect the output of the du command to another command, and that there is a command to send the output of a command directly to the clipboard (unbelievably enough, called "clip"):

du -ct -l 1 | clip

http://ru.memegenerator.net/instance/57285847/mind-blown-cat-mind-blown
I found this trick in a helpful blog post here.
Once it's in the clipboard, it can be pasted straight into Excel where it can be easily sorted, for example to find the largest directories:
Pretty cool, huh?
This same process of piping into clip works with a wide variety of command line commands, but this is the one for which I see the most immediate value.
--
Hope this helps!

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating