Linux – Disk Utilization [ du ]

Background

Let us quickly discuss using “Disk Utilization“, du, to list disk utilization on a Linux System.

BTW, we will be targeting folder level information.

Options

Tabulated

Option Option Short Form Option Long Form Sample
Human Readable -h –human-readable K – Kilobytes
M – Megabytes
G – Gigabytes
T – Terabytes
Total -c –total du –total
Summarize -s –summarize du -s
du –summarize

Sample

Human Readable

Command


du -h *  2>/dev/null

Output

Total

Objective

  1. List sizes for the following folders and at the tail end list aggregated size, as well
    • db2inst1/sqllib/acs
    • db2inst1/sqllib/db2tss

Command


du -c db2inst1/sqllib/acs db2inst1/sqllib/db2tss 2>/dev/null | more

Output

Summarize

Summarize for specific folders

Objective
  1. Summarize sized for the following folders
    • db2inst1/sqllib/acs
    • db2inst1/sqllib/db2tss
Command

du -s db2inst1/sqllib/acs db2inst1/sqllib/db2tss 2>/dev/null | more

Output

Summarize for all folders

Objective
  1. Summarize all sub-folders
Command

du -s * 2>/dev/null | more

Output

Summarize for all folders and Ordered

Objective
  1. Summarize all sub-folders
  2. And, order the results
Command

du -s * 2>/dev/null | sort -nr

Output

References

  1. Lifewire
    • How To Find How Much Disk Space A File Or Folder Uses In Linux
      Link
  2. Stack Exchange
    • Listing directories based on size from largest to smallest on single line
      Link

Linux – Finding Text in Log Files – Day 1

Background

Don’t really spend much time in the Linux World.

But, there are many Application Servers that sit on Linux Servers and rely on SQL Server on Windows.

 

Log Files

When error occurs a good Application Server write these errors in Log Files.

After a while needs develop to trend the type of DB Connectivity and more serious hard errors.

 

Sample Log Files

As we discussed in a recent post, we copied over SQL Server Error Log files over to Linux.

 

Text Search

grep

Let us use grep to perform simple Text Searches.

Scenario

Look for Text Matching Manufacturer

Script

grep -w -i -l -n  "Manufacturer" ERRORLOG

Output

Explanation
  1. No matches

 

Remediation

Attempted Workarounds

We tried the following workarounds

  1. Worked
    • Created a much simple text file and was able to grep against it
  2. Did Not Help
    • Modified copy over mode to binary and back to text
    • Command Issued
      • cat ERRORLOG | grep -i “manufacturer”

 

Worked

Code


cat ERRORLOG | tr -d '\000' | grep -i "manufacturer"

Output

Why does it work

  1. Cat
    • Outputs a file’s content
  2. tr – stands for translate
    • tr -d ‘\000’
      • -d means delete
      • \000 means null character

Crediting

What makes grep consider a file to be binary?
Link

When you are top 13% on stackexchange, you are one of the Big Boys and Girls.