cp non-hidden files only [closed] cp non-hidden files only [closed] shell shell

cp non-hidden files only [closed]


The shell doesn't expand * to include names starting with a dot, so:

cp * /target/directory

That won't copy the .svn directory.

If that isn't your issue (e.g. you are trying to do a recursive copy with sub-directories that contain hidden files), please clarify what you are up to.


You can use ls to list all the non hidden files and copy it:

cp $(ls) destination


ls on its own will only show you non-hidden files. If you replace the echo $file command with your cp command that should work.

for file in `ls`; do echo $file; done

Something like this would work fine:

for file in `ls`; do cp $file /path/to/desitination; done

There are more complicated ways of doing this, but for your needs this seems suitable enough.

**DISCLAIMER: This does not work if there are spaces in the files names.

A fix would be just using the star wildcard. If you run echo * you'll notice that this does not expand to hidden files. Thanks to Jonathan Leffler