November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Changing temporary directory for sort – bash

I was sorting a very big file using Linux sort command and unfortunately the sort failed as there was not enough space on my /tmp directory.

$ sort -t “|” -k5 ka.log.32323112.out > ka.log.32323112.out
sort: /tmp/sort1928700448: write error: No space left on device

just to mention, sort by default uses /tmp for temporaries.

So, how you can tell sort to use some other directory for temporaries ?

From man pages of sort(1)

-T, –temporary-directory=DIR
use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories

$ sort -T /home/jadu/ -t “|” -k5 ka.log.32323112.out > ka.log.32323112.out

It worked 🙂

Another way would be : export env variable TMPDIR to some directory which have sufficient space.

e.g.

$ export TMPDIR=/path/to/other/directory
$ sort -t “|” -k5 ka.log.32323112.out > ka.log.32323112.out

It worked too 🙂

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>