Too small to keep, too big to throw back

Unix Insider |  Operating Systems

The solution to this dilemma is the Unix utility du. This little utility will
recurse through all subdirectories and display all the blocks being used. In the display below,
the directory being processed contains a perl
subdirectory, which in turn contains a src subdirectory. The src directory
contains files totaling 1540 blocks. The perl directory count includes all the
blocks in src plus the blocks used by files in perl. Finally, the top level
includes all blocks below it, plus blocks used by files used in the current
directory.

$ du
1540 ./perl/src
5648 ./perl
5654 .

The -a option displays the details for each file.

$ du -a
1500 ./perl/src/big.prl
40   ./perl/src/prog.prl
1540 ./perl/src
4108 ./perl/perl.tar
5648 ./perl
2    ./minutes.txt
4    ./note.txt
5654 .

The du command will cut through a lot of ls commands.
It provides size information as well as a reasonable display of the directory tree.

Switching things around with tr

The tr utility translates one set of characters into another.
The command tr abc def test.txt will process the records from test.txt and will translate the letter a to d, the letter b to e and the letter c to f. At first glance this doesn't seem very useful, unless you want to
practice amateur cryptography, but tr has additional options that make it much
more powerful. Two examples should give you a feel for the command.

The characters to be translated can be expressed as a range. In the
command below, a directory is output through tr, which
translates a to A, b to B and so on -- converting everything from lowercase to uppercase.

$ ls -ls|tr [a-z] [A-Z]
TOTAL 6
   2 -RW-R--R--   1 MJB     GROUP        3 FEB 04 23:31 MINUTES.TXT
   4 -RW-R--R--   1 MJB     GROUP     1201 FEB 04 23:25 NOTE.TXT
   2 DRWXR-XRX    2 MJB     GROUP      128 JAN 29 18:53 PERL

Using tr in the real world

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Operating SystemsWhite Papers & Webcasts

See more White Papers | Webcasts

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness