But they perform the necessary syscall and that allows us to adapt the commands. Of course, all the above mentioned utilities do not exclusively create files. mktemp or tempfile ( for creating temporary files that do not need to exist between reboots !).truncate -size 0 /tmp/new_filename.txt.As mentioned, anything that can perform open(), openat() and, create() syscalls will create a file. In most shells nowadays true or : is a built-in, so doing : > /tmp/new_file is going to be more efficient, although marginally compared to touch /tmp/new_file.īut of course it does not stop there. That means, if the filename does not exist - it will be created, and if it does - the data will be truncated (and therefore gone, so > should be used with care). The > operator specifically calls the openat() system call with O_WRONLY|O_CREAT|O_TRUNC flags. Note also that a filename - is treated specially, so if you do want to create a file that is named literally -, you'll have to enclose that into single or double quotes.īy contrast, > is a shell redirection operator for stdout stream. Its original purpose is to update the access and modification time of a file, however if the file does not exist - it will be created. Most commonly new filename is created with something like this: That means if you call any command-line utility that does these system calls, you can create a new empty file. In general, creating any regular 1 file on Linux involves open(2), openat(2), and creat(2) system calls (and specifically with O_CREAT flags).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |