-1

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.

1
  • please update the question to expand on what you mean by doesn't work ... error message? no ouput? wrong output? too much output? hangs? something else? Commented Dec 12, 2023 at 18:28

2 Answers 2

0

I found solution while typing question

watch "bash -c 'sudo nft list ruleset | tail -n 30'" 
0

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).

1
  • OK. That's definitely better answer. Commented Dec 12, 2023 at 18:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.