1

I have XYZ=/opt/Ind and certain directories under /opt/Ind

I sorted the directories by : ls -t $XYZ Then I need to get only the size of the first folder. I tried

du -sk $(ls -t $XYZ/TAL/ | head -n 1)

It gives me this error

du: cannot access `\033[0m\033[01;34m20160525_033732\033[0m': No such file or directory

Will be glad for the help.

Mohit Arora
  • 337
  • 5
  • 19
Aishwarya
  • 71
  • 2
  • 10

2 Answers2

2

The problem here is that you are not using the normal ls but an alias, so that it provides you some coloured output. This way, instead of a normal name 20160525_033732 you get it with the blue colour.

$ echo -e "\033[0m\033[01;34m20160525_033732\033[0m"
20160525_033732

Just use \ls to use the original ls without any alias.

du -sk "$(\ls -t $XYZ/TAL/ | head -n 1)"
#         ^

See what the alias is with:

type ls

It will probably return something like:

ls is aliased to `ls --color=always'
Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598
0

add --color=never to the ls so it won't colorize the output:

du -sk $(ls --color=never -t $XYZ/TAL/ | head -n 1)
Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26