LoginSignup
3
2

More than 1 year has passed since last update.

treeで罫線が文字化けした際の対処方法

Posted at

Linuxでtreeコマンドを使用した際に罫線が文字化けした場合の対処方法

環境

$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

事象

Teretermで接続し、引数無しで実行すると以下のようになる

$ tree
.
├─ buildscripts
│?? ├─ checkdeps.sh
│?? ├─ cicd-corpus
│?? │?? ├─ disk1
│?? │?? │?? └─ bucket
│?? │?? │??     └─ testobj
│?? │?? │??         └─ 2b4f7e41-df82-4a5e-a3c1-8df87f83332f
│?? │?? │??             └─ part.1
│?? │?? └ disk2
...省略

更にwindowsにコピーすると以下のようになる

.
tqq buildscripts
x?? tqq checkdeps.sh
x?? tqq cicd-corpus
x?? x?? tqq disk1
x?? x?? x?? mqq bucket
x?? x?? x??     mqq testobj
x?? x?? x??         mqq 2b4f7e41-df82-4a5e-a3c1-8df87f83332f
x?? x?? x??             mqq part.1
x?? x?? tqq disk2
...省略

対策(Teratermだけで表示する場合)

Teratermで確認するだけならtree -Aとする

$ tree -A
.
├─ buildscripts
│   ├─ checkdeps.sh
│   ├─ cicd-corpus
│   │   ├─ disk1
│   │   │   └─ bucket
│   │   │       └─ testobj
│   │   │           └─ 2b4f7e41-df82-4a5e-a3c1-8df87f83332f
│   │   │               └─ part.1
│   │   └ disk2
...省略

しかしwindowsにコピペすると化ける

.
tqq buildscripts
x   tqq checkdeps.sh
x   tqq cicd-corpus
x   x   tqq disk1
x   x   x   mqq bucket
x   x   x       mqq testobj
x   x   x           mqq 2b4f7e41-df82-4a5e-a3c1-8df87f83332f
x   x   x               mqq part.1
x   x   tqq disk2

対策2(Windowsにコピペしたい場合)

UTF-8だと化けるのでLANG=Cで実行することでコピペ化けなくなる

$ tree --charset=C
.
|-- buildscripts
|   |-- checkdeps.sh
|   |-- cicd-corpus
|   |   |-- disk1
|   |   |   `-- bucket
|   |   |       `-- testobj
|   |   |           `-- 2b4f7e41-df82-4a5e-a3c1-8df87f83332f
|   |   |               `-- part.1
|   |   |-- disk2

もしくはLANG=C treeでも行けるが、上記までの結果と違いアルファベット順(-v)での表示となるので、オプションを付与してソートが必要

$ LANG=C tree
.
|-- CNAME
|-- COMPLIANCE.md
|-- CONTRIBUTING.md
|-- CREDITS
|-- Dockerfile
|-- Dockerfile.cicd
|-- Dockerfile.dev
|-- Dockerfile.hotfix
|-- Dockerfile.release
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -r            Sort files in reverse alphanumeric order.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  --dirsfirst   List directories before files (-U disables).
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2