Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the filename from the end of the du -h output

Tags:

linux

sed

awk

take the example:

$ du -h file_size.txt
112K file_size.txt

How would i remove the filename from the output of du -h

I have tried to use sed to search for a string (the filename) and replace it with nothing, but it hasnt worked (command below)

du -h file_size.txt | sed 's/ 'file_size.txt'//'

Could someone please point out why this wont work, or perhaps a better way to do it?

Regards

Paul

like image 282
paultop6 Avatar asked Feb 11 '10 19:02

paultop6


2 Answers

du -h file_size.txt | cut -f1
like image 120
Tomalak Avatar answered Oct 05 '22 05:10

Tomalak


You have some bad quoting in that command line. The simplest is probably:

du -h file_size.txt | cut -f -1

To fix your command line:

du -h file_size.txt | sed 's/file_size.txt//'

Since your post has an awk tag:

du -h file_size.txt | awk '{ print $1 }'
like image 27
Carl Norum Avatar answered Oct 05 '22 04:10

Carl Norum