0

I have this question in an assignment but can't figure it out.

Question:

In your commands history search for the use of the command ls and append them in the file /home/<your_home_director>/history.txt

Thanks

0

you can use history |grep ls > ~/history.txt for more info regarding grep you can use man grep for pipe you can read https://www.geeksforgeeks.org/piping-in-unix-or-linux/

| improve this answer | |
  • "... and append them ..." -- you probably want >> instead of >. – Andy Dalton Oct 18 at 16:10
  • 1
    ... you'd probably want something more specific than grep ls as well – steeldriver Oct 18 at 16:25
  • perhaps 'egrep '^(ls|/bin/ls) ' to catch on ls commands – doneal24 Oct 18 at 16:42
  • Note that this would also extract any command that used the string ls as an argument, like for example in the command grep ls (ls is not use as a command here). – Kusalananda Oct 18 at 16:53
  • @doneal24 how often do you routinely type /usr/bin/ls instead of ls? I think the comment was more about avoiding matches of ls to irrelevant phrases like death knells (and no, that's not in my history either, but it's a point of illustration) – roaima Oct 18 at 17:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.