I want to constantly see last 30 lines of code "nfc list ruleset" in Debian Bash. Something like this:
watch -n 1 nft list ruleset | tail -n 30 But above code doesn't show last 30 lines of "nfc" command output, it shows blank screen.
I found solution while typing question
watch "bash -c 'sudo nft list ruleset | tail -n 30'" just:
watch -n 1 'nft list ruleset | tail -n 30' Most watch implementations these days invoke a shell to interpret the concatenation of their arguments as shell code as if using eval. Some have a -x options to cut the middle man and run the command directly so
So:
watch foo bar is actually the same as:
watch -x sh -c 'foo bar' And your:
watch "bash -c 'sudo nft list ruleset | tail -n 30'"
Is like:
watch -x sh -c "bash -c 'sudo nft list ruleset | tail -n 30'" With that bash invocation totally unnecessary as sh can do piping just as well as bash and generally more efficiently.
You might want to make it:
sudo watch 'nft list ruleset | tail -n 30' Rather than:
watch 'sudo nft list ruleset | tail -n 30' even if watch or tail don't need superuser privileges to avoid the sudo overhead at each iteration (and filling up your audit logs).
doesn't work... error message? no ouput? wrong output? too much output? hangs? something else?