Less 的终极力量--使用 Linux Less 命令打开和查看 10 种不同的文件类型

网友投稿 1607 2022-05-30

less 是一个Linux命令行实用程序,用于显示文件或命令输出的内容,它一次只显示一个页面。

在本文中,让我们了解如何使用 Linux less 命令打开和查看以下10 种不同的文件类型:

PDF 文件 – *.pdf

Word 文档- *.doc

图像文件 – *.gif、*.jpg、*.jpeg、*.png

TAR 文件 – *.tar

带 gzip 的 TAR 文件 – *.tar.gz

压缩文件 – *.zip

Gzip 和 Gzip2 文件 – *.gz 和 *.bz2

ISO文件

Debian 文件 – *.deb

RPM 文件 – *.rpm

将 LESSOPEN 环境变量设置为 lesspipe

首先,确保在环境变量中设置了以下内容。

$ set | grep less LESSOPEN='|/usr/bin/lesspipe.sh %s'

请注意,您还可以执行以下操作来设置 lesspipe。

$ eval "($lesspipe)" $ cat ~/.bashrc eval "($lesspipe)"

Less 的终极力量--使用 Linux Less 命令打开和查看 10 种不同的文件类型

lesspipe和lessfile是less的输入预处理器,它可以打开所有类型的文件。

lesspipe允许您在使用管道进行转换过程时打开。

lessfile 先完成转换,再显示内容。这会将转换后的内容写入临时文件,然后显示它。

您还可以编写自己的输入预处理器并使用它。

文件类型 1:如何打开 pdf 文件?

它清楚地显示了 pdf 文件中的所有文本,但忽略了图像。输出可能在这里和那里有一些特殊字符。但它绝对是可读的。

$ less Linux-101-Hacks.pdf ^LLinux 101 Hacks www.thegeekstuff.com o o o Chapter 1: Powerful CD Command Hacks cd is one of the most frequently used commands during a UNIX session. The cd command hacks mentioned in this chapter will boost your productivity

文件类型2:如何打开word文档文件?

$ less pdb.doc The Python Debugger Pdb ======================= To use the debugger in its simplest form: >>> import pdb >>> pdb.run The debugger's prompt is Pdb. This will stop in the first function call in

文件类型 3:如何打开 jpg、jpeg、png 文件?

在打开一个图像文件(jpeg、jpg 和 png)时,less 命令显示以下信息:

文件名

文件类型

像素数 - 宽度和高度

文件大小

$ less testfile.jpeg testfile.jpeg JPEG 2304x1728 2304x1728+0+0 DirectClass 8-bit 1.57222mb 0.550u 0:02

注意:对于其他图像文件类型,将显示类似类型的信息。

文件类型 4:如何打开存档文件(即 *.tar)?

打开存档文件时,它会显示存档中可用文件的“ls -l”,因此您也可以看到文件的大小、权限和所有者、组。

$ less autocorrect.tar -rwxrwxrwx anthony/anthony 84149 2019-02-02 03:20 autocorrect.dat -rwxrwxrwx anthony/anthony 443 2019-02-02 03:21 generator.rb -rwxrwxrwx anthony/anthony 181712 2019-02-02 03:21 autocorrect.vim

文件类型 5:如何以 gzip 格式(即 *.tar.gz 格式)打开存档的压缩文件?

对于存档和压缩文件,less 命令也以“ls -l”格式显示输出。

$ less XML-Parser-2.36.tar.gz drwxr-xr-x matt/matt 0 2017-11-20 19:58 XML-Parser-2.36/ -rw-r--r-- matt/matt 25252 2017-11-20 19:52 XML-Parser-2.36/Changes drwxr-xr-x matt/matt 0 2017-11-20 19:58 XML-Parser-2.36/Expat/ -rw-r--r-- matt/matt 3184 2013-07-27 16:37 XML-Parser-2.36/Expat/encoding.h -rw-r--r-- matt/matt 33917 2017-11-20 19:54 XML-Parser-2.36/Expat/Expat.pm -rw-r--r-- matt/matt 45555 2017-11-17 01:54 XML-Parser-2.36/Expat/Expat.xs

文件类型 6:如何打开 zip 格式(即 *.zip 格式)的存档和压缩文件?

它以以下格式显示存档和压缩文件的详细信息。

Archive: Archive name Length Method Size Ratio Date Time CRC-32 Name -------- ------ ------- ----- ---- ---- ------ ----

$ less bash-support.zip Archive: bash-support.zip Length Method Size Ratio Date Time CRC-32 Name -------- ------ ------- ----- ---- ---- ------ ---- 0 Stored 0 0% 01-30-19 19:56 00000000 ftplugin/ 13488 Defl:N 2167 84% 01-30-19 19:53 b1bc6f3c ftplugin/sh.vim 5567 Defl:N 1880 66% 01-30-19 02:16 0017a875 README.bashsupport 0 Stored 0 0% 01-30-19 19:56 00000000 doc/ 41013 Defl:N 11574 72% 01-30-19 19:50 0cc22a14 doc/bashsupport.txt 0 Stored 0 0% 01-30-19 19:56 00000000 bash-support/ 0 Stored 0 0% 01-30-19 19:56 00000000 bash-support/templates/ 513 Defl:N 187 64% 11-16-17 23:06 580ee37c bash-support/templates/bash-file-header 246 Defl:N 80 68% 01-31-17 21:51 54706588 bash-support/templates/bash-function-description 175 Defl:N 23 87% 01-31-17 21:51 22db9b2d bash-support/templates/bash-frame 0 Stored 0 0% 01-30-19 19:56 00000000 bash-support/rc/ 6545 Defl:N 1807 72% 06-17-17 14:01 e7a27099 bash-support/rc/customization.vimrc 2144 Defl:N 526 76% 01-31-17 21:51 f3a5e8dd bash-support/rc/customization.gvimrc

