Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get ASCII characters similar to output of the linux command 'tree'?

Tags:

bash

tree

Is there a way to print the ASCII charachter '├── ' and '└──' using a bash or perl script? I want it be exactly like the output of 'tree'.

[root@localhost www]# tree -L 1
.
├── cgi-bin
├── error
├── html
└── icons
like image 804
Tom Iv Avatar asked Feb 21 '14 03:02

Tom Iv


People also ask

How do I type ASCII characters in Linux?

When you type Alt + numbers in Windows, you are actually typing Alt + character's ASCII code. To achieve the same in Ubuntu, you must type Ctrl + Shift + U , and then type character in Unicode hexadecimal value.

What is the output of tree command?

Upon completion of listing all files and directories found, tree returns the total number of files and directories listed. There are options to change the characters used in the output, and to use color output. The command is available in MS-DOS versions 3.2 and later and IBM PC DOS releases 2 and later.

Which character is used to represent a range of values in Linux?

A backslash followed by any other character maps to that character. Character range. For non-octal range endpoints represents the range of characters between the range endpoints, inclusive and in ascending order, as defined by the collation sequence.


2 Answers

They look to be a part of the extended ascii codes. You can see them here http://www.asciitable.com/

Also available at the Unicode table here: http://unicode-table.com/en/sections/box-drawing/

enter image description here

I believe 192, 195 and 196 are the ones you are after. In Unicode 2501, 2514 and 2523.

EDIT

Found a related stack question here, which recommends printing in Unicode.

What you want is to be able to print unicode, and the answer is in perldoc perluniintro. You can use \x{nnnn} where n is the hex identifier, or you can do \N{...} with the name:

perl -E 'say "\x{2514}"; use charnames; say "\N{BOX DRAWINGS LIGHT UP AND RIGHT}"'
like image 157
Rots Avatar answered Nov 03 '22 00:11

Rots


echo -e "\0342\0224\0224\0342\0224\0200\0342\0224\0200 \033[01"
like image 45
liyaoshi Avatar answered Nov 03 '22 01:11

liyaoshi