I have a directory containing several sub-directories, containing files.
I would like to sort the files in each of these directories by name alphabetically and copy the first file from each directory to a given new directory.
- I would like to ignore hidden files.
- If there is a file with the same name in the destination directory, both files should be kept.
parentdir ->dir1 ->afile ->bfile ->cfile ->dir2 ->dfile ->efile ->ffile ->dir3 ->afile ->hfile ->ifile
I would like to run a command that would populate my new directory like so:
newdir ->afile ->afile.1 ->dfile
How can this be accomplished?