Linux – ls (listar archivos)

por | 9 junio, 2015

El comando ls sirve básicamente para listar archivos.

Si no se especifica nada listará por defecto los archivos en el directorio actual.

ls tiene muchas e interesantes opciones:

 

-a muestra archivos ocultos (no ignora los cominezos con .)
-A, –almost-all do not list implied . and ..
–author with -l, print the author of each file
-b, –escape print octal escapes for nongraphic characters
–block-size=TAMAÑO utiliza bloques de TAMAÑO bytes
-B, –ignore-backups no muestra la entradas que terminan con ~
-c con -lt: ordena por ctime y muestra ctime (fecha de última modificación del fichero)

con -l: muestra ctime y ordena por nombre en cualquier otro caso: ordena por ctime

-C muestra las entradas por columnas
–color[=CUÁNDO] especifica si se usará color para distinguir los tipos de ficheros. CUÁNDO puede ser `never’, `always’ o `auto’
-d, –directory muestra las entradas de los directorios en lugar de sus contenidos, y no sigue los enlaces simbólicos
-D, –dired genera el resultado para el modo `dired’ de Emacs
-f do not sort, enable -aU, disable -ls –color
-F, –classify append indicator (one of */=>@|) to entries
–file-type likewise, except do not append `*’
–format=WORD across -x, commas -m, horizontal -x, long -l,   single-column -1, verbose -l, vertical -C
–full-time like -l –time-style=full-iso
-g like -l, but do not list owner
–group-directories-first group directories before files
-G, –no-group in a long listing, don’t print group names
-h, –human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G)
–si likewise, but use powers of 1000 not 1024
-H, –dereference-command-line follow symbolic links listed on the command line
–dereference-command-line-symlink-to-dir follow each command line symbolic link that points to a directory
–hide=PATTERN do not list implied entries matching shell PATTERN (overridden by -a or -A)
–indicator-style=WORD append indicator with style WORD to entry names: none (default), slash (-p), file-type (–file-type), classify (-F)
-i, –inode print the index number of each file
-I, –ignore=PATTERN do not list implied entries matching shell PATTERN
-k like –block-size=1K
-l utiliza un formato de listado largo
-L, –dereference al mostrar la información de un fichero para un enlace simbólico, muestra la información del fichero al que apunta el enlace en lugar de la del propio enlace
-m rellena el ancho con una lista de entradas separadas por comas
-n, –numeric-uid-gid like -l, but list numeric user and group IDs
-N, –literal print raw entry names (don’t treat e.g. Control characters specially)
-o like -l, but do not list group information
-p, –indicator-style=slash append / indicator to directories
-q, –hide-control-chars imprime ? en lugar de los caracteres no gráficos
–show-control-chars muestra los caracteres no gráficos tal y como son (predeterminado a menos que el programa sea `ls’ y la salida sea un terminal)
-Q, –quote-name encierra los nombres de las entradas entre comillas
–quoting-style=PALABRA utiliza el estilo de cita PALABRA para los nombres de las entradas:

literal, locale, shell, shell-always, c, escape

-r, –reverse reverse order while sorting
-R, –recursive list subdirectories recursively
-s, –size print the size of each file, in blocks
-S sort by file size
–sort=WORD sort by WORD instead of name: none -U, extension -X, size -S, time -t, version -v
–time=WORD with -l, show time as WORD instead of modification time: atime -u, access -u, use -u, ctime -c, or status -c; use specified time as sort key if –sort=time
–time-style=STYLE with -l, show times using style STYLE:

 

full-iso, long-iso, iso, locale, +FORMAT.

 

FORMAT is interpreted like `date’; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with `posix-‘, STYLE takes effect only outside the POSIX locale

-t sort by modification time
-T, –tabsize=COLS assume tab stops at each COLS instead of 8
-u con -lt: ordena por atime y muestra atime (fecha de último acceso al fichero)

con -l: muestra atime y ordena por nombre en cualquier otro caso: ordena por atime

-U no ordena; muestra las entradas en el orden del directorio
-v ordena por versión
-w, –width=COLS assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-Z, –context print any SELinux security context of each file
-1 list one file per line
–help muestra esta ayuda y finaliza
–version informa de la versión y finaliza

TAMAÑO puede ser (o puede ser un entero seguido opcionalmente por) uno de los siguientes: kB 1000, K 1024, MB 1000*1000, M 1024*1024, y así en adelante para G, T, P, E, Z, Y.

Ejemplos:

$ ls

c7200_i0_lock c7200_i0_log.txt core Desktop Downloads dynagen NAS

ls -lh

total 12M

-rw-r–r– 1 javier javier   5 jul 12 14:14 c7200_i0_lock

-rw-r–r– 1 javier javier   0 jul 12 14:14 c7200_i0_log.txt

-rw——- 1 javier javier 52M ago 13 13:07 core

drwxr-xr-x 3 javier javier 4,0K oct 4 17:37 Desktop

drwx—— 2 javier javier 4,0K sep 6 09:36 Downloads

drwxr-xr-x 6 javier javier 4,0K jul 12 14:23 dynagen

drwxr-xr-x 4 javier javier 4,0K sep 17 09:46 NAS

 

La opción -R se puede usar para buscar archivos:

 

$ ls -R |grep CISCO3620

CISCO3620-DC.gab

CISCO3620.gab

CISCO3620-RPS.gab

 

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *