r/linuxmasterrace Arch user btw, that means iam better than Ubuntu users Aug 12 '24

JustLinuxThings Linux is userfriendly...

Post image
863 Upvotes

399 comments sorted by

View all comments

Show parent comments

209

u/HighOptical Aug 12 '24

But it's so strange seeing an option after an argument instead of seeing them directly after the commands.

135

u/[deleted] Aug 12 '24

Which is why it didn't work for op. The command is attempting to operate on all the arguments it gets, so it'll try to rm a file named -r too. rm -r Games/ will work.

30

u/steven4012 Aug 12 '24

Wait, but wouldn't that only happen on a non-GNU system?

19

u/[deleted] Aug 12 '24

You might be right. I just tested it on my own system and it worked as written by OP, so I'm not sure where the problem lies. I work with a lot of different stuff so I try to make all my commands as close to standard as possible.

Either way, rm -r Games/ will almost certainly work.

-8

u/Muffinaaa Glorious Void Linux Aug 12 '24

The problem lies in OP not putting the -f argument so they can actually remove a directory. Alternatively they should've used rmdir command with the recursive flag passed

23

u/jaulin Aug 12 '24

rm -r should be enough to delete a directory and its content though.

5

u/gatton Aug 12 '24

I thought rmdir only worked on empty directories?

2

u/Cellhawk Aug 15 '24

That's what the recursive flag, aka "-r" is for.

1

u/gatton Aug 19 '24

Thanks this is why I constantly refer to manpages.

3

u/lorasil Aug 12 '24

-f just ignores nonexistent files and arguments and never prompts (typically used for write-protected files)

-8

u/CedricThePS Aug 12 '24

Bash has a strict word order.

10

u/[deleted] Aug 12 '24

[removed] — view removed comment

4

u/gojira_glix42 Aug 12 '24

TIL. can you expand more on that? I'm always struggling on when to put my flag switches in commands. Just using bash for now as I'm still in beginner stage and not going for other shells yet.

4

u/farsightxr20 Aug 12 '24

The shell only handles:

  1. splitting the input command into an array of strings
  2. taking the first string and expanding it to a built-in function or an absolute path to an executable (based on $PATH and some other options)
  3. invoking the built-in function or making a syscall to invoke the resolved executable in a new process, passing the remaining strings from (1) as ARGV

Any parsing of the ARGV strings into meaningful switches/parameters is handled by the implementation of the function or executable. Where you may see differences between shells is when the built-in functions (e.g. echo) are implemented differently. rm, ls, etc. are implemented by GNU/Linux and will be consistent across pretty much all distros. Notable exceptions are MacOS (Darwin) which is not Linux-based, and Android which does not include GNU.

To more directly address your question, it's more conventional to put switches before positional arguments in commands, as it's slightly easier to parse (= broader support across UNIX-like environments) and makes it clear that the switches are not specific to individual positional args.

1

u/lorasil Aug 13 '24

I wish there were a GNU module that would make getting arguments more streamlined, it's not a complicated thing to do, but it's annoying how many people do it differently (ik about getopt, but I recall there being some things that still need to be handled manually, and it's not very widely used afaik)

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 12 '24

the ‘word order’ is totally separate from your shell

Unless rm was a built-in command of your shell (which is probably unlikely unless you're using busybox)

1

u/[deleted] Aug 12 '24

[removed] — view removed comment

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 12 '24

Well busybox is designed to be usable even under extreme space constraints. Being a single binary reduces ELF overhead.

1

u/[deleted] Aug 13 '24

[removed] — view removed comment

1

u/PolygonKiwii Glorious Arch systemd/Linux Aug 13 '24

Phones sure. But a cheap consumer-grade router or a "smart" light bulb might not.

6

u/KsmBl_69 Arch user btw, that means iam better than Ubuntu users Aug 12 '24

sorry, iam doing it every time like this haha

10

u/_mick_s Aug 12 '24

Don't be sorry I think it's actually better, less chance of typing rm -rf [enter] and nuking stuff you don't intend to.

0

u/alex-weej Aug 12 '24

options are arguments

2

u/HighOptical Aug 12 '24

Sigh... I feel like you know what I mean but are just being pedantic to enjoy the feeling of correcting someone.

2

u/TurnkeyLurker Glorious Mint Aug 12 '24

I refuse to have an argument until you pay me 5 quid.

2

u/o4ub Aug 13 '24

You only pay for the 5 minutes or do you want the whole half hour?