Need to disable options from a command

Hi,

I am working on a Linux machine.
I need to disable 2 options from the available 6 options of a command.
For eg. in the "ls" command we have various options like "l ,r, t, a, .... "
From this, I need to disable option "a"

So when the users type in "ls -a", they should get an error or option not available. However when the type "ls -l", they should be able to see the long listing normally.

Is this possible? I don't have root access but can work with the Linux admins to disable the world execute permission on the command and have a script or something similar to enable only the required options.

Any help will be appreciated.

For starters, you would probably want to create an alias for the original command, which in turn would point to a function that could evaluate the parameter options/choices to produce the exclusive error you are looking for.

For what purpose? Not showing them their config files won't prevent them from having access every other way, such as finding them with find, matching them with shell globbing, finding them with tab completion, etc, etc, etc. The forced hiding could also be abused: Users could create files starting with . and nobody would find them.

What is your actual goal?

@Corona688 - I am not going to disable the options for "ls" command. I am just using this one as an example. I need to do it for some other command where a particular application server is being stopped by using a command which also has options to list down other some details which the users still might want to use.

in /etc/profile or the .profile of some selected users:

alias somecmd='/path/to/myscript'
#!/bin/ksh
# myscript: dummy wrapper for somecmd
#  disallow -l
echo "$@" grep -q  '-l'
if [ $? -eq 0 ]  ; then
   echo 'illegal option'
   exit 1;
fi
/full/path/to/somecmd "$@"

This is bare bones, you need to work it up to what you need. One fault: if the user knows that /full/path/to/somecmd works he/she might use it that way - it will bypass the alias.

1 Like