Listado y estado de archivos y directorios¶
- Listado y estado de archivos y directorios
- ls
- tree
- stat
- Cambio de propietario de archivos y directorios
- Enlaces entre archivos y directorios
ls¶
Listado simple¶
$ ls 100_0474-dup.JPG 100_0474.JPG 1969 2007 2008 2009 2010
Listado con formato largo¶
$ ls -l total 44 -rw-rw-r-- 1 gomix gomix 33519 abr 4 07:20 aloha.png drwxr-xr-x 8 gomix gomix 4096 feb 6 09:35 fwsnort drwxrwxr-x 4 gomix gomix 4096 ene 6 17:37 ruby
Listado de archivos ocultos/nombres que comienzan con '.'¶
$ ls -a . .. 100_0474-dup.JPG 100_0474.JPG 1969 2007 2008 2009 2010 .oculto
Listado recursivo¶
$ ls -lR Photos/2007/04 Photos/2007/04: total 32 drwxrwxr-x. 2 gomix gomix 4096 ago 26 2009 02 drwxrwxr-x. 2 gomix gomix 4096 ago 26 2009 03 drwxrwxr-x. 2 gomix gomix 4096 ago 26 2009 04 drwxrwxr-x. 2 gomix gomix 4096 ago 26 2009 05 Photos/2007/04/02: total 45672 -rw-rw-r--. 1 gomix gomix 1320520 abr 2 2007 100_0627.jpg -rw-rw-r--. 1 gomix gomix 1343956 abr 2 2007 100_0628.jpg -rw-rw-r--. 1 gomix gomix 1234108 abr 2 2007 100_0629.jpg ... -rw-rw-r--. 1 gomix gomix 985560 abr 2 2007 100_0663.jpg -rw-rw-r--. 1 gomix gomix 1012308 abr 2 2007 100_0664.jpg -rw-rw-r--. 1 gomix gomix 798756 abr 2 2007 100_0665.jpg Photos/2007/04/03: total 142724 -rw-rw-r--. 1 gomix gomix 1374004 abr 3 2007 000_0001.jpg -rw-rw-r--. 1 gomix gomix 1478120 abr 3 2007 000_0002.jpg -rw-rw-r--. 1 gomix gomix 1448212 abr 3 2007 000_0003.jpg ... -rw-rw-r--. 1 gomix gomix 1228388 abr 3 2007 100_0776.jpg -rw-rw-r--. 1 gomix gomix 1536380 abr 3 2007 100_0777.jpg -rw-rw-r--. 1 gomix gomix 1478864 abr 3 2007 100_0778.jpg Photos/2007/04/04: total 87924 -rw-rw-r--. 1 gomix gomix 1318100 abr 4 2007 100_0779.jpg -rw-rw-r--. 1 gomix gomix 1158560 abr 4 2007 100_0780.jpg -rw-rw-r--. 1 gomix gomix 914528 abr 4 2007 100_0781.jpg ... -rw-rw-r--. 1 gomix gomix 1305500 abr 4 2007 100_0852.jpg -rw-rw-r--. 1 gomix gomix 1109732 abr 4 2007 100_0855.jpg -rw-rw-r--. 1 gomix gomix 1023280 abr 4 2007 100_0856.jpg Photos/2007/04/05: total 16828 -rw-rw-r--. 1 gomix gomix 1181212 mar 22 2009 100_0857.jpg -rw-rw-r--. 1 gomix gomix 1137832 mar 22 2009 100_0858.jpg -rw-rw-r--. 1 gomix gomix 1338128 abr 5 2007 100_0859.jpg ... -rw-rw-r--. 1 gomix gomix 951332 abr 5 2007 100_0869.jpg -rw-rw-r--. 1 gomix gomix 1029572 abr 5 2007 100_0870.jpg -rw-rw-r--. 1 gomix gomix 1102596 nov 28 2008 100_0871.jpg
Listado ordenado por fecha/hora¶
# ls -lt total 136 -rw-r--r-- 1 root root 425 dic 17 10:55 hypercomtote -rw-r--r-- 1 root root 512 nov 1 11:49 pmsn -rw-r--r-- 1 root root 424 oct 29 14:05 hypercomtot -rw-r--r-- 1 root root 511 oct 26 14:45 hypercomtotn -rw-r--r-- 1 root root 503 sep 1 11:43 mpn -rw-r--r-- 1 root root 506 sep 1 11:42 cuadrantebn -rw-r--r-- 1 root root 499 sep 1 11:41 taxicashorgn
Listado en orden reverso¶
# ls -ltr total 136 -rw-r--r-- 1 root root 499 sep 1 11:41 taxicashorgn -rw-r--r-- 1 root root 506 sep 1 11:42 cuadrantebn -rw-r--r-- 1 root root 503 sep 1 11:43 mpn -rw-r--r-- 1 root root 511 oct 26 14:45 hypercomtotn -rw-r--r-- 1 root root 424 oct 29 14:05 hypercomtot -rw-r--r-- 1 root root 512 nov 1 11:49 pmsn -rw-r--r-- 1 root root 425 dic 17 10:55 hypercomtote
Identificación de directorios, ejecutables y FIFOs¶
Use -F, ello añade tras cada nombre de directorio un `/', tras cada nombre de FIFO un `|', y tras cada nombre de un ejecutable un `*'.
$ ls -F gomix/ asociaciones/ Rakefile sh/ typescripts/ validaciones_new_record.sh* validaciones.sh* videos/
tree¶
(traducción/edición incompleta)
tree - lista el contenido de directorios en un formato tipo árbol.
tree [-acdfghilnpqrstuvxACDFQNSUX] [-L level [-R]] [-H baseHREF] [-T title] [-o filename]
[--nolinks] [-P pattern] [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst] [--version]
[--help] [--filelimit #] [--si] [--prune] [--du] [--timefmt format] [directory ...]
tree es un programa de listado de directorio recursivo que produce un lista de archivos indentados, colorea ala dircolors si la variable de entorno LS_COLORS está definida y la salidad es a un tty. Sin argumentos tree lista los archivos en el directorio actual. Cuando se especifican directorios, tree lista todos los archivos y directorios encontrados en cada uno respectivamente. Una vez que termine de listar, tree devuelve el la cantidad total de archivos y/o directorios listados.
Por omisión, cuando se encuentra un enlase simbólico, la ruta referida por el enlase es impresa después del nombre del enlase en el formato:
name -> real-path
Si se incluye la opción -l y el enlase simbólico refiere al directorio actual, entonces tree seguirá la ruta del enlase simbólico como si fuera un directorio real.
Opciones¶
Opciones de listado.
-a All files are printed. By default tree does not print hidden files (those beginning with a
dot `.'). In no event does tree print the file system constructs `.' (current directory)
and `..' (previous directory).
-d List directories only.
-l Follows symbolic links if they point to directories, as if they were directories. Symbolic
links that will result in recursion are avoided when detected.
-f Prints the full path prefix for each file.
-x Stay on the current file-system only. Ala find -xdev.
-L level
Max display depth of the directory tree.
-R Recursively cross down the tree each level directories (see -L option), and at each of them
execute tree again adding `-o 00Tree.html' as a new option.
-P pattern
List only those files that match the wild-card pattern. Note: you must use the -a option to
also consider those files beginning with a dot `.' for matching. Valid wildcard operators
are `*' (any zero or more characters), `?' (any single character), `[...]' (any single char‐
acter listed between brackets (optional - (dash) for character range may be used: ex: [A-
Z]), and `[^...]' (any single character not listed in brackets) and `|' separates alternate
patterns.
-I pattern
Do not list those files that match the wild-card pattern.
--prune
Makes tree prune empty directories from the output, useful when used in conjunction with -P
or -I. See BUGS AND NOTES below for more information on this option.
--noreport
Omits printing of the file and directory report at the end of the tree listing.
--charset charset
Set the character set to use when outputting HTML and for line drawing.
--filelimit #
Do not descend directories that contain more than # entries.
--timefmt format
Prints (implies -D) and formats the date according to the format string which uses the strf‐
time(3) syntax.
-o filename Send output to filename.
Opciones de archivo
-q Print non-printable characters in filenames as question marks instead of the default.
-N Print non-printable characters as is instead of as escaped octal numbers.
-Q Quote the names of files in double quotes.
-p Print the file type and permissions for each file (as per ls -l).
-u Print the username, or UID # if no username is available, of the file.
-g Print the group name, or GID # if no group name is available, of the file.
-s Print the size of each file in bytes along with the name.
-h Print the size of each file but in a more human readable way, e.g. appending a size letter
for kilobytes (K), megabytes (M), gigabytes (G), terabytes (T), petabytes (P) and exabytes
(E).
--si Like -h but use SI units (powers of 1000) instead.
--du For each directory report its size as the accumulation of sizes of all its files and sub-
directories (and their files, and so on). The total amount of used space is also given in
the final report (like the 'du -c' command.) This option requires tree to read the entire
directory tree before emitting it, see BUGS AND NOTES below. Implies -s.
-D Print the date of the last modification time or if -c is used, the last status change time
for the file listed.
-F Append a `/' for directories, a `=' for socket files, a `*' for executable files, a `>' for
doors (Solaris) and a `|' for FIFO's, as per ls -F
--inodes
Prints the inode number of the file or directory
--device
Prints the device number to which the file or directory belongs
Opciones de ordenado
-v Sort the output by version.
-r Sort the output in reverse alphabetic order.
-t Sort the output by last modification time instead of alphabetically.
-c Sort the output by last status change instead of alphabetically. Modifies the -D option (if
used) to print the last status change instead of modification time.
-U Do not sort. Lists files in directory order. Disables --dirsfirst.
--dirsfirst
List directories before files. This is a meta-sort that alters the above sorts. This option
is disabled when -U is used.
Opciones gráficas
-i Makes tree not print the indentation lines, useful when used in conjunction with the -f
option.
-A Turn on ANSI line graphics hack when printing the indentation lines.
-S Turn on ASCII line graphics (useful when using Linux console mode fonts). This option is now
equivalent to `--charset=IBM437' and may eventually be depreciated.
-n Turn colorization off always, over-ridden by the -C option.
-C Turn colorization on always, using built-in color defaults if the LS_COLORS environment
variable is not set. Useful to colorize output to a pipe.
Opciones XML/HTML
-X Turn on XML output. Outputs the directory tree as an XML formatted file.
-H baseHREF
Turn on HTML output, including HTTP references. Useful for ftp sites. baseHREF gives the
base ftp location when using HTML output. That is, the local directory may be
`/local/ftp/pub', but it must be referenced as `ftp://hostname.organization.domain/pub'
(baseHREF should be `ftp://hostname.organization.domain'). Hint: don't use ANSI lines with
this option, and don't give more than one directory in the directory list. If you wish to
use colors via CCS style-sheet, use the -C option in addition to this option to force color
output.
-T title
Sets the title and H1 header string in HTML output mode.
--nolinks
Turns off hyperlinks in HTML output.
Opciones misceláneas
--help Outputs a verbose usage listing.
--version
Outputs the version of tree.
Ejemplos de uso¶
$ tree /home/gomix/tmp/blog/test/
/home/gomix/tmp/blog/test/
|-- fixtures
| `-- posts.yml
|-- functional
| `-- posts_controller_test.rb
|-- integration
|-- performance
| `-- browsing_test.rb
|-- test_helper.rb
`-- unit
|-- helpers
| `-- posts_helper_test.rb
`-- post_test.rb
6 directories, 6 files
Impresión de marca de tiempo de modificación
$ tree -D /home/gomix/tmp/blog/test/
/home/gomix/tmp/blog/test/
|-- [Feb 14 12:03] fixtures
| `-- [Feb 14 12:03] posts.yml
|-- [Feb 14 12:03] functional
| `-- [Feb 14 12:03] posts_controller_test.rb
|-- [Feb 14 11:47] integration
|-- [Feb 14 11:47] performance
| `-- [Feb 14 11:47] browsing_test.rb
|-- [Feb 14 11:47] test_helper.rb
`-- [Feb 14 12:03] unit
|-- [Feb 14 12:03] helpers
| `-- [Feb 14 12:03] posts_helper_test.rb
`-- [Feb 14 12:03] post_test.rb
6 directories, 6 files
Ordenado por cambio de estado
$ tree -D -c /home/gomix/tmp/blog/test/ /home/gomix/tmp/blog/test/ |-- [Feb 14 12:03] unit | |-- [Feb 14 12:03] helpers | | `-- [Feb 14 12:03] posts_helper_test.rb | `-- [Feb 14 12:03] post_test.rb |-- [Feb 14 12:03] fixtures | `-- [Feb 14 12:03] posts.yml |-- [Feb 14 12:03] functional | `-- [Feb 14 12:03] posts_controller_test.rb |-- [Feb 14 11:47] integration |-- [Feb 14 11:47] performance | `-- [Feb 14 11:47] browsing_test.rb `-- [Feb 14 11:47] test_helper.rb 6 directories, 6 files
Límite de profundidad
$ tree -L 2 /home/gomix/tmp/blog/app/
/home/gomix/tmp/blog/app/
|-- assets
| |-- images
| |-- javascripts
| `-- stylesheets
|-- controllers
| |-- application_controller.rb
| `-- posts_controller.rb
|-- helpers
| |-- application_helper.rb
| `-- posts_helper.rb
|-- mailers
|-- models
| `-- post.rb
`-- views
|-- layouts
`-- posts
11 directories, 5 files
stat¶
stat muestra estado de archivo o estado de sistema de archivos.
stat [OPTION]... FILE...
Opciones¶
- -L, --dereference , sigue enlaces.
- -f, --file-system, muestra estado del sistema de archivos en vez del estado del archivo.
- -c --format=FORMAT, usa el formato especificado por FORMAT, incluye un caracter nueva línea después de cada uso de FORMAT en la salida.
- --printf=FORMAT, como --format pero interpretado como "backslashs escapes" y no incluye caracteres de nueva línea.
- -t, --terse, imprime la información en forma tersa.
- --help muestra la ayuda en línea y termina.
- --version muestra la información de versión y termina.
Especificando archivos¶
Las secuencias válidas para especificar archivos son (sin --file-system).
- %a , permisos de acceso en octal.
- %A , permisos de acceso legibles para el humano.
- %b , cantidad de bloques asignados (vea %B)
- %B , tamaño en bytes de cada bloque reportado por %b.
- %C , contexto de seguridad SELinux.
- %d , número de dispositivo en decimal.
- %D , número de dispositivo en hexadecimal.
- %f , modo crudo en hexadecimal.
- %F , tipo de archivo.
- %g , ID de grupo propietario.
- %G , nombre de grupo propietario.
- %h , cantidad de enlaces duros.
- %i , número inode.
- %m , punto de montura.
- %n , nombre de archivo
- %N , nombre de archivo "quoted with dereference" si es enlace simbólico.
- %o , tamaño de bloque I/O.
- %s , tamaño total en bytes.
- %t , tipo de dispositivo mayor en hexadecimal.
- %T , tipo de dispositivo menor en hexadecimal.
- %u , ID de usuario propietario.
- %U , nombre de usuario propietario.
- %w , fecha/hora de nacimiento del archivo, legible por el humano, - si desconocido.
- %W , fecha/hora de nacimiento del archivo, segundos desde Epoch, 0 si desonocido.
- %x , fecha/hora del último acceso, legible por el humano.
- %X , fecha/hora del último acceso, segundos desde Epoch.
- %y , fecha/hora de la última modificación, legible por el humano.
- %Y , fecha/hora de la última moficación, segundos desde Epoch.
- %z , fecha/hora del último cambio, legible por el humano.
- %Z , fecha/hora del último cambio, segundos desde Epoch.
Especificando sistemas de archivos¶
Las secuencias de formato para sistemas de archivos son:
- %a , bloques libres disponibles a los no super-usuario.
- %b , total de bloques de datos en sistema de archivos.
- %c , total de nodos archivo en sistema de archivos.
- %d , nodos archivo libres en sistema de archivos.
- %f , bloques libres en sistema de archivos.
- %i , ID del sistema de archivos en hexadecimal.
- %l , máxima longitud de nombres de archivos.
- %n , nombre de archivo.
- %s , tamaño de bloque (para transferencias más rápidas).
- %S , tamaño de bloque fundamental (para conteos de bloques).
- %t , tipo de sistema de archivos en hexadecimal.
- %T , tipo de sistema de archivos en forma legible por el humano.
NOTA: su shell puede que tenga su propia versión de stat que usualmente precede a la versión descrita aquí. Refiérase en ese caso a la documentación de su shell.
Ejemplos de uso¶
stat archivo-simple
$ stat audio.ogg
Fichero: «/home/gomix/audio.ogg»
Tamaño: 3289875 Bloques: 6432 Bloque E/S: 4096 fichero regular
Dispositivo: fd00h/64768d Nodo-i: 16922 Enlaces: 1
Acceso: (0664/-rw-rw-r--) Uid: ( 500/ gomix) Gid: ( 500/ gomix)
Acceso: 2012-12-30 22:19:37.733414123 -0430
Modificación: 2011-09-08 17:39:48.534750880 -0430
Cambio: 2011-09-08 17:39:48.534750880 -0430
Creación: -
Cambio de propietario de archivos y directorios¶
Simple
# chown gomix.gomix archivo.txt
Recursivo sobre directorio
# chown -R gomix.gomix doc/
Enlaces entre archivos y directorios¶
Enlace simbólico a un directorio:
$ ln -s Fotos Photos $ ls -ld Photos lrwxrwxrwx 1 gomix gomix 5 nov 26 12:21 Photos -> Fotos
