Difference between pages "Piping" and "Analysis"

From Linuxintro
(Difference between pages)
imported>ThorstenStaerk
(New page: The most fascinating thing about Unix is how the following works together: * the way Unix treats streams * the paradigm "everything is a file" * the paradigm "do one thing and do it well" ...)
 
imported>ThorstenStaerk
 
Line 1: Line 1:
The most fascinating thing about Unix is how the following works together:
+
What analysis can you do with Linux:
* the way Unix treats streams
 
* the paradigm "everything is a file"
 
* the paradigm "do one thing and do it well"
 
  
Let's start with the most basic program: cat. cat inputs a "stream" and outputs a "stream", nothing else. Find it out like this:
+
* you can [[disassemble]] a program to find out what it does
poochy:~ # cat
+
* you can trace a compiled program to find out what syscalls it calls with [[strAce]]
Hello, I am typing a line
+
* you can trace a [[shell script]] to find out what [[commands]] it calls by adding set -x at the script's beginning
Hello, I am typing a line
+
* you can do [[network sniffing]]
After typing cat with no parameters, you can ''input'' a line (followed by ENTER). cat does nothing but ''output'' the line again. You end your input with CTRL_D. Standard for your input is the keyboard, standard for a program's output is the console.
+
* you can do [[usb bus sniffing]]
  
'''''How can this be useful?'''''
+
= See also =
 
+
* [[areAs]]
This can be extremely useful. E.g. take the paradigm "everything is a file". So you can replace your ''input stream'' by a file using a parameter:
 
cat ''readme.txt''
 
outputs the content of ''readme.txt'' to the console. So you can display a file.
 
 
 
Or you can redirect cat's output ''stream'' to a file using the > operator:
 
cat > myfile.txt
 
Allows you to (over)write directly the file ''myfile.txt''.
 
 
 
Or you can redirect the output of cat to the input of another command using the | (pipe) operator:
 
cat myfile.txt | cat
 
is equivalent to cat myfile.txt.
 
 
 
'''''How can this pipe be useful?'''''
 
 
 
There is a command to search a string in a stream (yes, or in a file, because everything is a file), called grep.
 
grep needle
 
takes an input stream and echos only those lines containing the string "needle":
 
poochy:/usr # grep needle
 
haystack
 
hay
 
more hay
 
even more hay
 
needle
 
needle
 
again hay
 
some more hay
 
 
 
Now if we combine cat and grep, we get
 
cat * | grep needle
 
"*" stands for "all files". This command searches in all files for the string "needle" and outputs the files that contain it. Just FYI, this is equivalent to
 
grep "needle" *
 
because, as said, you can hand over files to grep.
 

Latest revision as of 13:24, 13 November 2013

What analysis can you do with Linux:

See also