Tuesday, June 29, 2010

list all files which have space in them in bash and sort

The most simple-minded way of doing this would be
ls "* *"
but this would not work. This site notes the way to do it - with find:
find ~ -name '* *'
And also lists a neat way of looping through,
find ~ -name '* *' while read FILE;
do
echo $FILE ;
done

The problem is that this lists files in non-alphabetical order. To get it in alphabetical order, The Alphabetizer is available for one-time jobs like my php suggest list. For piping in bash, of course, we can use sort:
find ~ -name '* *' | sort

No comments:

Post a Comment