A
A
Alexander Semenenko2017-11-13 15:47:28
linux
Alexander Semenenko, 2017-11-13 15:47:28

How can I modify a bash function so that it executes correctly?

I wrote this function:
ldirs () { du -sh `ls -F "[email protected]" | grep "/$" | sed -e 's/\/$//'`; }
It lists the directory, looks only for subdirectories, and removes the slash in the output. This list of directories is then passed to the du -sh command.
Here's how it works:
$ ldirs
49M GNS3
129K PDF
72M programm
512 Videos
26M Documents
31M Downloads
13M Pictures
512 Music
512 Public
du: cannot access 'Work': No such file or directory
du: cannot access 'table': No such file or directory
1.0K Templates
The "Desktop" directory has a space in its name and each word is passed to the du command. Here's how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2017-11-13
@semenenko88

find -maxdepth 1 -type d -not -name '.' -print0 | xargs -0 du -sh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question