I'm trying to create a Bash shell script that allows for the transfer of files from a flash device to a archive in which the user will specify. Although I'd like to restrict this user from not being able to create any sub-directories in this archive directory.

NOTE: So in essence, I want the archive directory that the user creates/specifies to be a flat one-level structure.

I don't have the first clue how to achieve this and would appreciate any help that I can get.

  • Can you try rephrasing this a bit? You're going to create a flat directory structure w/ no sub-directories when you copy files to the flash drive?
    – slm
    Oct 6, 2014 at 13:02
  • Yes, please rephrase this. Are you asking how to allow a user to write files to a directory but not allow them to create any sub-directories?
    – terdon
    Oct 6, 2014 at 13:28
  • Yes I would like the users to be able to copy to the directory but not allow them to create a sub directory. Sorry if the question was a bit sketchy.
    – Michael
    Oct 6, 2014 at 13:42
  • @Michael - does that read correctly still? Feel free to edit it if not.
    – slm
    Oct 6, 2014 at 15:01

1 Answer 1


There isn't any native mechanism to easily achieve it. Linux's permission system cannot specify separate permissions for creating files and directories because directories are files in fact. But try such way:

  1. Make all archive directories to be owned by a one (or few different) user, created just for this purpose. Lets assume its name archiveuser.
  2. Make all archive directories (I guess you have many) to be owned by this user, in.ex.:

    $ chown archiveuser:archiveuser /somedir/archivedir1
    $ chown archiveuser:archiveuser /somedir/archivedir2
    $ chown archiveuser:archiveuser /somedir/archivedir3
  3. Restrict access to archive dirs to be accessed only for owner:

    $ chmod 700 /somedir/archivedir1
    $ chmod 700 /somedir/archivedir2
    $ chmod 700 /somedir/archivedir3
  4. Use sudo mechanism to give cp command access to archive dirs:

    add to /etc/sudoers:

    someuser1 ALL=(archiveuser) NOPASSWD:/bin/cp /path/to/pendrive/* /somedir/archiveuser/*
    someuser2 ALL=(archiveuser) NOPASSWD:/bin/cp /path/to/pendrive/* /somedir/archiveuser/*

    Of course it is convenient to make proper group for all users that should be allowed to use this command. Read sudo tutorial :-).

  5. That's all. Users have to use:

    $ sudo -u archiveuser cp /path/to/pendrive/somefile /somedir/archiveuser/ 

You may create some alias to make it more convenient to use (i.e. alias cpt='sudo -u archiveuser cp'). Notice also that cp -r that is necessary to copy a directory is not allowed by sudo in this case. Also mkdir command is prevented by permissions. Thus your goal is achieved.


You must log in to answer this question.

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