Para visualizar las primera líneas de un archivo
se puede utilizar head
y para las últimas
tail
, pero es posible combinarlas en un sólo
comando. Lo mejor es crear una función en el
archivo .bashrc
de la siguiente manera:
function ht1() { (head -n 1;tail -n 1) < "$1" }
De esta manera invocando ht1 archivo-a-ver
veremos la primer y última línea de
archivo-a-ver
:
# ht1 /var/log/kern.log Sep 18 09:55:10 huayra kernel: imklog 5.8.11, log source = /proc/kmsg started. Sep 18 11:52:54 huayra kernel: [ 7083.517735] fuse init (API version 7.17)
Se pueden crear varias funciones con distinta cantidad de líneas a mostrar:
function ht() { (head -n 5;tail -n 5) < "$1" } function ht10() { (head -n 10;tail -n 10) < "$1" }
Vemos el resultado:
# ht /var/log/kern.log
Sep 18 09:55:10 huayra kernel: imklog 5.8.11, log source = /proc/kmsg started.
Sep 18 09:55:10 huayra kernel: [ 0.000000] Initializing cgroup subsys cpuset
Sep 18 09:55:10 huayra kernel: [ 0.000000] Initializing cgroup subsys cpu
Sep 18 09:55:10 huayra kernel: [ 0.000000] Linux version 3.2.0-4-686-pae (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.41-2+deb7u2
Sep 18 09:55:10 huayra kernel: [ 0.000000] Disabled fast string operations
Sep 18 10:17:35 huayra kernel: [ 1364.361786] XFS (dm-0): Mounting Filesystem
Sep 18 10:17:36 huayra kernel: [ 1364.714449] XFS (dm-0): Ending clean mount
Sep 18 10:20:39 huayra kernel: [ 1548.324157] tpm_tis tpm_tis: 1.2 TPM (device-id 0xFFFF, rev-id 255)
Sep 18 10:21:35 huayra kernel: [ 1604.513989] tpm_tis tpm_tis: 1.2 TPM (device-id 0xFFFF, rev-id 255)
Sep 18 11:52:54 huayra kernel: [ 7083.517735] fuse init (API version 7.17)
Publicado el 19/09/2013 por OSiRiS
alias
apc
bash
bashrc
bash_aliases
cache
computed field
courier
docker
dovecot
drupal
export
foxyproxy firefox
grep
head
history
iftop
imap
imapsync
liberaciones
migracion
migrate
Monotributo
Moreno emprendedor mincyt
mysql
openwrt
owncloud
parallel-ssh
parches
performance
previous next links
query
shell
sql
sugarcrm
tail
tar
tl-mr3020
tryton
undelete
vcard
views_navigation
wget
wicd