Can I Create a Universal Modifier for Commands in Linux?

0
3
Asked By CuriousCoder42 On

Hey everyone! I'm pretty new to Linux/Unix, and I have this idea about creating a general modifier (like --rep) that could make commands behave more uniformly. For example, I'd love to be able to append output from multiple commands in one line without repeating the command each time, kind of like how "touch file1 file2 file3" works. Here are some examples I was thinking of:

1. `cat --rep text1 >> texta.txt text2 >> textb.txt text3 >> textc.txt`
2. `mount --rep /dev/sdb /mnt/usb1 /dev/sdc /mnt/usb2 /dev/sdd /mnt/usb3`
3. `ip --rep a r l`

If this is feasible and wouldn't take months to implement, I'd love a confirmation and maybe a couple of resources to help me dive deeper. Thanks a bunch!

1 Answer

Answered By TechieTom On

A few things to consider here:

1. Try to avoid using `cat` unnecessarily! For example, you can use `lsblk >> blocks.txt` directly. For chaining commands, use `&&` like this: `lsblk >> blocks.txt && lspci >> pcis.txt`.

2. Different commands have their own options. If you need to mount everything in your fstab file, `mount -a` does the trick without needing a modifier. It's usually better to use commands as they were designed rather than trying to create a workaround.

3. The UNIX/Linux philosophy encourages building small, specific tools that do one job really well. This way, you can chain them together effectively. Sure, you could squeeze multiple `ip` commands into one, but it might just create a confusing wall of text instead of clarity.

LearningLizard -

(1 - I totally forgot about those ls* commands for a moment. Thanks for the reminder.)

I tend to input commands repetitively with just slight variations, since I'm still getting the hang of things and often find myself troubleshooting instead of just using commands. I guess I was hoping for a way to streamline that process, but it sounds like I'm better off sticking to learning the commands the right way. Appreciate the reality check!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.