【Linux】查看文件内容指令

指令功能
cat由第一行开始显示文件内容
tac从最后一行开始显示
nl显示的时候,顺便输出行号
more一页一页的显示文件内容
less同more,但它可以往前翻页
head只看头几行
tail只看尾巴几行

详解

1. cat

由第一行开始显示文件内容

cat [-AbEnTv]
-A :相当於 -vET 的整合选项,可列出一些特殊字符而不是空白而已;
-b :列出行号,仅针对非空白行做行号显示,空白行不标行号!
-E :将结尾的断行字节 $ 显示出来;
-n :列印出行号,连同空白行也会有行号,与 -b 的选项不同;
-T :将 [tab] 按键以 ^I 显示出来;
-v :列出一些看不出来的特殊字符

2. tac

tac与cat命令刚好相反,文件内容从最后一行开始显示,可以看出 tac 是 cat 的倒着写!

3. nl

显示行号

nl [-bnw] 文件
-b :指定行号指定的方式,主要有两种:

-b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
-b t :如果有空行,空的那一行不要列出行号(默认值);

-n :列出行号表示的方法,主要有三种:

-n ln :行号在荧幕的最左方显示;
-n rn :行号在自己栏位的最右方显示,且不加 0 ;
-n rz :行号在自己栏位的最右方显示,且加 0 ;

-w :行号栏位的占用的位数。

4. more

一页一页翻动,在 more 这个程序的运行过程中,你有几个按键可以按的:

空格   :代表向下翻一页;
Enter    :代表向下翻『一行』;
/字串 :代表在这个显示的内容当中,向下搜寻『字串』这个关键字;
:f      :立刻显示出档名以及目前显示的行数;
q      :代表立刻离开 more ,不再显示该文件内容。
b 或 [ctrl]-b :代表往回翻页,不过这动作只对文件有用,对管线无用。

5. less

一页一页翻动,less运行时可以输入的命令有:

空格     :向下翻动一页;
[pagedown] :向下翻动一页;
[pageup]    :向上翻动一页;
/字串     :向下搜寻『字串』的功能;
?字串     :向上搜寻『字串』的功能;
n      :重复前一个搜寻 (与 / 或 ? 有关!)
N      :反向的重复前一个搜寻 (与 / 或 ? 有关!)
q       :离开 less 这个程序;

6. head

取出文件前面几行

head [-n number] 文件
-n :后面接数字,代表显示几行的意思.默认的情况中,显示前面 10 行!

7. tail

取出文件后面几行

tail [-n number] 文件
-n :后面接数字,代表显示几行的意思
-f :表示持续侦测后面所接的档名,要等到按下[ctrl]-c才会结束tail的侦测

8. od

以字符或者十六进制的形式显示二进制文件。

一个典型的Haproxy_exporter监控metric例子 包含指标 haproxy_backend_bytes_in_total haproxy_backend_bytes_out_total haproxy_backend_client_aborts_total haproxy_backend_compressor_bytes_bypassed_total haproxy_backend_compressor_bytes_in_total haproxy_backend_compressor_bytes_out_total haproxy_backend_connection_errors_total haproxy_backend_current_queue haproxy_backend_current_server haproxy_backend_current_session_rate haproxy_backend_current_sessions haproxy_backend_http_connect_time_average_seconds haproxy_backend_http_queue_time_average_seconds haproxy_backend_http_response_time_average_seconds haproxy_backend_http_responses_compressed_total haproxy_backend_http_responses_total haproxy_backend_http_total_time_average_seconds haproxy_backend_response_errors_total haproxy_backend_retry_warnings_total haproxy_backend_server_aborts_total haproxy_backend_server_selected_total haproxy_backend_sessions_total haproxy_backend_up haproxy_backend_weight haproxy_exporter_build_info haproxy_exporter_csv_parse_failures haproxy_exporter_total_scrapes haproxy_frontend_bytes_in_total haproxy_frontend_bytes_out_total haproxy_frontend_compressor_bytes_bypassed_total haproxy_frontend_compressor_bytes_in_total haproxy_frontend_compressor_bytes_out_total haproxy_frontend_connections_total haproxy_frontend_current_session_rate haproxy_frontend_current_sessions haproxy_frontend_http_requests_total haproxy_frontend_http_responses_compressed_total haproxy_frontend_http_responses_total haproxy_frontend_limit_session_rate haproxy_frontend_limit_sessions haproxy_frontend_max_session_rate haproxy_frontend_max_sessions haproxy_frontend_request_errors_total haproxy_frontend_requests_denied_total haproxy_frontend_sessions_total haproxy_server_bytes_in_total haproxy_server_bytes_out_total haproxy_server_check_duration_seconds haproxy_server_check_failures_total haproxy_server_client_aborts_total haproxy_server_connection_errors_total haproxy_server_current_queue haproxy_server_current_session_rate haproxy_server_current_sessions haproxy_server_downtime_seconds_total haproxy_server_http_responses_total haproxy_server_max_queue haproxy_server_max_session_rate haproxy_server_max_sessions haproxy_server_redispatch_warnings_total haproxy_server_response_errors_total haproxy_server_retry_warnings_total haproxy_server_server_aborts_total haproxy_server_server_selected_total haproxy_server_sessions_total haproxy_server_up haproxy_server_weight haproxy_up process_cpu_seconds_total process_max_fds process_open_fds process_resident_memory_bytes process_start_time_seconds process_virtual_memory_bytes promhttp_metric_handler_requests_in_flight promhttp_metric_handler_requests_total
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值