Super User is a question and answer site for computer enthusiasts and power users. 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

I had a virus or something on my computer that set the attributes for all the folders in the root of my external drive to system and hidden, and created shortcuts to them. I am now trying to remove these attributes all at once with the following command, but it doesn't do anything:

dir /ash /b | attrib -h -s

According to my understanding of the documentation of these commands, this should work. Is there something wrong here?


share|improve this question
up vote 1 down vote accepted

Yes. The pipe | redirects program 1's output to program 2's input. However, your program 2 – attribdoes not read any input. It wasn't written to do so. Instead, it expects file names in its command line.

Most Unixes have a tool called xargs to handle such cases of converting text input into command-line arguments. (Most Unixes also have a tool called find to handle this specific case of applying a command recursively, too. (Most Unixes also have a chmod command that has a "recursive mode" option, too, but I guess this is of little relevance here.))

On Windows, without xargs, you will have to do something like:

for/f "tokens=*" %f in ('dir/b/ash') do @attrib -r -h -s "%~f"

Or maybe:

for/r . %f in (*) do @attrib -r -h -s "%~f"
share|improve this answer
What a roundabout way of doing things! attrib supports recursion natively, see keltari's answer. – Karan Feb 5 '13 at 2:01
Thanks for the explanation as to why it doesn't work. I will try your suggestions. On the other hand, I could also just use my linux machine to do this, although I am not exactly sure how the windows attributes will translate into a linux environment, For instance, this particular thing is not a problem when I just connect the drive to my linux machine (because of the .filename used for hidden folders in unix) – Merwe Feb 5 '13 at 5:39

Actually you can do it in a much easier fashion

attrib e:\*.* -s -h /s

Will remove all the system and hidden attributes starting at the root of the e: drive and all its subdirectories

the /s tells attrib to process subdirectories.

share|improve this answer
Can also add /d if the directories have been affected as well. – Karan Feb 5 '13 at 2:01
I also considered this option, but only the directories were affected, and only in the root of the drive. I suppose it could not do any harm do do it this way, other than changing the attributes for files that needs to stay hidden and system. I could also use the attrib command on the folders individually, but of course that will take a long time. I was just frustrated that it didn't work although I figured it should. – Merwe Feb 5 '13 at 5:35

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.