Comment on mv *.jpg is complete bullshit.
mindbleach@sh.itjust.works 9 months agoIt’s literally just mv *.jpg /mnt/Example/Pictures
.
Multiple StackOverflow answers take this as read.
mv ./*.jpg /mnt/Example/Pictures
works fine, though, so thank you for the practical solution. I’m still disgusted there’s any filename that gets treated as… not a filename. That broken stair might be older than I am.
GenderNeutralBro@lemmy.sdf.org 9 months ago
Ahhh. That’s a confusing thread, with a couple confounding factors.
The OP in that thread is attempting to a batch rename, which is out of scope of the
mv
command.If you are NOT trying to change the name of the file, I recommend always making the last argument of
mv
your destination directory, rather than the destination file. This is strictly mandatory if you are moving multiple files.OP in that SO thread used the filename as the destination path — a filename which did not exist, and therefore could not be resolved by the wildcard. And if it had existed, the move would have failed. Because of that,
mv /data/*/Sample_*/logs/*_Data_time.err /data/*/Sample_*/logs/*_Data_time_orig.err
is not a valid command.OP cannot accomplish what they want with a single
mv
command. They would need to use a loop or something likefind
.I agree that the lack of universal consistency in how commands handle arguments is unfortunate. There’s no way around that without reinventing the entire OS. Many commands let you pass ‘–’ as an argument to signify that any subsequent arguments should not be interpreted as options even if they begin with ‘-’. But that’s entirely up to the implementation of each program; it’s not a shell feature.
Future OS designers: consider typed arguments. Abandon all legacy cruft.
mindbleach@sh.itjust.works 9 months ago
Disagree. If wildcard expansion is not a feature of the tool, it shouldn’t be up to the tool to shape how each expanded input is passed. Some hideous escape syntax ought to force
*.jpg
to appear as“-a.jpg”
instead of-a.jpg
, once it reachesmv
.Instead
*
is acting as a cheeky littlels
alternative, minus any degree of formatting control, and piping actualls
input intomv
is similarly fraught with complications.GenderNeutralBro@lemmy.sdf.org 9 months ago
The issue here is that there’s no difference here between
-a.jpg
and“-a.jpg”
.Go ahead and try these commands. They are 100% equivalent:
The reason these are equivalent is because quoting (and expansion, and globbing) is processed in the shell. The shell then passes the evaluated string as an argument to the tool. All of those evaluate to the same string, so they look exactly the same to the
ls
command.What is the solution if there’s a file name that matches something the tool thinks is an argument? What would the correct behavior be?
The only solution is to include some way to communicate to the tool what each argument is. In practice, you could do
ls – *
and it would work even if the first filename was “-laR”. However, not all tools use the–
convention. This is really core to the design of the OS, in that command arguments have no type.mindbleach@sh.itjust.works 9 months ago
Jesus. That’s beyond Javascript levels of “helpfully” reinterpreting strings. That’s borderline Excel behavior.
What is the point of strings allowing every character besides
\0
if they’re gonna eat quotation marks?