I have a directory setup very nicely(i.e organized with READMEs and easy navigation etc.). I would like people to be able to access the files in this directory maybe even copy them to their own directory (on the same computer) but I don't want my own directory to get shaken up/messed up or else everything could get ruined. Is there anyway to put a lock on certain commands within my directory, or is there anyway of putting a lock on certain files?

For example somebody should be able to move through the space freely like this:

$ cd ThisDirectory
$ cd ThatDirectory

But they shouldn't be able to move these files like this:

$ mv ThisDirectory
$ mv ThatDirectory

Is there anyway to put a lock on the mv command for specific files?

  • 5
    Just don't give others write permissions to them? Aug 18, 2015 at 17:47

1 Answer 1


Simply change permissions of the files in a way everyone could read them, but not alter them.

When you use ls -l to list your files, you get something like

    ls -l file
    -rw-rwxr--    1 rafael   Grp      1620 Aug 18 14:58 file

That first set of dashes/letters sets the permitting of three distinct (but not exclude each other) groups, namely User (you), Group, Others (or everyone in this machine/server).

So the example above may be read as

    -            It's a file
     rw-         Owner may read and write
        rwx      Others in group may read, write and execute
           r--   Other users (not in group) may read

To prevent anyone from changing your files set them with

    chmod go-w file

This will set them to be not writable by anyone besides you

    ls -l file
    -rw-r-xr--    1 rafael   Grp      1620 Aug 18 14:58 file

Let me dive into these dash/letters:

    -rw-rwxr--    1 rafael   Grp      1620 Aug 18 14:58 file

The first one indicates the file type (directory, symlink, named pipes). Then there are three sets of three symbols, each set is composed of one r (for read), one w (for write), and one x (for execute), or their positions filled by a dash, if that permission is disabled.

Your directories should have the same permissions, with the addition of "execute" for all users ("executing" a directory means accessing any entry within it). If your directories are writable, the entries in it may be deleted or renamed.

In the command chmod, there are three parts as well go (means group and others), the '-' (minus sign) is to remove (permission) and them came the (list of) rights to change


    chmod u-wx file    # prevent you reading the file or executing it
    chmod u+wx file    # permit you to read nte file or execute it
    chmod ug+rx file   # permit you and your group to read or execute it
    chmod ugo-rwx file # permit no access, for anybody

One last note

chmod also supports -R, for recursion, so if you have a directory called myDir:

    chmod -R go-w myDir  # protect everything in that directory and its sub directories/files
    chmod -R go+rX myDir # grant reading access in that directory and its sub directories/files

Should do the trick.

Thanks for asking, and I hope it could help others as well!

  • Oh, thanks @Toby Speight, for your great edits.
    – Rafareino
    Aug 19, 2015 at 19:26

You must log in to answer this question.

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