El touchpropósito principal del comando es manipular las marcas de tiempo de los archivos y crear archivos.
Ejemplos
1. crear archivos
$ ls -l
total 0
$ touch file{1..3}
$ ls -l
total 0
-rw-rw-r--. 1 saml saml 0 Jan 12 13:33 file1
-rw-rw-r--. 1 saml saml 0 Jan 12 13:33 file2
-rw-rw-r--. 1 saml saml 0 Jan 12 13:33 file3
NOTA: La total 0salida de ls -les correcta. Esta implementación de lsmuestra el número de bloques que utilizan los archivos cuando se enumeran. Puede asegurarse de este hecho agregando el -sinterruptor a ls. Esto enumerará los bloques en uso por cada archivo. Aquí he agregado 2 caracteres a archivo1 y archivo2.
Ejemplo
$ ls -ls
total 8
4 -rw-rw-r--. 1 saml saml 3 Jan 13 12:07 file1
4 -rw-rw-r--. 1 saml saml 3 Jan 13 12:09 file2
0 -rw-rw-r--. 1 saml saml 0 Jan 13 12:05 file3
2. información de hora / fecha de un archivo - comando stat
$ stat file1
File: ‘file1’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 11403667 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ saml) Gid: ( 1000/ saml)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2014-01-12 13:33:38.279456149 -0500
Modify: 2014-01-12 13:33:38.279456149 -0500
Change: 2014-01-12 13:33:38.279456149 -0500
Birth: -
Podemos utilizar touchpara manipular las diversas marcas de tiempo en un archivo determinado.
3. extracto de la página de manual de touch
-a change only the access time
-m change only the modification time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
4. manipulando el tiempo de acceso
$ touch -a -t200001010000 file1
$ stat file1
File: ‘file1’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 11403667 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ saml) Gid: ( 1000/ saml)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2000-01-01 00:00:00.000000000 -0500
Modify: 2014-01-12 13:33:38.279456149 -0500
Change: 2014-01-12 13:38:52.023434696 -0500
Birth: -
5. manipular modificar tiempo
$ touch -m -t200001010000 file1
$ stat file1
File: ‘file1’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 11403667 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ saml) Gid: ( 1000/ saml)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2000-01-01 00:00:00.000000000 -0500
Modify: 2000-01-01 00:00:00.000000000 -0500
Change: 2014-01-12 13:39:31.060432026 -0500
Birth: -
Tal vez se pregunte sobre el tiempo de cambio (ctime). Eso no puede ser manipulado usando touch. Eso rastrea el momento en que se tocó cualquiera de los metadatos en el archivo. Consulte estas preguntas y respuestas de U&L para obtener más detalles, titulado: ¿Qué puede hacer en un archivo sin activar la marca de tiempo "Cambiar"? .
echo -n > filename, puede ejecutar lo siguiente:>filename