Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 12, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/cc41ab02c75fa55a2cf9679df4f26523 to your computer and use it in GitHub Desktop.
Save YumaInaura/cc41ab02c75fa55a2cf9679df4f26523 to your computer and use it in GitHub Desktop.
Linux — Play with ASCII sort order by ls command

Play with ASCII sort order by ls command

Ref

http://www.asciitable.com/

Example script

create various kind of files

mkdir -p ./names

touch './names/"'
touch './names/#'
touch './names/+'

touch './names/...'
touch './names/....'

touch './names/0'
touch './names/1'
touch './names/2'

touch './names/ALICE'
touch './names/bob'
touch './names/CAROL'
touch './names/david'
touch './names/Eric'
touch './names/fred'

cd ./names/
ls -la -1
cd ../

rm -rf ./names

We found some files comes before current directory . and above directory.. . No we understood "dot directories" are nothing special, they just listed by ASCII order.

Output Exampple

"
#
+
.
..
...
....
0
1
2
ALICE
CAROL
Eric
bob
david
fred
Play with ASCII sort order by ls command
https://gist.github.com/YumaInaura/cc41ab02c75fa55a2cf9679df4f26523
#!/bin/bash -eu
# ## Ref
# http://www.asciitable.com/
# ## Example script
# create various kind of files
mkdir -p ./names
touch './names/"'
touch './names/#'
touch './names/+'
touch './names/...'
touch './names/....'
touch './names/0'
touch './names/1'
touch './names/2'
touch './names/ALICE'
touch './names/bob'
touch './names/CAROL'
touch './names/david'
touch './names/Eric'
touch './names/fred'
cd ./names/
ls -la -1
cd ../
rm -rf ./names
# We found some files comes before current directory `.` and above directory`..` .
# No we understood "dot directories" are nothing special, they just listed by ASCII order.
"
#
+
.
..
...
....
0
1
2
ALICE
CAROL
Eric
bob
david
fred
#!/bin/bash -eu
bash ascii.sh | tee ascii.sh.log
rm -f ..UNDERSTAND.md
echo "# " $(cat .gist.title.txt) >> ..UNDERSTAND.md
script2md ascii.sh >> ..UNDERSTAND.md
echo '## Output Exampple' >> ..UNDERSTAND.md
echo '```' >> ..UNDERSTAND.md
./ascii.sh >> ..UNDERSTAND.md
echo '```' >> ..UNDERSTAND.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment