Colorized /etc/passwd
Here’s a script that will display all the information in the /etc/passwd file, with each type of value (username, UID, GID, home directory, and shell) colorized differently:
awk -F: '{printf "\\033[1;34m%-10s\\033[0m \\033[1;32m%-5s\\033[0m \\033[1;35m%-5s\\033[0m \\033[1;33m%-25s\\033[0m \\033[1;31m%s\\033[0m\\n", $1, $3, $4, $6, $7}' /etc/passwd
Explanation:
- awk uses the “:” as a field separator to split the values in the /etc/passwd file.
- printf statement is used to format and display the output.
- \033[1;34m is the escape code for blue color
- \033[1;32m is the escape code for green color
- \033[1;35m is the escape code for purple color
- \033[1;33m is the escape code for yellow color
- \033[1;31m is the escape code for red color
- \033[0m is the escape code for resetting the color
You can customize the script to use different colors and format the output as you prefer.
![](https://itvraag.nl/wp-content/uploads/2023/01/user-mgmt-bash-943x1024.jpg)
Note that the script will only work on systems that use the traditional UNIX /etc/passwd file format.
Colorized log files
Here’s a script that will display the /var/log/dpkg.log file, with each type of value (date, action, package name) colorized differently:
awk '{printf "\\033[1;36m%-22s\\033[0m \\033[1;32m%-8s\\033[0m \\033[1;35m%s\\033[0m\\n", $1, $2, $4}' /var/log/dpkg.log
Explanation:
- awk uses the default field separator (space) to split the values in the /var/log/dpkg.log file.
- printf statement is used to format and display the output.
- \033[1;36m is the escape code for cyan color
- \033[1;32m is the escape code for green color
- \033[1;35m is the escape code for purple color
- \033[0m is the escape code for resetting the color
You can customize the script to use different colors and format the output as you prefer.
![](https://itvraag.nl/wp-content/uploads/2023/01/awk-colored-log-1.jpg)
Note that the script is only going to work on systems that use the dpkg package manager, and only if the dpkg.log file is in the default location(/var/log/dpkg.log), if you are using other package manager or the file is located in another location, you need to adjust the path accordingly.