GNU/Linux >> Linux の 問題 >  >> Linux

Linux Less Command で 10 種類のファイル タイプを開いて表示 – Less の究極のパワー


写真提供:gfpeck

先ほど、find コマンドと grep コマンドの 15 の実際的な例について説明しました。
 
この記事では、Linux の少ないコマンドを使用して開いて表示する方法を確認しましょう。 次の 10 種類のファイル タイプ :

<オール>
  • PDF ファイル – *.pdf
  • Word 文書 - *.doc
  • 画像ファイル – *.gif、*.jpg、*.jpeg、*.png
  • TAR ファイル – *.tar
  • gzip を含む TAR ファイル – *.tar.gz
  • Zip ファイル – *.zip
  • Gzip および Gzip2 ファイル – *.gz および *.bz2
  • ISO ファイル
  • Debian ファイル – *.deb
  • RPM ファイル – *.rpm
  • LESSOPEN 環境変数を lesspipe に設定します

    まず、環境変数に以下が設定されていることを確認してください。

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


    以下の手順でレスパイプをセットアップすることもできます。

    $ eval "($lesspipe)"
    
    $ cat ~/.bashrc
    eval "($lesspipe)"
    • レスパイプ , 少ないファイル less の入力プリプロセッサであり、あらゆるタイプのファイルを開くことができます。
    • レスパイプ 変換プロセス中にパイプを使用して開くことができます。
    • 少ないファイル 最初に変換を完了してから、コンテンツを表示します。これにより、変換されたものが一時ファイルに書き込まれ、表示されます。
    • 独自の入力プリプロセッサを作成して使用することもできます。

    ファイル タイプ 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 2009-02-02 03:20 autocorrect.dat
    -rwxrwxrwx anthony/anthony 443 2009-02-02 03:21 generator.rb
    -rwxrwxrwx anthony/anthony 181712 2009-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 2007-11-20 19:58 XML-Parser-2.36/
    -rw-r--r-- matt/matt 25252 2007-11-20 19:52 XML-Parser-2.36/Changes
    drwxr-xr-x matt/matt 0 2007-11-20 19:58 XML-Parser-2.36/Expat/
    -rw-r--r-- matt/matt 3184 2003-07-27 16:37 XML-Parser-2.36/Expat/encoding.h
    -rw-r--r-- matt/matt 33917 2007-11-20 19:54 XML-Parser-2.36/Expat/Expat.pm
    -rw-r--r-- matt/matt 45555 2007-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-09 19:56 00000000 ftplugin/
    13488 Defl:N 2167 84% 01-30-09 19:53 b1bc6f3c ftplugin/sh.vim
    5567 Defl:N 1880 66% 01-30-09 02:16 0017a875 README.bashsupport
    0 Stored 0 0% 01-30-09 19:56 00000000 doc/
    41013 Defl:N 11574 72% 01-30-09 19:50 0cc22a14 doc/bashsupport.txt
    0 Stored 0 0% 01-30-09 19:56 00000000 bash-support/
    0 Stored 0 0% 01-30-09 19:56 00000000 bash-support/templates/
    513 Defl:N 187 64% 11-16-07 23:06 580ee37c bash-support/templates/bash-file-header
    246 Defl:N 80 68% 01-31-07 21:51 54706588 bash-support/templates/bash-function-description
    175 Defl:N 23 87% 01-31-07 21:51 22db9b2d bash-support/templates/bash-frame
    0 Stored 0 0% 01-30-09 19:56 00000000 bash-support/rc/
    6545 Defl:N 1807 72% 06-17-07 14:01 e7a27099 bash-support/rc/customization.vimrc
    2144 Defl:N 526 76% 01-31-07 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 2006-08-10 04:15 ./
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/bin/
    -rwxr-xr-x root/root 665052 2006-08-10 04:15 ./usr/bin/lshw
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/man/
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/man/man1/
    -rw-r--r-- root/root 1874 2006-08-10 04:15 ./usr/share/man/man1/lshw.1.gz
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/lshw/
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/doc/
    drwxr-xr-x root/root 0 2006-08-10 04:15 ./usr/share/doc/lshw/
    -rw-r--r-- root/root 999 2006-08-10 04:13 ./usr/share/doc/lshw/copyright
    -rw-r--r-- root/root 1386 2006-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 2007
    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 2007, 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
    


    この記事は、 の著者、SathiyaMoorthy によって書かれました。 15 Practical Linux Find Command Examples 記事。 The Geek Stuff は、あなたのヒントやゲスト記事を歓迎します


    Linux
    1. findコマンドを使用してLinux上のファイルとディレクトリを検索します

    2. Linuxtacコマンドの使用を開始する

    3. Linuxでの並べ替えコマンドと例

    1. statコマンドを使用してLinuxのファイルステータスを確認します

    2. xclipを使用してLinuxコマンドラインでコピーして貼り付けます

    3. Linuxでのファイルコマンドの基本的な例

    1. Linuxコマンドラインでテキストファイルを表示するためにlessを使用する

    2. 例を使用してLinuxでlessコマンドを使用する方法

    3. Linuxでのコマンドの削減