Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
chraebsli ( chraebsli@programming.dev )  to Programmer Humor@programming.dev · 3 years ago

Touch a file in Linux

programming.dev

message-square
44
link
fedilink
672

Touch a file in Linux

programming.dev

chraebsli ( chraebsli@programming.dev )  to Programmer Humor@programming.dev · 3 years ago
message-square
44
link
fedilink
  • null ( null@slrpnk.net ) 
    link
    fedilink
    arrow-up
    27
    ·
    3 years ago

    Is there a command that’s actually just for creating a new file?

    • Gamma ( gamma@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      20
      ·
      3 years ago

      Nope. If you open a nonexistent path and you have permissions to write to that directory, then that file is created.

    • ezchili ( ezchili@iusearchlinux.fyi ) 
      link
      fedilink
      arrow-up
      9
      ·
      3 years ago

      I guess printf “” > file

    • Midnitte ( Midnitte@beehaw.org ) 
      link
      fedilink
      English
      arrow-up
      8
      ·
      3 years ago

      I mean, nano filename will work, but there’s no mkfile that I can find…

      $>filename would also work, but it’s not explicitly for creating a new file

    • tranzystorekk ( tranzystorek_io@beehaw.org ) 
      link
      fedilink
      English
      arrow-up
      6
      ·
      3 years ago

      most shells will accept outputting from a silent command to a file, e.g. :> foo.txt (where : is the posix synonym to the true command)

    • dan ( dan@upvote.au ) 
      link
      fedilink
      arrow-up
      4
      ·
      3 years ago

      How often do you actually need a blank file though? Usually you’d be writing something in the file.

      • null ( null@slrpnk.net ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        I’m betting that’s why none ever materialized. Most tools that can manipulate a file, can also create that file first, so there’s just never been a usecase.

        Right-clicking the desktop to create a new txt file in Windows feels so natural, but I can’t really think of any time you’d want to create a new file and do nothing with it in a CLI.

        • schnurrito ( schnurrito@discuss.tchncs.de ) 
          link
          fedilink
          arrow-up
          3
          ·
          3 years ago

          You might if some other program checks whether that file exists and behaves differently depending on that.

          • null ( null@slrpnk.net ) 
            link
            fedilink
            arrow-up
            1
            ·
            3 years ago

            But even still, what’s a realistic usecase that would that involve needing a blank, unmodified file in that instance?

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 361 users / day
  • 2.81K users / week
  • 4.1K users / month
  • 7.7K users / 6 months
  • 463 local subscribers
  • 33.7K subscribers
  • 1.56K Posts
  • 25.6K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code