As of May 31, 2023, we have updated our Code of Conduct.
3 votes

Sort a list of filenames such that files in subdirectories are listed before files in the parent directory

Here a simple way: awk 'BEGIN{FS="/"; OFS="\t"}{print NF, $0}' file | sort -rn | cut -f2- A1/B1/file A2/file A1/file file Should works for simple cases, like your question. If ...
Gilles Quénot's user avatar
2 votes
Accepted

Copy multiple files by filenames in subdirectories in linux

The -name test accepts a POSIX filename generation pattern, so find . -name "file[156].txt" For more complex cases, tests may be chained with the logical conjunction -o find . \( -name &...
steeldriver's user avatar
  • 77.4k
2 votes
Accepted

Sort a list of filenames such that files in subdirectories are listed before files in the parent directory

zsh has the od glob qualifier to order glob expansions depth-first, $ print -rC1 -- **/file(Nod) A2/file A1/B1/file A1/file file That can be applied to an arbitrary list of files, if that list of ...
Stéphane Chazelas's user avatar
1 vote

Sort a list of filenames such that files in subdirectories are listed before files in the parent directory

To expand on the insights of @Kusalananda, if indeed these filenames are the complete contents of an extant directory tree, find can do what you want: Given: $ find . ./f2 ./A1 ./A1/B1 ./A1/B1/f2 ./A1/...
Jim L.'s user avatar
  • 7,045
1 vote

How to copy files from a list without extension to a different folder?

Okay, I got the solution, for file in $(<01cBC.txt); do cp "$file".* 01cBC; done; Thanks
Debajyoti Kabiraj's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible