Respuestas:
Usa el touchcomando:
The touch utility sets the modification and access times of files to the
current time of day. If the file doesn't exist, it is created with
default permissions.
Ejemplo:
touch newfile
newfileya existe y no está vacío, touch newfilete dejará con un archivo vacío . Quizás no sea lo que querías.
newfileya existe, el touchcomando solo actualizará la marca de tiempo del archivo (que es exactamente para qué comando) sin editar el contenido del archivo.
> newfile
También creará un archivo vacío. Si el archivo ya existe, se truncará (se vaciará). Para mantener el contenido del archivo, use >>para agregar como en:
>> file
Incluso si el archivo existe, los contenidos no se modificarán.
Editar : si no tiene ningún contenido para escribir, este es más rápido:
user@host$ :> newfile
user@host$ :>> new_or_existing_file
Nota. :Es el comando aquí. No es parte del aviso.
cat /dev/null > file1.ext
la forma exacta también hay otra manera
echo "" > file2.ext
La diferencia es file1.ext será cero bytes y file2.ext sería un byte. Puedes verificar esto por
ls -l file*.*
Python one-liner:
$ python -c 'import sys,os;f=sys.argv[1];os.utime(f,None) if os.path.exists(f) else open(f,"a").close' myfile.txt
Básicamente, la implementación de Python touch.
Podemos hacerlo más corto con esto:
$ python -c 'import sys,os;f=sys.argv[1];'$'\n''with open(f,"a"): os.utime(f,None)' mysecondfile.txt
touch newfile.txto alguna otra extensión (si necesita especificar la extensión).