Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a particular column in linux df command

I am trying to collect information on the amount of space left on different servers. So when I execute df -k i get output as:

Filesystem  1024-blocks    Used     Avail Capacity  Mounted on
/dev/ad1s1f   125925198 2568970 113282214     2%    /builds

And sometimes the output comes as :

Filesystem           1K-blocks      Used Available Use% Mounted on
10.102.1.123:/storage/disk1/build
                     10735331328 10597534720 137796608  99% /buildbackup

Now I want to fetch data on the disk space available. So let me know how to fetch data from a particular column.

like image 336
Ram Krishna Avatar asked Mar 02 '15 11:03

Ram Krishna


People also ask

How do I cut a specific column in a Unix file?

1) The cut command is used to display selected parts of file content in UNIX. 2) The default delimiter in cut command is "tab", you can change the delimiter with the option "-d" in the cut command. 3) The cut command in Linux allows you to select the part of the content by bytes, by character, and by field or column.

Which command is used to select a particular column in a file?

1 Answer. The explanation: To extract specific columns from a file, we can use cut command followed by -c option and list of column numbers, delimited by a comma.


1 Answers

You can for example say:

df --output=source,avail

Or as commented by Tim Bunce, you can use --direct to prevent the long filesystem name make the line split in two. This will show the filesystem as -.

From man df:

--output[=FIELD_LIST]

use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

...

FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent' and 'target' (see info page).

--direct

show statistics for a file instead of mount point

Test

$ df --output=source,avail
Filesystem               Avail
/dev/sda7            321675536
like image 159
fedorqui 'SO stop harming' Avatar answered Sep 28 '22 05:09

fedorqui 'SO stop harming'