Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Add number to variable size in Bash

I am trying to find the size of a folder, and add 1M to it. The 1M is just spacing that I need for other reasons.

Here is what I have tried:

echo $($(du -sh myFolder) + 1) # command not found: 170M
echo $(`du -sh myFolder` + 1)  # same as above

I want to be able to save this to a variable so I can use it in a dd call.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

echo $(($(du -sb myFolder | cut -f1)+1048576))

du -sb gives a single sumarized result in bytes.

over 4 years ago · Santiago Trujillo Report

0

Alternatives if you can't use -b as Joao Morais suggested:

expr `du -hs myFolder | awk '{print $1}' | tr -d M` + 1

echo $((`du -hs myFolder | awk '{print $1}' | tr -d M` + 1))
over 4 years ago · Santiago Trujillo Report

0

Yet another way:

BLOCKSIZE=1048576 du -s myFolder | awk '{print $1+1}'

or to put in a variable:

mbs=$(BLOCKSIZE=1048576 du -s myFolder | awk '{print $1+1}')

Works on Linux, BSD, and OS X (possibly others).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!