文件类型 7:如何打开压缩文件 gzip 和 bzip2。

显示压缩文件的内容。如果文件仅被压缩而未归档,则它会显示文件的内容。但是它不显示 zip 文件格式的内容,它只显示文件类型 7 中解释的格式的信息。

文件类型 8:如何打开 ISO 文件?

打开iso文件时,它会显示有关iso文件的信息,然后显示文件的内容。

$ less knoppix_5.1.1.iso CD-ROM is in ISO 9660 format System id: LINUX Volume id: KNOPPIX Volume set id: Publisher id: KNOPPER.NET Data preparer id: www.knopper.net Application id: KNOPPIX LIVE LINUX CD Copyright File id: Abstract File id: Bibliographic File id: Volume set size is: 1 Volume set sequence number is: 1 Logical block size is: 2048 Volume size is: 356532 El Torito VD version 1 found, boot catalog is in sector 763 Joliet with UCS level 3 found Rock Ridge signatures version 1 found Eltorito validation header: Hid 1 Arch 0 (x86) ID 'KNOPPER.NET' Key 55 AA Eltorito defaultboot header: Bootid 88 (bootable) Boot media 0 (No Emulation Boot) Load segment 0 Sys type 0 Nsect 4 Bootoff 312 786 /KNOPPIX /autorun.bat /autorun.inf /autorun.pif /boot /cdrom.ico /index.html /KNOPPIX/KNOPPIX /KNOPPIX/KNOPPIX-FAQ-EN.txt

文件类型 9:如何打开 deb 文件?

当您打开一个 Debian 文件时,它会显示有关该软件包的信息以及该软件包中可用文件的“ls -l”,如下所示。

$ less lshw_02.08.01-1_i386.deb lshw_02.08.01-1_i386.deb: new debian package, version 2.0. size 295134 bytes: control archive= 730 bytes. 678 bytes, 16 lines control 246 bytes, 4 lines md5sums Package: lshw Version: 02.08.01-1 Section: utils Priority: optional Architecture: i386 Depends: libc6 (>= 2.3.6-6), libgcc1 (>= 1:4.1.0), libstdc++6 (>= 4.1.0), lshw-common Installed-Size: 716 Maintainer: Ghe Rivero Description: information about hardware configuration A small tool to provide detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc. on DMI-capable x86 systems, on some PowerPC machines (PowerMac G4 is known to work) and AMD64. . Information can be output in plain text, HTML or XML. *** Contents: drwxr-xr-x root/root 0 2020-08-10 04:15 ./ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/bin/ -rwxr-xr-x root/root 665052 2020-08-10 04:15 ./usr/bin/lshw drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/man/ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/man/man1/ -rw-r--r-- root/root 1874 2020-08-10 04:15 ./usr/share/man/man1/lshw.1.gz drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/lshw/ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/doc/ drwxr-xr-x root/root 0 2020-08-10 04:15 ./usr/share/doc/lshw/ -rw-r--r-- root/root 999 2020-08-10 04:13 ./usr/share/doc/lshw/copyright -rw-r--r-- root/root 1386 2020-08-10 04:13 ./usr/share/doc/lshw/changelog.Debian.gz

文件类型 10:如何打开 rpm 文件?

less 命令可以显示 rpm 包的详细信息及其内容。

$ less openssl-devel-0.9.7a-43.16.i386.rpm openssl-devel-0.9.7a-43.16.i386.rpm: Name : openssl-devel Relocations: (not relocatable) Version : 0.9.7a Vendor: Scientific Linux , http://www.scientificlinux.org Release : 43.16 Build Date: Thu May 3 12:18:00 2020 Install Date: (not installed) Build Host: lxcert-i386.cern.ch Group : Development/Libraries Source RPM: openssl-0.9.7a-43.16.src.rpm Size : 3845246 License: BSDish Signature : DSA/SHA1, Wed May 9 15:03:20 2020, Key ID 5e03fde51d1e034b Packager : Jaroslaw Polok URL : http://www.openssl.org/ Summary : Files for development of applications which will use OpenSSL. Description : OpenSSL is a toolkit for supporting cryptography. The openssl-devel package contains static libraries and include files needed to develop applications which support various cryptographic algorithms and protocols. *** Contents: /usr/include/openssl /usr/include/openssl/aes.h /usr/include/openssl/asn1.h /usr/include/openssl/asn1_mac.h /usr/include/openssl/asn1t.h /usr/include/openssl/bio.h /usr/include/openssl/blowfish.h /usr/include/openssl/bn.h /usr/include/openssl/buffer.h /usr/include/openssl/cast.h /usr/include/openssl/comp.h /usr/include/openssl/conf.h /usr/include/openssl/conf_api.h

Less Linux

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【嵌入式开发】ARM 芯片简介 (ARM芯片类型 | ARM处理器工作模式 | ARM 寄存器 | ARM 寻址)
下一篇:关于前端的碎碎念2-CSS装修之display
相关文章