chraebsli@programming.dev to Programmer Humor@programming.dev · 2 年前Touch a file in Linuxprogramming.devimagemessage-square87linkfedilinkarrow-up11.2Karrow-down129
arrow-up11.17Karrow-down1imageTouch a file in Linuxprogramming.devchraebsli@programming.dev to Programmer Humor@programming.dev · 2 年前message-square87linkfedilink
minus-square4am@lemm.eelinkfedilinkarrow-up21arrow-down3·2 年前“Do one thing and do it very well” is the UNIX philosophy after all; if you’re 99% likely to just create that missing file after you get a file not found error, why should touch waste your time?
minus-squareTrailblazing Braille Taser@lemmy.dbzer0.comlinkfedilinkarrow-up35·2 年前Because now touch does two things. Without touch, we could “just” use the shell to create files. : > foo.txt
minus-squareKusimulkku@lemm.eelinkfedilinkarrow-up9·2 年前But this directly goes against that philosophy, since now instead of changing timestamps it’s also creating files
minus-squarekautau@lemmy.worldlinkfedilinkarrow-up10·edit-22 年前You can pass -c to not create a file, but it does go against the philosophy that it creates them by default instead of that being an option EDIT: Looking closer into the code, it would appear to maybe be an efficiency thing based on underlying system calls Without that check, touch just opens a file for writing, with no other filesystem check, and closes it With that check, touch first checks if the file exists, and then if so opens the file for writing
“Do one thing and do it very well” is the UNIX philosophy after all; if you’re 99% likely to just create that missing file after you get a file not found error, why should
touchwaste your time?Because now touch does two things.
Without touch, we could “just” use the shell to create files.
deleted by creator
But this directly goes against that philosophy, since now instead of changing timestamps it’s also creating files
You can pass
-cto not create a file, but it does go against the philosophy that it creates them by default instead of that being an optionEDIT: Looking closer into the code, it would appear to maybe be an efficiency thing based on underlying system calls
Without that check, touch just opens a file for writing, with no other filesystem check, and closes it
With that check, touch first checks if the file exists, and then if so opens the file for writing