Advertisement
B1KMusic

Command breakdown / ps aux | grep gedit explained

Oct 26th, 2014
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. Breakdown of "ps aux | grep gedit"
  2.  
  3. 'ps' is the actual program/application
  4.  
  5. 'aux' is actually a set of three flags, a, u, and x. You could order them any way you want, such as "xua", but since "aux" is the most pronounceable (like the word "auxiliary", pronounce "awks" or "awgs", or just "a-u-x"), it's easier to remember it that way.
  6.  
  7. You could also write it as "ps xua" (or other variants), "ps -aux", or "ps -a -u -x". But since ps is one of those awesome programs that lets you put flags without the dash (another such program is tar, e.g. "tar xf file.tar.gz", which will extract any tar file, whether it's .tar, .tgz, .tar.gz, .tar.xz, or .tar.bz2. Go ahead and try it next time you wind up with a tar file on a linux system), "ps aux" is the nicest choice. Remember that, too; whenever you see a command like "df -h -i -u -o -v" (df is a real command, but half of those flags are made-up. You can expect h (human-readable) and v (verbose output) to work, though), you can combine all the flags together into a "flag clump", the following command is equivalent: "df -hiuov"
  8.  
  9. From the man page:
  10.  
  11. a: select all processes.
  12.  
  13. x: something about a "BSD-style must-have-tty restriction" (tty is TeleTYpe, or the "fresh install of arch linux terminal" I was talking about earlier. Access via Ctrl+Alt+F[1-6], get back to GUI via Ctrl+Alt+F7, sometimes F8), so I take it this flag is just use to prevent errors on weird/idiosyncratic systems.
  14.  
  15. u: select by user id, rather than weird stuff like daemons and terminals. I'm not completely sure what this does, actually, or why not including it will fail to bring up gedit's process.
  16.  
  17. '|' is a pipe. It's used to redirect output to input, so you can chain commands together in neat ways.
  18.  
  19. In this case, the output of 'ps aux' is being redirected to the program, grep. Grep's name is funny. It comes from an old perl expression used commonly to search for text using regular expressions, and print it out. That is, g/[re]/p, where g means "global", re means "regex", and p means "print".
  20.  
  21. This actually works in vim. You initiate like a normal command, via ':'. Type in some gibberish like "dfggsdkljdhfl" on multiple lines, then include one or two lines that say something coherent, like "hello" on one line and "hallo" on the other, and then, from normal mode, enter :g/h.llo/p
  22.  
  23. You will get the following or similar output:
  24. :g/h.llo/p
  25. 6 hello
  26. 8 hallo
  27.  
  28. So now you can start to see how grep works. Grep is a whole lot simpler, though. Because this use of regex was so common, someone decided to just make a program that does it by default, and thus the name is grep. You could also just remember it by mentally linking it to that one episode of Game Grumps, when Arin randomly says "next time on grep", and then Barry draws a title card for it after Jon laughs about it. That's strangely how I remember it.
  29.  
  30. Anyways, the use of grep is as follows:
  31.  
  32. $ grep regex file
  33.  
  34. Where file is the file you want to rummage through, and regex is the search term, or regular expression, that you want to find in the file. Grep is neat because in addition to finding and printing each (and only) line, it highlights the match found in red.
  35.  
  36. That's all well and good, except nobody ever uses grep like this. Even I forgot the order of the arguments and had to guess in the terminal to make sure it was right (it wasn't, which is why file is explained first in the description--I was too lazy to reorder the description). The way most people use grep is in a pipe. some command or output | grep regex.
  37.  
  38. And that's where 'gedit' comes in. It's the search term.
  39.  
  40. So here's some actual output of that whole line (ps aux | grep text , since my current system doesn't have gedit, but scratch instead)
  41.  
  42. $ ps aux | grep text
  43. braden 4876 0.0 0.9 157328 18064 ? Sl 09:50 0:01 scratch-*text*-editor
  44. braden 5434 0.0 0.0 4412 784 pts/8 R+ 10:43 0:00 grep --color=auto *text*
  45.  
  46. As you can see, the pid of scratch-text-editor (although I was using gedit as an example, it was actually scratch) is 4876, so you could do some interesting stuff with that, like '$ kill -s STOP 4876' to freeze it, and the same command but with CONT instead of STOP to unfreeze it.
  47.  
  48. Also, the attentive reader will know from the above output that I currently have a lot of terminals open. At least eight of them. Can you guess where that information is?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement