1183
Touch a file in Linux (programming.dev)
top 50 comments
sorted by: hot top controversial new old
[-] bjoern_tantau@swg-empire.de 133 points 7 months ago

Does anyone actually use touch for its intended purpose? Must be up there with cat.

[-] funkajunk@lemm.ee 94 points 7 months ago
[-] TheBat@lemmy.world 73 points 7 months ago

Wtf. All these years I thought 'touch' was reference to Michelangelo's Creation of Adam.

[-] funkajunk@lemm.ee 45 points 7 months ago

That's beautiful, bro 🥲

[-] BestBouclettes@jlai.lu 89 points 7 months ago* (last edited 7 months ago)

The intended use of touch is to update the timestamp right?

[-] bjoern_tantau@swg-empire.de 100 points 7 months ago

Yeah. It could just as well have issued a file not found error when you try to touch a nonexistent file. And we would be none the wiser about what we're missing in the world.

[-] 4am@lemm.ee 21 points 7 months ago

“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?

[-] 0x0@lemmy.dbzer0.com 35 points 7 months ago

Because now touch does two things.

Without touch, we could "just" use the shell to create files.

: > foo.txt
[-] deegeese@sopuli.xyz 21 points 7 months ago

Touch does one thing from a “contract” perspective:

Ensure the timestamp of is

[-] dan@upvote.au 14 points 7 months ago

Systemd also does one thing from a contract perspective: run your system

load more comments (2 replies)
[-] stebo02@lemmy.dbzer0.com 19 points 7 months ago

with this logic, any command that moves, copies or opens a file should just create a new file if it doesn't exist

and now you're just creating new files without realising just because of a typo

load more comments (2 replies)
[-] BestBouclettes@jlai.lu 9 points 7 months ago

If you touch -c it should work I guess

[-] zurchpet@lemmy.ml 33 points 7 months ago

We use it to trigger service restarts.

touch tmp/service-restart.txt

Using monit to detect the timestamp change and do the actual restart command.

load more comments (2 replies)
[-] tubaruco@lemm.ee 21 points 7 months ago

what is cat's use if not seeing whats inside a file?

[-] Navigate@lemmings.world 61 points 7 months ago

It is short for concatenate, which is to join things together. You can give it multiple inputs and it will output each one directly following the previous. It so happens to also work with just one input.

[-] kautau@lemmy.world 10 points 7 months ago
[-] 0x0@lemmy.dbzer0.com 49 points 7 months ago
[-] kautau@lemmy.world 9 points 7 months ago
load more comments (1 replies)
load more comments (1 replies)
load more comments (1 replies)
[-] ulterno@lemmy.kde.social 28 points 7 months ago

It is to use along with split. e.g.

  1. You take a single large file, say 16GB
  2. Use split to break it into multiple files of 4GB
  3. Now you can transfer it to a FAT32 Removable Flash Drive and transfer it to whatever other computer that doesn't have Ethernet.
  4. Here, you can use cat to combine all files into the original file. (preferably accompanied by a checksum)
load more comments (2 replies)
[-] magic_lobster_party@kbin.run 21 points 7 months ago

I sometimes use cat to concatenate files. For example, add a header to a csv file without manually copy and paste it. It’s rare, but at least more frequent than using touch.

[-] wewbull@feddit.uk 19 points 7 months ago
$ cat file1 > output_file
$ cat file2 >> output_file
$ cat file3 >> output_file

I'm sorry!

load more comments (1 replies)
[-] marcos@lemmy.world 14 points 7 months ago

When you updated a Django server, you were supposed to touch the settings.py file so the server would know to reload your code. (I haven't used any for a long time, so I don't know if it's still the procedure.)

There are many small things that use it.

load more comments (1 replies)
[-] NotSteve_@lemmy.ca 13 points 7 months ago

I used it recently to update the creation date of a bunch of notes. Just wanted them to display in the correct order in Obsidian. Besides that though, always just used it for file creation lol

[-] noproblemmy@programming.dev 12 points 7 months ago

cat

Ahhhhh, fuck. I'm quite noob with linux. I got into some rabbit hole trying to read the docs. I found 2 man pages, one is cat(1) and the other cat(1p). Apparently the 1p is for POSIX.

If someone could help me understand... As far as I could understand I would normally be concerned with (1), but what would I need to be doing to be affected by (1p)?

load more comments (2 replies)
[-] starman2112@sh.itjust.works 10 points 7 months ago

I don't know anything about Linux but I do love touching cats

load more comments (1 replies)
[-] Trainguyrom@reddthat.com 9 points 7 months ago* (last edited 7 months ago)

Touch is super useful for commands that interact with a file but don't create the file by default. For example, yesterday I needed to copy a file to a remote machine accessible over ssh so I used scp (often known as "secure copy") but needed to touch the file in order to create it before scp would copy into it

[-] emptiestplace@lemmy.ml 9 points 7 months ago

Sorry, what?

load more comments (10 replies)
[-] dubyakay@lemmy.ca 53 points 7 months ago

These are some weird looking dolph--- oh

[-] xmunk@sh.itjust.works 48 points 7 months ago

Remember to confirm consent before touching.

[-] IsoSpandy@lemm.ee 64 points 7 months ago

You can only touch in places where you have permission to touch.

[-] lseif@sopuli.xyz 24 points 7 months ago
[-] sukhmel@programming.dev 41 points 7 months ago

Iseif is not in the sudoers file. This incident will be reported.

[-] Zozano@lemy.lol 47 points 7 months ago

images-2

Same energy as Joan Cornella's comics

[-] Schorsch@feddit.de 13 points 7 months ago
[-] null@slrpnk.net 41 points 7 months ago

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

[-] gamma@programming.dev 36 points 7 months ago

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

[-] ezchili@iusearchlinux.fyi 15 points 7 months ago
[-] 48954246@lemmy.world 21 points 7 months ago* (last edited 7 months ago)

Feels dangerous to run. What happens if the file already exists and has something important in it?

touch -a is probably better

[-] gaterush@lemmy.world 9 points 7 months ago

The other command could just be printf '' >> file to not overwrite it. Or even simpler >>file and then interrupt

[-] owsei@programming.dev 10 points 7 months ago

or :>>file then you don't need to interrupt

load more comments (5 replies)
load more comments (8 replies)
[-] RustyNova@lemmy.world 29 points 7 months ago

I'm way to used to doing nano file.txt that I always forget about touch.

Although most times, if I create a file, it's to put something in it

[-] debil@lemmy.world 10 points 7 months ago

If you need multiple files for testing a script or such: touch file{1..5}.txt

load more comments (1 replies)
load more comments (3 replies)
[-] makingStuffForFun@lemmy.ml 16 points 7 months ago

As a Linux user, that is truly magical, and beautiful.

load more comments
view more: next ›
this post was submitted on 17 Mar 2024
1183 points (100.0% liked)

Programmer Humor

19512 readers
167 users here now

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

founded 1 year ago
MODERATORS