Last active
August 8, 2023 03:13
-
-
Save naranyala/ec55aeb676929d1dd4c6e6ef623e3b9e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Function to display the folder structure with colorized sizes using tree command, awk, and sed | |
display_folder_structure() { | |
local dir_path="$1" | |
tree -ah --du "$dir_path" | awk ' | |
$2 ~ /K/ || $2 ~ /M/ || $2 ~ /G/ || $2 ~ /T/ || $2 ~ /P/ || $2 ~ /E/ || $2 ~ /Z/ || $2 ~ /Y/ || $2 ~ /B/ { | |
print $0 | |
} | |
' | sed -E 's/(.*[[:digit:]]+)K/\o033[34m\1K\o033[0m/g; s/(.*[[:digit:]]+)M/\o033[32m\1M\o033[0m/g; s/(.*[[:digit:]]+)G/\o033[31m\1G\o033[0m/g; s/(.*[[:digit:]]+)T/\o033[35m\1T\o033[0m/g; s/(.*[[:digit:]]+)P/\o033[36m\1P\o033[0m/g; s/(.*[[:digit:]]+)E/\o033[33m\1E\o033[0m/g; s/(.*[[:digit:]]+)Z/\o033[35m\1Z\o033[0m/g; s/(.*[[:digit:]]+)Y/\o033[36m\1Y\o033[0m/g; s/(.*[[:digit:]]+)B/\o033[34m\1B\o033[0m/g' | |
} | |
# Check if an argument is provided for the directory path | |
if [ $# -eq 0 ]; then | |
dir_path="." | |
else | |
dir_path="$1" | |
fi | |
# Call the function to display the folder structure | |
display_folder_structure "$dir_path" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment