Skip to main content

[CLI] less - view file trên terminal


root@hvn-do-workspace:~# whatis less
less (1)             - opposite of more
root@hvn-do-workspace:~# whatis more
more (1)             - file perusal filter for crt viewing
Các UNIX developer khá là vui tính trong chuyện trả lời "whatis". Một câu trả lời cũng vui tính không kém khi hỏi :
# whatis git
git (1)              - the stupid content tracker
Khái niệm
Cơ bản thì less là 1 chương trình để view file text trên terminal. ``less`` chỉ để view chứ không edit file, các UNIX-like OSes đều cài sẵn ``vi`` và ``less``. So với ``vi``, khi xem các file lớn, ``less`` không cần phải đọc toàn bộ input file trước khi start (``vi`` sẽ đọc toàn bộ và nhét vào RAM) vì vậy less sẽ start nhanh hơn.

``less`` là một phiên bản cải tiến của ``more``, đây là một kiểu chơi chữ trong tiếng Anh:
less is more

Có 2 cách dùng ``less`` cơ bản:

1. less filename
đọc input file tên là filename 
Ví dụ:
less /etc/passwd 
 2. some commands | less
đọc qua pipeline (|) output của câu lệnh trước nó
Ví dụ:
ls -la | less (dùng khi output quá dài)
Các phím tắt
j : xuống
k : lên
space: xuống 1 màn hình
q: quit
/ tu_khoa: search down
? tu_khoa: search up
-N : hiển thị số dòng (bấm -N, enter)

Đọc thêm

Từ Description section trong ``man 1 less``

Less  is  a  program  similar  to  more (1), but which allows backward movement in the file as well as forward movement.  Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi (1).  Less uses termcap (or terminfo on some systems), so it can run on  a  variety  of terminals.  There is even limited support for hardcopy terminals.  (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.)  Commands are based on both more and vi.  Commands may be preceded by a decimal number, called N in the descriptions below.  The number is used by some commands, as indicated.

Hết!

Comments

  1. di chuyển đến dòng thứ N:
    Ng

    VD đến dòng 69:
    69g

    ReplyDelete

Post a Comment

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG