Linux - Padding zeros using printf command

By xngo on June 17, 2019

Example below shows how to pad zeroes to a number using printf command. It will pad zeroes to the number until the total length is 5.

number=13
printf "%05d" ${number}
 
echo
 
number=12345
printf %05d ${number}

Output

00013
12345

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.