ls command in linux.
Hôm nay chúng ta sẽ tìm hiểu lệnh ls, lệnh liệt kê file và thư mục trong linux.
ls
liệt kê file và thư mục
[dt]% ls
abc app.js c.txt filter.txt index.php output.txt t text.txt xyz
abc.txt a.txt d.txt index.html install_arco.txt remote_ubuntu text2.txt t.txt
[dt-arco:test]
ls -l
Liệt kê chi tiết
[dt]% cd abc
[dt-arco:abc]
[dt]% ls
a.txt b.txt
[dt-arco:abc]
[dt]% ls -l
total 8
-rw-r--r-- 1 dt dt 450 06:00 23 Thg 2 a.txt
-rw-r--r-- 1 dt dt 31 22:45 20 Thg 2 b.txt
[dt-arco:abc]
Liệt kê ra các quyền như r(đọc), w(ghi), các quyền này mình sẽ có 1 bài viết khác chi tiết hơn.
ls -a
liệt kê ra file ẩn
[dt]% touch .config <-- tạo file ẩn
[dt-arco:abc]
[dt]% ls
a.txt b.txt
[dt-arco:abc]
[dt]% ls -a
. .. a.txt b.txt .config
[dt-arco:abc]
[dt]%
- . : là thư mục hiện tại
- .. : là thư mục cha
- file ẩn là file bắt đầu bằng dấu chấm.
ls -r
Liêt kê đảo ngược thứ tự
[dt]% ls --> theo thứ tự abc
a.txt b.txt
[dt-arco:abc]
[dt]% ls -r --> ngược lại
b.txt a.txt
[dt-arco:abc]
ls -t
Liệt kê theo thời gian mới nhất tới củ nhất
[dt]% ls -lt
total 8
-rw-r--r-- 1 dt dt 450 06:00 23 Thg 2 a.txt
-rw-r--r-- 1 dt dt 31 22:45 20 Thg 2 b.txt
[dt-arco:abc]
file a.txt là file mới nhất.
[dt]% ls -t
a.txt b.txt <-- a.txt trước
[dt-arco:abc]
Nếu muốn file củ nhất trước.
[dt]% ls -tr
b.txt a.txt <-- b.txt trước
[dt-arco:abc]
[dt]%
ls -R
Liệt kê file trong thư mục con
[dt-arco:xyz] <-- ta đang thư mục xyz
[dt]% ls
abc <-- trong xyz có thư mục abc
[dt-arco:xyz]
[dt]% ls -R <-- liệt kê các file trong abc
.:
abc <-- thư mục abc
./abc: <-- trong abc có a.txt và b.txt
a.txt b.txt
[dt-arco:xyz]
ls /home/dt/Downloads
Liệt kê file và thư mục của /home/dt/Downloads
ls Downloads | more
Thư mục Downloads có rất nhiều file ta dùng more để xem từng trang.
[dt-arco:~]
[dt]% ls Downloads | more
162-cach-Sap-xep-nha-cua-theo-phong-thuy.pdf
2017-07-05-raspbian-jessie.img
2017-07-05-raspbian-jessie.zip
4000_world_1.pdf
400.pdf
50-particle.rules
5-LINKING-WORDS.pdf
arcolinuxb-i3-v21.11.05-x86_64.iso.torrent
arcolinux-spices
balenaEtcher-1.7.1-x64.AppImage
balenaEtcher-1.7.3-x64.AppImage
balenaEtcher-1.7.8-ia32.AppImage
balena-etcher-electron-1.7.1-linux-x64.zip
--More--
Ta nhấn space sẽ hiện theo từng trang, enter sẽ xuống theo từng dòng. không xem nữa nhấn ctrl + c , enter
ls Downloads | head -2
Xem 2 dòng đầu
[dt]% ls Downloads | head -2
162-cach-Sap-xep-nha-cua-theo-phong-thuy.pdf
2017-07-05-raspbian-jessie.img
[dt-arco:~]
ls Downloads | tail -2
Xem 2 dòng cuối.
[dt]% ls Downloads | tail -2
xedap2.jpg
xedap3.jpg
[dt-arco:~]
Như vậy ta đã hiểu lệnh ls rồi nhé. Hẹn các bạn ở các bài vết sau trên dblog24h.com.