Last active
February 2, 2024 16:42
-
-
Save v2keener/537250058bb7d46468175a9021b3f97f to your computer and use it in GitHub Desktop.
list files with size as kilobytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# "input field separator" (IFS) to newline (0x0a) | |
IFS=$'\n' | |
# for i in | |
# tail result of `ls -lt` except the first line | |
for i in $(ls -lt | tail -n $(echo "$(ls -lt | wc -l) - 1" | bc) ) | |
do | |
size=$(echo "$(echo $i | awk '{print $5}') / 1024" | bc) | |
file=$(echo $i | awk '{print $9}') | |
echo "$size KB $file" | |
done | |
# IFS back to bash default of '[space][tab][newline]' | |
# For zsh this would be $' \t\n\0', as bash with '[null]' at the end | |
IFS=$' \t\n' # for bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment