How to copy only non-hidden files (GNU/Linux)

Simple!
Go to the source directory and execute the following command.


cp -iv --parents `find . -type f | regexmatch '.*/\..+' 1` -t TARGET

TAREGT is the target directory.

For this you need regexmatch and ruby. You can install ruby via apt-get install ruby and regexmatch can you download from here.

Explanation:

As first find SRC -type f lists all files from the source directory and forward it to regexmatch by a pipe (the "|" bar). As second regexmath '.*/..+' 1 removes all files from the list, which path contains a part that starts with a dot (means its hidden). Then copy all these files to TARGET and create their parent directories.

There is the dot "." in find because then all paths returned, now starting with this dot, which is a special link to the current directory. So if you copy ./file.txt from the source directory to the target directory it will copied from ./file.txt (where . means the source directory) to targetdir/./file.txt (where the dot refers to target dir). Genius.

 

Edit: find -not -iname ".*"  (?)

Christoph Schulz

Christoph Schulz
I am Dev. Maybe.

Packaging Fractal as DEB 1/?

Nothing happend here for some time, so let's write something. :)Because I am crazy I decided trying to package Fractal (Gnomes's GTK Matr...… Continue reading