As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label utility. Show all posts

dus is meant to have better output than GNU du -s, which simply summarized the current directorys size (recursively), and bar chart for visualization of sizes.

https://lh3.googleusercontent.com/-fGK67jXeexo/VnSkafYPtXI/AAAAAAAAIpY/4ECerkOqR-8/s800-Ic42/2015-12-19--08%25253A19%25253A28.png

Watch this video for more usages

It has quite a few of options to use, watch this video for examples of some of them:

-0 Use null character (0) as target separator for stdin.
-c <count> Number of items to printout of result head.
--color Colorized output for easier interpretation.
-d Dont enter directory. Only used if a single directory is defined as target.
-h Print human readable sizes (e.g., 1K 234M 5G).
-i Inverted/reverted order of listed result.
-n Enable natural sort order if sort order is a string representation.
-s <...> Sort by property; size, name, atime, mtime, ctime.
-t <ms> File/directory parse timeout given in milliseconds.

You can also pipe in list of directories or files to dus, it reads from standard input as well and gives you the output you want.

dus was created by Rikard Johansson on 2015-10-16, written in C++14 under GPLv3, currently v0.0.6 (2015-12-18).

I am sure many of you know of Ncdu (NCurses Disk Usage, video), but I found tdu (GitHub, video) is a simpler option, and frankly, I like it better.

It uses the output of du, parses and renders out a tree or outline as seen below.

https://lh3.googleusercontent.com/-pNNeSjnDTao/Vj09nEt9ZRI/AAAAAAAAIKQ/Uc7Qor-YbKI/s800-Ic42/2015-11-07--07%25253A53%25253A02.png

You can sort by size, name, number of descendants, or unordered as from du, toggle on the numbers of descendants, switch to ASCII line-drawing as seen on the right of the screenshot above.

Its not fancy, thats clear, but the tree or the outline representation gives you a better sense of how space is used. Only if it can has bar charts to display the size and the amount of descendants, tdu would be the perfect disk usage visualizer in my opinion.

tdu was created in 2004 by Darren Stuart Embry, written in C under the GPLv2, last verison 0.0.20121127 was nearly three years ago. There is also a Perl version.

This is a note for some use cases of xsnap, which I never can remember how to use them, exactly, even after five years.

1   Timestamp

This is the format I like to use:

-file "$HOME/tmp/ss/$(date +'%Y-%m-%d--%H:%M:%S.png')"

2   -region

Option value type GEOMETRY format: WxH+X+Y, for example:

xsnap -region 1280x720+2+20 -file screenshot.png

xsnap grabs 1280 by 720 pixels area at screen position 2, 20.

3   Full-screen

Using xwininfo to determine the screen size:

xsnap -file screenshot.png -region "$(xwininfo -root | sed '/\(Width\|Height\)/ {s/[ :a-z-]//gi;p} ; d' | tr '\n' ' ' | cut -d ' ' -f1-2 | tr ' ' 'x')+0+0"

The breakdown version:

xsnap -file screenshot.png -region "$(xwininfo -root |
  sed '/\(Width\|Height\)/ {s/[ :a-z-]//gi;p} ; d' |
  tr '\n' ' ' |
  cut -d ' ' -f1-2 |
  tr ' ' 'x')+0+0"

Have you ever read cds manpage? If you havent, then you should if you dont even know what cd or cd - does. The manpage is of POSIX Programmers Manual, so the content is not only for the Bash, but for every POSIX-compliant shell.

1   cd brings you(r) home

It means literally, like, seriously bringing you home or bringing your home to you.

/path/somewhere $ cd
~ $

I believe many people have discovered this on their own like me. You just happen to run cd without giving any argument, then you wowd for finding out this quick way to get back to home.

I remember once I was talking to someone, who didnt even know about this. Its more amazed for me than for him, I wondered how on Earth this guy had been doing in order to get back to home.

2   cd - for last directory

I dont use this argument - often, but when I need it, itd save a lot of typing time especially you keep switching between two directory.

