3

When executing

watch tree .

I get output as follows

Every 2.0s: tree .                                   macbook.local: Fri Dec 20 16:23:33 2019

.
    hello.txt
    hi.txt
    hmm.c
    subdir
        hello.txt

1 directory, 4 files

I want it to look like regular tree command output. Like below:

.
├── hello.txt
├── hi.txt
├── hmm.c
└── subdir
    └── hello.txt

1 directory, 4 files

I know that, I can use

while; do; clear; tree .; sleep 2; done

But I want to achieve the same thing with watch command

2 Answers 2

1

This is expected behavior as all non-printable characters are stripped from the output of watch. And this is mentioned in man page of watch.

You can try to exec command on this way:

 watch "tree|cat -v"
1

Setting LC_CTYPE=C will probably make tree use plain ASCII alternatives. With watch the command may be:

watch 'LC_CTYPE=C tree .'
# or (not strictly equivalent)
LC_CTYPE=C watch tree .

Notes:

  • The setting will affect the way non-ASCII characters in filenames are displayed.
  • You may encounter a generic hint of LC_ALL=C. This variable overrides LC_CTYPE, but also LC_COLLATE and other LC_* variables. LC_COLLATE affects sorting in tree.

In my Debian I can use --charset=C to force ASCII drawings without affecting characters in filenames (so this is even better than the approach with LC_CTYPE):

watch tree --charset=C .

Although in Debian even watch tree . works well for me. On the other hand watch "tree|cat -v" from this other answer generates virtually unreadable output. Apparently your setup is different (macbook.local – macOS?). My answer is to provide hints that may be useful for users with yet another setup.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .