
Foto per gentile concessione di gfpeck
In precedenza abbiamo discusso 15 esempi pratici di comando find e comando grep. Ora è il momento di rivolgere la nostra attenzione a qualcosa di meno.
In questo articolo, esaminiamo come utilizzare il comando Linux less per aprire e visualizzare i seguenti 10 diversi tipi di file :
- File PDF – *.pdf
- Documento Word- *.doc
- File immagine – *.gif, *.jpg, *.jpeg, *.png
- File TAR – *.tar
- File TAR con gzip – *.tar.gz
- File zip – *.zip
- File Gzip e Gzip2 – *.gz e *.bz2
- File ISO
- File Debian – *.deb
- File RPM – *.rpm
Imposta la variabile d'ambiente LESSOPEN su lesspipe
Innanzitutto, assicurati che nella variabile di ambiente sia impostato quanto segue.
$ set | grep less LESSOPEN='|/usr/bin/lesspipe.sh %s'
Tieni presente che puoi anche eseguire le seguenti operazioni per configurare lesspipe.
$ eval "($lesspipe)" $ cat ~/.bashrc eval "($lesspipe)"
- lesspipe , menofile sono il preprocessore di input per meno, che gli consente di aprire tutti i tipi di file.
- lesspipe ti permette di aprire mentre è in corso il processo di conversione tramite pipe.
- menofile prima completa la conversione, quindi visualizza il contenuto. Questo scrive l'oggetto convertito in un file temporaneo, quindi lo visualizza.
- Puoi anche scrivere il tuo preprocessore di input e usarlo.
Tipo di file 1:come aprire un file pdf?
Mostra chiaramente tutto il testo nel file pdf, ma ignora le immagini. L'output potrebbe avere alcuni caratteri speciali qua e là. Ma è sicuramente leggibile.
$ 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
Tipo di file 2:come aprire un file di documento 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
Tipo di file 3:come aprire un file jpg, jpeg, png?
Durante l'apertura di un file immagine (jpeg, jpg e png), il comando less mostra le seguenti informazioni:
- Nome del file
- Tipo di file
- Numero di pixel:larghezza e altezza
- Dimensione del file
$ less testfile.jpeg testfile.jpeg JPEG 2304x1728 2304x1728+0+0 DirectClass 8-bit 1.57222mb 0.550u 0:02
Nota: Informazioni simili verranno visualizzate per altri tipi di file immagine.
Tipo di file 4:come aprire un file archiviato (es. *.tar)?
Durante l'apertura del file di archivio mostra "ls -l" dei file disponibili nell'archivio, quindi puoi vedere la dimensione del file, i permessi di esso e il proprietario, anche il gruppo.
$ 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
Tipo di file 5:come aprire un file compresso archiviato in formato gzip (es. formato *.tar.gz)?
Per il file archiviato e compresso anche less command mostra l'output nel formato “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
Tipo di file 6:come aprire un file archiviato e compresso in formato zip (es. formato *.zip)?
Mostra i dettagli del file archiviato e compresso nel seguente formato.
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
Tipo di file 7:come aprire un file compresso gzip e bzip2.
Mostra il contenuto del file compresso. Se il file è solo compresso e non archiviato, mostra il contenuto del file. Tuttavia non mostra il contenuto di un formato di file zip, mostra solo le informazioni nel formato spiegato in Tipo di file 7.
Tipo di file 8:come aprire un file ISO?
Durante l'apertura di un file iso, mostra le informazioni sul file iso e quindi mostra il contenuto del file.
$ 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
Tipo di file 9:come aprire un file deb?
Quando apri un file Debian, mostra le informazioni su quel pacchetto e anche "ls -l" dei file disponibili in quel pacchetto, come mostrato di seguito.
$ 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
Tipo di file 10:come aprire un file rpm?
less può mostrare i dettagli del pacchetto rpm e il suo contenuto.
$ 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
Questo articolo è stato scritto da SathiyaMoorthy, autore di 15 Articolo pratico di esempi di comandi per la ricerca di Linux. The Geek Stuff accoglie con favore i tuoi suggerimenti e gli articoli degli ospiti