create an empty file
Make a new empty file, empty an existing one, or make a file with a few lines in it.
danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.
Steps
-
touch file.txtmake it if it is not there; else just update its date
-
> file.txtmake it, or empty it if it is there
-
truncate -s 0 file.txtdanger empty a file, even one a program has open
-
echo 'one line' > file.txtmake it with one line in it
-
printf 'line 1\nline 2\n' > file.txtwith several lines
Commands used
touchtruncateprintf
Each has a page in lore: lore touch opens it.
Related recipes
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- change permissions of a folder and everything in itGive a folder, its subfolders and its files the permissions or the owner they need, without making them open to everyone.
- check a file's permissionsSee who may read, write and run a file or a folder, and why a path is refused.