1

I have a folder which located as /home/makgun/Desktop/a\ b so that

I tried this command mv /home/makgun/Desktop/a\ b/* /home/makgun/Desktop/a\ b/.* to rename all files as .FILENAME to be hidden but it didn't work also it deleted all files ( Fortunately, I tried this command with "try folder" and I copied 2 files to this folder. But after this command they are deleted not hidden)

So, What I need to type in command line to hide all files in a folder.

  • You have to make a "for loop". Sorry I'm not at my computer so I can't give you the exact command. – Zalmy Jul 9 '15 at 23:47
  • 1
    cd to the target directory, " for f in *; do mv $f .$f ; done" – Zalmy Jul 10 '15 at 0:00
  • Yes this works but if filename has space character it doesn't work. ( there is a file which is called as A file it has space character) How do I do for this type of file? – makgun Jul 10 '15 at 0:10
  • 1
    Enclose the "$f" and ".$f" in quotes. – Zalmy Jul 10 '15 at 0:17
  • 1
    @Zalmy Thanks zalmy for your quick response. – makgun Jul 10 '15 at 0:20
1

This is done using a for loop.

Navigate to the target directory. Then run the command below

for f in *; do mv "$f"  ".$f" ;  done
  • I wondered that how I can back to unhide? Because it will be necessary for me after 1 month. – makgun Jul 10 '15 at 11:32
2

To unhide the files use for f in .*;do mv "$f" ${f:1}; done.

Test it first just to make sure it doesn't break anything.

Explanation for f in .* creates a loop of all the files starting with . to parse the . I used ${f:1} bash substring function.

Thank you

  • 1
    By the way, to test, use for f in .*; do echo mv "$f" "${f:1}"; done. It is a good practice to test your scripts like that. Then, you can write done | bash instead of done. – theoden Jul 17 '15 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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