Discussion:
Misunderstanding sed command
(too old to reply)
Grimble
2023-05-09 14:18:44 UTC
Permalink
Using du -d 1 to get some directory sizes, I also get many
du: cannot access.../read... messages
I thought to suppress them by piping them to sed
du -d 1 | sed '/du:/d'
but doesn't work. Am I misunderstanding the sed command?
--
Grimble
Machine 'Haydn' running Plasma 5.20.4 on 5.15.98-desktop-1.mga8 kernel.
Mageia release 8 (Official) for x86_64
David W. Hodgins
2023-05-09 15:15:25 UTC
Permalink
Post by Grimble
Using du -d 1 to get some directory sizes, I also get many
du: cannot access.../read... messages
I thought to suppress them by piping them to sed
du -d 1 | sed '/du:/d'
but doesn't work. Am I misunderstanding the sed command?
[***@x3 home]$ pwd
/home
[***@x3 home]$ du -d 1
6.0G ./dave
4.0K ./rpms
du: cannot read directory './garage/.dbus': Permission denied
du: cannot read directory './garage/.ssh': Permission denied
du: cannot read directory './garage/.gnupg': Permission denied
du: cannot read directory './garage/tmp': Permission denied
76K ./garage
du: cannot read directory './tester/.dbus': Permission denied
du: cannot read directory './tester/.local': Permission denied
du: cannot read directory './tester/.cache/chromium': Permission denied
du: cannot read directory './tester/.cache/dconf': Permission denied
du: cannot read directory './tester/.cache/gvfs': Permission denied
du: cannot read directory './tester/.cache/mozilla': Permission denied
du: cannot read directory './tester/.cache/doc': Permission denied
du: cannot read directory './tester/.pki': Permission denied
du: cannot read directory './tester/.gnupg': Permission denied
du: cannot read directory './tester/.config/chromium': Permission denied
du: cannot read directory './tester/.config/ibus': Permission denied
du: cannot read directory './tester/.config/pulse': Permission denied
du: cannot read directory './tester/.config/dconf': Permission denied
du: cannot read directory './tester/tmp': Permission denied
du: cannot read directory './tester/.mozilla/firefox': Permission denied
2.8G ./tester
8.8G .
[***@x3 home]$ du -d 1 2>/dev/null
6.0G ./dave
4.0K ./rpms
76K ./garage
2.8G ./tester
8.8G .
[***@x3 home]$

The error messages from the du command go to STDERR, not STDOUT. The sed command
is only seeing the non-error output.

With "du -d 1 2>/dev/null" the good output still goes to STDOUT, but the error
messages are suppressed by redirecting them to the null output device.

Regards, Dave Hodgins
Grimble
2023-05-09 15:56:14 UTC
Permalink
Post by Grimble
Using du -d 1 to get some directory sizes, I also get many
du: cannot access.../read... messages
I thought to suppress them by piping them to sed
du -d 1 | sed '/du:/d'
but doesn't work. Am I misunderstanding the sed command?
/home
6.0G    ./dave
4.0K    ./rpms
du: cannot read directory './garage/.dbus': Permission denied
du: cannot read directory './garage/.ssh': Permission denied
du: cannot read directory './garage/.gnupg': Permission denied
du: cannot read directory './garage/tmp': Permission denied
76K     ./garage
du: cannot read directory './tester/.dbus': Permission denied
du: cannot read directory './tester/.local': Permission denied
du: cannot read directory './tester/.cache/chromium': Permission denied
du: cannot read directory './tester/.cache/dconf': Permission denied
du: cannot read directory './tester/.cache/gvfs': Permission denied
du: cannot read directory './tester/.cache/mozilla': Permission denied
du: cannot read directory './tester/.cache/doc': Permission denied
du: cannot read directory './tester/.pki': Permission denied
du: cannot read directory './tester/.gnupg': Permission denied
du: cannot read directory './tester/.config/chromium': Permission denied
du: cannot read directory './tester/.config/ibus': Permission denied
du: cannot read directory './tester/.config/pulse': Permission denied
du: cannot read directory './tester/.config/dconf': Permission denied
du: cannot read directory './tester/tmp': Permission denied
du: cannot read directory './tester/.mozilla/firefox': Permission denied
2.8G    ./tester
8.8G    .
6.0G    ./dave
4.0K    ./rpms
76K     ./garage
2.8G    ./tester
8.8G    .
The error messages from the du command go to STDERR, not STDOUT. The sed command
is only seeing the non-error output.
With "du -d 1 2>/dev/null" the good output still goes to STDOUT, but the error
messages are suppressed by redirecting them to the null output device.
Regards, Dave Hodgins
Ahhhh! Of course.
Thanks
--
Grimble
Machine 'Haydn' running Plasma 5.20.4 on 5.15.98-desktop-1.mga8 kernel.
Mageia release 8 (Official) for x86_64
Michael Wood
2023-05-09 15:31:54 UTC
Permalink
sed is acting on stdout, but the errors get written to stderr. You can
re-direct stderr to stdout, to get the sed to work using:
du -d 1 2>&1 | sed '/du:/d'
Post by Grimble
Using du -d 1 to get some directory sizes, I also get many
du: cannot access.../read... messages
I thought to suppress them by piping them to sed
du -d 1 | sed '/du:/d'
but doesn't work. Am I misunderstanding the sed command?
red floyd
2023-05-11 01:05:15 UTC
Permalink
sed is acting on stdout, but the errors get written to stderr.  You can
du -d 1 2>&1 | sed '/du:/d'
OP doesn't want the stderr. So the previously discussed

du -d 1 2> /dev/null | sed '/du:/d'

is the proper answer here.
William Unruh
2023-05-11 22:43:25 UTC
Permalink
Post by red floyd
sed is acting on stdout, but the errors get written to stderr.  You can
du -d 1 2>&1 | sed '/du:/d'
OP doesn't want the stderr. So the previously discussed
du -d 1 2> /dev/null | sed '/du:/d'
is the proper answer here.
Except all of the lines with du: in them are from stderr, not stdout.
so
du -d 1 2> /dev/null
would be enough. However there might be other lines in stderr that he
wants to see. Certainly his post says he only wanted to get rid of the
lines with du: in them.
red floyd
2023-05-12 22:08:11 UTC
Permalink
Post by William Unruh
Post by red floyd
sed is acting on stdout, but the errors get written to stderr.  You can
du -d 1 2>&1 | sed '/du:/d'
OP doesn't want the stderr. So the previously discussed
du -d 1 2> /dev/null | sed '/du:/d'
is the proper answer here.
Except all of the lines with du: in them are from stderr, not stdout.
so
du -d 1 2> /dev/null
would be enough. However there might be other lines in stderr that he
wants to see. Certainly his post says he only wanted to get rid of the
lines with du: in them.
Agreed.

William Unruh
2023-05-09 16:46:05 UTC
Permalink
Post by Grimble
Using du -d 1 to get some directory sizes, I also get many
du: cannot access.../read... messages
log on as root and try again. They are probably permission problems. If
not, they your disk is probably terminally failing.
Post by Grimble
I thought to suppress them by piping them to sed
du -d 1 | sed '/du:/d'
Those error messages come out on stderr rather than stdout. Only the
latter is piped to sed so sed never sees the error messages.
If you wnat to get rid of them
du -d 1 2>/dev/null
which sends stderr ( output track 2) to dev/null.
Post by Grimble
but doesn't work. Am I misunderstanding the sed command?
No You are misunderstanding stderr and stdout.
Loading...