每天⼀个Linux命令(13)less命令
less命令的作⽤与more⼗分相似,都可以⽤来浏览⽂字档案的内容,不同的是less命令允许⽤户向前或向后浏览⽂件,⽽more命令只能向前浏览。
⽤less命令显⽰⽂件时,⽤PageUp键向上翻页,⽤PageDown键向下翻页。要退出less程序,应按Q键。
(1)⽤法:
⽤法: less  [选项参数] [⽂件参数]
(2)功能:
功能: less 与more命令类似,但可以通过翻页键查看上下页的内容
(3)选项参数:
1) -e:                                              ⽂件内容显⽰完毕后,⾃动退出
2) -f:                                                强制显⽰⽂件
  3) -g:                                              不加亮显⽰搜索到的所有关键词,仅显⽰当前显⽰的关键字,以提⾼显⽰速度
  4) -l:                                                搜索时忽略⼤⼩写的差异
  5) -N:                                              每⼀⾏⾏⾸显⽰⾏号
6) -s:                                              将连续多个空⾏压缩成⼀⾏显⽰
linux换行按哪个键  7) -S:                                              在单⾏显⽰较长的内容,⽽不换⾏显⽰
  8) -x<;数字>:                                    将TAB字符显⽰为指定个数的空格字符。
(4)实例:
1)[root@localhost Documents]# less  less_text                  在另⼀个进程页⾯中显⽰⽂本内容,按q键退出
[root@localhost Documents]# mv more_text1 less_text    //将more_text1改名为less_text
[root@localhost Documents]# ll
总⽤量4
-rw-r--r--. 1 root root 664 5⽉907:59 less_text
[root@localhost Documents]# cat less_text    //在当前终端中显⽰(和less命令显⽰的效果还是有差别的)
[root@localhost Documents]# less less_text  //在另⼀个页⾯中显⽰⽂本
I am studing orders of Linux!
I am trying to write as many as lines of text!
No matter how low you consider yourself,
there is always someone looking behind you,
hoping that they were that high!
Something you want keep all the time,always you will lose!
Never forget to say "thanks"!
Hppay today,also,prepared for happiness in the future!
Don't aim your success if you want it,just do what you love and believe and finally you will success!
Maybe you can be laze man like a pig,but you can't feel free as it!
I am a college school student!
I am planning to live and work in hangzhou or guangzhou!
I am from hefei anhui!
Enough,I have write too many words!
(END)
2)[root@localhost Documents]# ps -ef |less      显⽰已有进程信息
ID        PID  PPID  C STIME TTY          TIME CMD
root          10000:16 ?        00:00:10 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
root          20000:16 ?        00:00:00 [kthreadd]
root          32000:16 ?        00:00:03 [ksoftirqd/0]
root          52000:16 ?        00:00:00 [kworker/0:0H]
root          72000:16 ?        00:00:00 [migration/0]
root          82000:16 ?        00:00:00 [rcu_bh]
root          92000:16 ?        00:00:00 [rcuob/0]
root        102000:16 ?        00:00:00 [rcuob/1]
root        112000:16 ?        00:00:00 [rcuob/2]
root        122000:16 ?        00:00:00 [rcuob/3]
root        132000:16 ?        00:00:00 [rcuob/4]
root        142000:16 ?        00:00:00 [rcuob/5]
root        152000:16 ?        00:00:00 [rcuob/6]
root        162000:16 ?        00:00:00 [rcuob/7]
root        172000:16 ?        00:00:00 [rcuob/8]
root        182000:16 ?        00:00:00 [rcuob/9]
root        192000:16 ?        00:00:00 [rcuob/10]
root        202000:16 ?        00:00:00 [rcuob/11]
root        212000:16 ?        00:00:00 [rcuob/12]
root        222000:16 ?        00:00:00 [rcuob/13]
root        232000:16 ?        00:00:00 [rcuob/14]
root        242000:16 ?        00:00:00 [rcuob/15]
root        252000:16 ?        00:00:00 [rcuob/16]
root        262000:16 ?        00:00:00 [rcuob/17]
root        272000:16 ?        00:00:00 [rcuob/18]
root        282000:16 ?        00:00:00 [rcuob/19]
root        292000:16 ?        00:00:00 [rcuob/20]
root        302000:16 ?        00:00:00 [rcuob/21]
root        312000:16 ?        00:00:00 [rcuob/22]
root        322000:16 ?        00:00:00 [rcuob/23]
root        332000:16 ?        00:00:00 [rcuob/24]
root        342000:16 ?        00:00:00 [rcuob/25]
root        352000:16 ?        00:00:00 [rcuob/26]
:
.
......//还有很多没有显⽰
3)[root@localhost Documents]# history | less              显⽰历史输⼊的进程信息
1  touch touch_test /home/sunjimeng/Document
2  cd /home/sunjimeng/Document
3  ll
4  cd /
5  touch touch_text /home/sunjimeng/Document/touch_test
6  cd /home/sunjimeng/Document
7  ll
8  rm touch_test
9  cd /
10  ls -l /home/sunjimeng/Document
11  touch /home/sunjimeng/Document/touch_test_file
12  cd home/sunjimeng/Document
13  ll
14  touch touch_test_file
15  ll
16  touch -t 06061806 touch_test_file
17  ll
18  touch touch_test_file
19  ll
20  touch -t 06061806 touch_test_file
21  ll
22  touch touch_test_file2
23  ll
24  touch -r touch_testfile touch_test_tile2
25  touch -r touch_test_file touch_test_file2
26  ll
27  touch -d "10 day ago" touch_test_file2
28  ll
29  touch -r touch_test_file touch_test_file2
30  ll
31  touch -d "10 days ago" touch_test_file2
32  ll
33  touch "10 days ago" touch_test_file
34  ll
:
4)[root@localhost Documents]# less less1 less2                          查看多个⽂件(怎么切换下⼀个还不清楚)root@localhost Documents]# cat >less1 <<EOF
> Lost means Get!
>
> No losing No getting!
>
> End!
> EOF
[root@localhost Documents]# cat >less2 <<EOF
> If you want keep,you always lose!
>
> Certainly It is!
> End!
> EOF
[root@localhost Documents]# ll
总⽤量12
-rw-r--r--. 1 root root  45 5⽉908:15 less1
-rw-r--r--. 1 root root  57 5⽉908:16 less2
-rw-r--r--. 1 root root 664 5⽉907:59 less_text
[root@localhost Documents]# less less1 less2
Lost means Get!
No losing No getting!
End!
less1 (file 1 of 2) (END) - Next: less2
5)[sunjimeng@localhost ~]$ netstat -tpnl |less      在另⼀个进程页⾯中分页显⽰信息,这⾥显⽰的是⽹络信息[sunjimeng@localhost ~]$ netstat -tpnl |less
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address          Foreign Address        State      PID/Program name
tcp        000.0.0.0:220.0.0.0:*              LISTEN      -
tcp        00127.0.0.1:6310.0.0.0:*              LISTEN      -
tcp        00127.0.0.1:250.0.0.0:*              LISTEN      -
tcp6      00 :::22                  :::*                    LISTEN      -
tcp6      00 ::1:631                :::*                    LISTEN      -
tcp6      00 ::1:25                  :::*                    LISTEN      -
(5)其他:
  1.全屏导航
  ctrl + F - 向前移动⼀屏
  ctrl + B - 向后移动⼀屏
  ctrl + D - 向前移动半屏
  ctrl + U - 向后移动半屏
  2.单⾏导航
  j - 向前移动⼀⾏
  k - 向后移动⼀⾏
  3.其它导航
  G - 移动到最后⼀⾏
  g - 移动到第⼀⾏
  q / ZZ - 退出 less 命令
  4.其它有⽤的命令
  v - 使⽤配置的编辑器编辑当前⽂件
  h - 显⽰ less 的帮助⽂档
  &pattern - 仅显⽰匹配模式的⾏,⽽不是整个⽂件
  5.标记导航
  当使⽤ less 查看⼤⽂件时,可以在任何⼀个位置作标记,可以通过命令导航到标有特定标记的⽂本位置:  ma - 使⽤ a 标记⽂本的当前位置
  'a - 导航到标记 a 处

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。