So I want to create an alias called changeAllPermisions that accepts one parameter argument in such a way that when changeAllPermissions argument is called , both Group and Other do not have access to read, write or execute argument. If argument is a directory, then the permissions will be changed to argument as well as everything inside recursively.

Here is what I know

I know how to create an alias, for example

alias myAlias=ls

I also know how to list files recursively

ls -R

To change the permissions as stated by my problem, I would do

chmod go-rwx

But I´m having a hard time putting all this together.

Any help is appreciated.

Thanks friends.

2 Answers 2


chmod already has a recursive flag (-R). From the manpage:

   -R, --recursive
          change files and directories recursively

So, if you wanted a function to do this for you, you could write something like

function myFunc() {
    chmod -R go-rwx -- "$1"

Or an alias:

alias myAlias='chmod -R go-rwx'

I haven't tested this, but off the top of my head this is what I came up with:

alias changeAllPermissions='chmod -R go-rwx $1'

The -R option changes permissions recursively.

  • What does $1 do? What difference does it make not to include it? the other person who replied didn't include it
    – Haz
    Sep 13, 2015 at 3:45
  • $1 is a variable representing the first argument being passed to the alias. For example: mv ~/myfile ~/backupfile ~/myfile, being the first argument would be represented by '$1'. ~/backupfile would be represented by '$2'. I'm guessing he left it out by mistake because otherwise it wouldn't work. Sep 13, 2015 at 4:42
  • Actually I tried without it, and it worked
    – Haz
    Sep 13, 2015 at 4:52
  • Good to know. I'm still learning. Sep 13, 2015 at 5:18
  • You're mixing up functions and aliases. When defining an alias, the arguments are put at the end; $1 will be whatever is the shell's positional parameter at the time the alias is expanded (in many situations, this will happen to be empty, so your alias will happen to work). @Haz the $1 is just a mistake in Graham's answer. Sep 13, 2015 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .