Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible we can run some command on some particular folder so that we can't file type except image in that folder ?

share|improve this question
How would the system detect if the file is acceptable or not ? – jlliagre Oct 18 '10 at 7:35

No, this is not easy to do. You can restrict permissions so that only files of certain ownership or execute/read/write permissions can be written, but discriminating on file type is not something most unix file systems do.

I suggest you will need to implement this at the programmatic level. Either in the software that you allow access with (for example FTP often has restrictions based on mime types) or in some type of control daemon that checks your users input for validity you can check out the contents.

If you post your exact case scenario we might be able to suggest and appropriate way of handling this, but for now all we can say is that this is not a standard way of adding restrictions. There probably is an appropriate tool for the job, but we need to know the job first.

share|improve this answer
I know that we can handle it during the development... but just want to be extra safe... by making the folder restricted to accept only say .jpg, .png etc – Amit Aggarwal Oct 20 '10 at 13:03
Wanting to be extra safe is a good thing, keep thinking like that. I would just suggest that the best way to be safe is to understand and follow conventions on a given platform. Unix doesn't make any particular distinction about file type, and unlike in windows file names are NOT indicative of what they contain or do. A png of puppies could be called spam_people.exe and an exactable binary file that sends emails could be called puppy_photo.png. The important part is what unix DOES do, set very exact permissions at the user, group and system levels. – Caleb Oct 20 '10 at 13:18

The easy solution would be to have a daemon check periodicaly the output of file(1) and erase anythng not of the desired file type.

share|improve this answer
A cron job would be easier to implement than a daemon. – dunxd Oct 18 '10 at 9:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.