~ $ cd /path/to/somewhere/deep
/path/to/somewhere/deep $ # do somegthing
/path/to/somewhere/deep $ cd /path/to/other/place/way/way/deep
/path/to/other/place/way/way/deep $ # do something
/path/to/other/place/way/way/deep $ cd -
/path/to/somewhere/deep $ # now we are back
/path/to/somewhere/deep $ cd -
/path/to/other/place/way/way/deep $ # we are back to the other

Note

If you actually have a - directory, use cd ./- to get into it.

3   CDPATH is directory search path

Before I read the manpage, I had never thought of it, even I seemed to have heard of it or seen it. Its like PATH, but only for searching directories when using cd.

~ $ mkdir foobar
~ $ CDPATH=$HOME
~ $ cd /
/ $ cd foobar
/home/login/foobar $ # bang!

You can enter the ~/foobar from anywhere, just by typing cd foobar. Its like you can run foobar from anywhere if its executable and its searchable via PATH.

It can also be auto-completed via bash-completion. On Gentoo, run eselect bashcomp enable base to enable it.

Although I find this could be useful, but I prefer more specific way to change directory, like my own g script for quick directory switch.

4   cd !$ comes in handy

This relies on Bashs History Expansion, so this is not for every shell. But its very useful when the last argument is a directory from previous command, and you need to get into for further actions. !$ is your best friend.

~ $ mkdir long/long/directory
~ $ cd !$
~/long/long/directory $

This is probably my own oldest script and still being used besides .bashrc.

This g script was born at 2007-12-26T03:01:29+0800. (Yep, I am a timestamping nuts) Four years ago, I wrote a post about how to use it, but I doubt anyone has ever wanted to use it.

Its a simple script for quickly switching working directory. You can switch with index or keyword, it also supports Bash completion. There are a lot of script like this around, but I am happy with mine, even it had some issues.

After these years, I finally updated it to adding keyword support which I always wanted. I used to memorize the indexes of those directories, it wasnt a big issue for me. Besides that, a Makefile was written for easy installation.

Other than fixing some syntax and weird scripting (still read weird), its basically the same as you read in that old blog post.

If you havent tried directory switcher, why not try mine and create some issues for me to fix? (I am sure there are plenty to fix)

In my Fluxbox keys, I have three keys to take different kind of screenshots using scrot, whole screen, window, and window with window manager decoration aka window border. If I only need a portion of screen, I would grab the whole screen, then use GIMP to crop it; or I will use GIMP to grab screenshot.

Recently, I started to looking for a note taking program and I chose KeepNote. It has a hotkey Ctrl+Insert to insert a screenshot from an external command, I think its very interesting and useful function to me. The default command is ImageMagicks import. For some unknown reason, it always gave me an all black screenshot if I select normal windows area, but Fluxboxs toolbar can be grabbed correctly and I could have correct screenshot if I run import from a shell.

Note

Im no longer using KeepNote since 2010-11-15, now Vim Notes, instead. (2015-08-19T22:48:20Z)

Of course, I could always make a screenshot, then import it into KeepNote, but that seems to take too much efforts.

So, I found a program called xsnap, I am using version 1.5.6. It supports window (mouse middle button click) and region grab (drag a region). It doesnt accept a filename by default, a simple shell script for KeepNote to do the job:

xsnap -png -file "$1"

Note

my use cases. (2015-08-19T22:42:24Z)

I also specify the format, though PNG is the default format.

I think its also the time to let scrot get retired in my Fluxbox keys:

None Print :Exec xsnap -file "$HOME/tmp/ss/$(date +'%Y-%m-%d--%H:%M:%S.png')"

Note

Ive switched to dwm since 2011-07-06. (2015-08-19T22:43:56Z)

The old ones using scrot:

None Print Print :Exec scrot '%Y-%m-%d--%H:%M:%S_$wx$h.png' -e 'mv $f ~/tmp/ss'
None Print S :Exec scrot -s -d 1 '%Y-%m-%d--%H:%M:%S_$wx$h.png' -e 'mv $f ~/tmp/ss'
None Print B :Exec scrot -s -b -d 1 '%Y-%m-%d--%H:%M:%S_$wx$h.png' -e 'mv $f ~/tmp/ss'