New FAMILUG

The PyMiers

Wednesday 10 February 2016

[CLI] namei - theo em đến cuối chân trời

Khi cho một đường dẫn và kiểm tra xem đường dẫn đó có tồn tại hay không, ls có thể trả lời có hoặc không. Nhưng namei mới là giải pháp để tìm ra đường dẫn đứt ở đoạn nào.
$ whatis namei
namei (1)            - follow a pathname until a terminal point is found
$ ls /etc/salt/minion.d/extra.conf/hihi/hehe
ls: cannot access /etc/salt/minion.d/extra.conf/hihi/hehe: Not a directory

$ namei /etc/salt/minion.d/extra.conf/hihi/hehe
f: /etc/salt/minion.d/extra.conf/hihi/hehe
 d /
 d etc
 d salt
 d minion.d
 - extra.conf
hihi - No such file or directory
Kết quả cho biết đường dẫn này không tồn tại từ phần "hihi" chứ ko phải phần "hehe".


Dùng thêm option -l để hiện thông tin chi tiết.
$ namei -l /etc/salt/minion.d/extra.conf/hihi/hehe
f: /etc/salt/minion.d/extra.conf/hihi/hehe
drwxr-xr-x root root /
drwxr-xr-x root root etc
drwxr-xr-x root root salt
drwxr-x--- root root minion.d
-r--r----- root root extra.conf
hihi - No such file or directory
namei nằm trong package util-linux, package chứa rất nhiều các công cụ quan trọng để bảo trì hệ thống nên có thể nói sẽ tìm thấy namei trên mọi Linux-based OS:
$ dpkg -S `which namei`
util-linux: /usr/bin/namei
Bài viết thực hiện trên:
$ lsb_release -d
Description:    Ubuntu 14.04.3 LTS
$ dpkg -l util-linux | grep ii
ii  util-linux                          2.20.1-5.1ubuntu20.7             amd64        Miscellaneous system utilities
hvn AT familug DOT org
Hết.

No comments:

Post a Comment