Вы можете написать скрипт, который выглядит следующим образом:
#/bin/bash
# using "shopt -s nullglob" so that an empty directory won't give you a literal '*'.
shopt -s nullglob
# get a sorted directory listing
filelist=$(for i in .*0* *0*; do echo "$i"; done | sort -t0 -k2)
IFS=$(echo -en "\n\b")
# iterate over your sorted list
for f in $filelist
do
# just cat text files.
file $f | grep text > /dev/null 2>&1
if [ $? = 0 ]
then
cat $f
fi
done
Тест:
[plankton@localhost SO_scripts]$ ls -l
total 40
-rw-r--r-- 1 plankton plankton 10 Sep 9 10:56 afile0zzz
-rw-r--r-- 1 plankton plankton 14 Sep 9 10:56 bfile xxx0yyy
-rwxr-xr-x 1 plankton plankton 488 Sep 9 10:56 catfiles.sh
-rw-r--r-- 1 plankton plankton 9 Sep 9 10:56 file0123
-rw-r--r-- 1 plankton plankton 9 Sep 9 10:56 file0124
-rw-r--r-- 1 plankton plankton 7 Sep 9 10:56 file0a
-rw-r--r-- 1 plankton plankton 8 Sep 9 10:56 file0aa
-rw-r--r-- 1 plankton plankton 7 Sep 9 10:56 file0b
-rw-r--r-- 1 plankton plankton 9 Sep 9 10:56 file0bbb
-rw-r--r-- 1 plankton plankton 18 Sep 9 10:56 files*_0asdf
[plankton@localhost SO_scripts]$ ./catfiles.sh
. is not a text file
.. is not a text file
Doing catfiles.sh
#/bin/bash
# using "shopt -s nullglob" so that an empty directory won't give you a literal '*'.
shopt -s nullglob
# get a sorted directory listing
filelist=$(for i in .* *; do echo "$i"; done | sort -t0 -k2)
IFS=$(echo -en "\n\b")
# iterate over your sorted list
for f in $(for i in .* *; do echo "$i"; done | sort -t0 -k2)
do
# just cat text files.
file $f | grep text > /dev/null 2>&1
if [ $? = 0 ]
then
echo "Doing $f"
cat $f
else
echo "$f is not a text file"
fi
done
Doing file0123
file0123
Doing file0124
file0124
Doing file0a
file0a
Doing file0aa
file0aa
Doing files*_0asdf
file with * in it
Doing file0b
file0b
Doing file0bbb
file0bbb
Doing bfile xxx0yyy
bfile xxx0yyy
Doing afile0zzz
afile0zzz
Обновлено в соответствии с предложением Песы .*0* *0*
.