Question:
in ubuntu/linux, what does history | grep h do?
╚ Blue Bro ♫
2012-09-20 07:53:37 UTC
Explain piping to me?
Three answers:
Blake
2012-09-20 08:12:44 UTC
Typing "history | grep h" will bring up all of your command history that contains and "h" anywhere in the command.



Examples:

sudo shutdown -h now

bash vsftp.conf

cd /home/



Using the pipe "|" is like adding additional commands together in one sitting. In this example, first the kernel will perform a history of your commands, then it will grep that output and search for the character "h". So instead of seeing both transactions you only see the one. I'm not sure how may times you're limited to piping your commands, but I would guess it's not very limited. Play with it and see for yourself. Also read the man pages for each command you use. There is no man page for the "|" however :P
anonymous
2012-09-20 08:11:48 UTC
history will list the commands recently typed into the terminal.



grep will search the data you give it for a particular character or string of characters.



The pipe tells the system that you want to pass (pipe) the output from history to grep.



In this case grep is searching for anything that used h. Which in my case was everything in history.



Try some other letters or strings and you can see grep just gives you the matches:



history | grep his

history | grep z

history | grep py
anonymous
2014-08-05 00:55:09 UTC
complicated problem research onto yahoo just that could help


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...