← Back to context

Comment by diarrhea

2 months ago

No thank you...

One of the primary things shells are supposed to excel at is file system navigation and manipulation, but the experience is horrible. I can never get `cp`, `rsync`, `mv`, `find` right without looking them up, despite trying to learn. It's way too easy to mess up irreversibly and destructively.

One example is flattening a directory. You accidentally git-cloned one too deep, into `some/dir/dir/` and want to flatten contents to `some/dir/`, deleting the then-empty `some/dir/dir/`. Trivial and reversible in any file manager, needlessly difficult in a shell. I get it wrong all the time.

Similarly, iterating over a list of files (important yet trivial). `find` is arcane in its invocation, differs between Unix flavors, you will want `xargs` but `{}` substitution is also very error-prone. And don't forget `print0`! And don't you even dare `for f in *.pdf`, it will blow up in more ways than you can count. Also prepare to juggle quotes and escapes and pray you get that right. Further, bash defaults are insane (pray you don't forget `set -euo pipefail`).

How can we be failed by our tools so much, for these use cases? Why aren't these things trivial and safe?

I agree that certain commands require some effort to learn, but I would not include `cp` or `mv` in that list.

  • I have trouble gauging the effects of `*`, aka "will I cp/mv the dir or all contents of the dir"? Then shell expansion getting in the way, like expanding it all ("argument list too long"). I try to use rsync when possible, where intermittent `.` in paths are relevant, as well as trailing slashes... and don't forget `-a`! Then I forget if those same things apply to cp/mv. Then I cp one directory too deep and need to undo the mess -- no CTRL+Z!

    The wide-spread use of `rm -rf some-ostensibly-empty-dir/` is also super dangerous, when `rm -r` or even `rmdir` would suffice, but you need to remember those exist. I find it strange there's no widely (where applicable) available `rm-to-trash`, which would be wildly safer and is table stakes for Desktop work otherwise.

    Then there's `dd`...

    I use terminals a lot, but a GUI approach (potentially with feedback pre-operation) plus undo/redo functionality for file system work is just so much easier to work with. As dumb as drag-and-drop with a mouse is, a single typo can't wreck your day.

    • If using dd for messing with filesystems and partitions, then I don't know how much more a gui will save you. Its an inherently scary task that needs some thinking first. Personally, that stuff always scares me gui or not.

What is there to get wrong in your flattening dir example? I'd mv the internal dir as some other name to outside say dir2, them rm rf outer and mv the dir2. Unless there is something wrong in this approach.

I would agree with the rest, I always have to look up find and xargs syntax.

  • If you make a typo, it'll go wrong. This is something that file managers fundamentally do not suffer from when trying to do that operation

    • You've never mis-dragged something in the GUI or had a flaky mouse button which lets up randomly while you're dragging which left your folder "somewhere" that you now have to find?

      1 reply →

    • `rm` is a destructive operation, but you can always alias it to move it to a trash folder.

      File managers have nowhere near the flexibility available in the terminal.

   can never get `cp`, `rsync`, `mv`, `find` right without looking them up

Wow! You have the brain really fried by not using it if you have issue using these simple command without help.

I would double down on advising you to go back learning to use the roots before getting IDE or llm assistant...

  • Interesting attack on my person!

    The things I want to get done on my computer are so much richer than moving files back and forth in a terminal all day. Simple things should be simple. Tools should enable us. Moving files is a means to an end and these commands having so many sharp edges makes me unhappy indeed.

    But yes, of course I am an IDE toddler and cannot even tie my shoes without help from an LLM, thanks for reminding me.

Most of the commands you've mentioned have worked fairly well for me. Are you sure you're looking up cp, mv and find every time before using them? Sounds pretty weird.

With fish, `for f in *.pdf` Just Works™.

  • This is also a crutch. Take the time to learn the kludgier tool. It will make you a better developer.

    /s (I'm a big fan of fish)

    • Terminal emulators are a crutch you kids are spoiled by. In my day we had to create programs on punch cards. Copy a file from one directory to another? fifteen cards full of custom assembler code. Print out a file listing on the teletype? Ten cards... uphill... in the snow... both ways.

      /s (no, not really)

LLMs make all those commands trivial to learn. Back in the day we had to study whole man pages meant as reference. Like keeping attention for minutes at a time. The horror!

  • You read the manpages once and then if you're some super elite user you create some aliases for yourself.

    Or if you are me, you do `history | grep name-of-command` to find the last time you used it and edit that haha