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 ...
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 &...
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 ...
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/...
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
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filenames × 1182bash × 230
shell × 171
rename × 155
shell-script × 144
files × 123
linux × 118
find × 112
directory × 86
command-line × 64
wildcards × 63
filesystems × 48
quoting × 46
rm × 37
grep × 35
ls × 35
text-processing × 34
sed × 33
sort × 31
awk × 30
regular-expression × 29
scripting × 28
symlink × 26
string × 24
cp × 23