18.04.2024, 16:40 UhrDeutsch | English
Hallo Gast [ Registrierung | Anmelden ]

What you should know to understand the answers in the forums!

And what lies beyond ...

This page introduces users with some basics in Linux to
concepts they might need to set up and use Kanotix's features.

For example: to change from S.u.S.E to Debian .
People in transition from using mouse clicks to using the command line can find a lot of concepts which, possibly, may not be understood in the beginning.

Information found in the forum can always be compared or related to this page.

Redirection of the output of a command with > or >> to a file

All programs have the ability to send output to the terminal. That happens, for instance, when they react to an input, when an error occurs, or for actions whose results are sent to a logfile.

They normally do this in one of two ways:
  • Standard output (0)
  • Standard error output (2)

The > character is used to redirect the output.
  • a > character (over)writes the output in an (existing) file.
  • two consecutive > characters, >>, allows appending the output to an already existing file.

In both cases, the file will be created if it does not exist.

Example 1:
$ Command > ResultOfCommand.txt 
The Standard output from the Command will be written in the "ResultOfCommand.txt" file, and all the existing data in it will be overwritten.

Example 2:
$ Command >> ResultOfCommand.txt 
The Standard output from the Command will be appended to the "ResultOfCommand.txt" file, and the existing data in it will not be overwritten.

Redirection of standard error output:
To redirect an error output, you will put the appropriate input (here 2) before the > character, so that only the warning output will be redirected. The standard output will continue to appear on the terminal.

Example 1:
$ Command 2> ./OutputFromCommand.txt' 
The Error output of the command will be saved in the OutputFromCommand.txt" file, and all contents previously in the file will be overwritten.

Example 2:
$ Command 2>>./OutputFromCommand.txt 
The Error output of the command will be appended to the OutputFromCommand.txt" file, and all contents previously in the file will not be overwritten.

Redirection of standard & standard error output:

To redirect both outputs, we use the &1 characters.
Example 1:
$ Command 2>&1 > OutputFromCommand.txt' 
The Error output of the command will be saved in the OutputFromCommand.txt" file, and all contents previously in the file will be overwritten.

Example 2:
$ Command 2>&1 >> OutputFromCommand.txt 
The Error output of the command will be appended to the OutputFromCommand.txt" file, and all contents previously in the file will not be overwritten.

Other options are possible. Consult the man pages of bash or sh.
man bash


The Pipe |

The pipe character can be obtained with the hot-keys "AltGr+<>". The pipe is used to send the output of a command, directly to a second command for additional processing.

(Some keyboards the | symbol is created by "shift and selecting the key \ which has what appears to have two short dashes above the \ )
$ Command1 | Command2 


Example 1:
$ locate bin | grep aMule 
In this example, the command locate bin is invoked, but its output will not be displayed on the screen. Instead it will be forwarded directly to a second command, grep aMule. The forwarded data will serve as input for that second command.

The output that will be displayed on the screen is the output from the second command, grep aMule. In this case it will only display one line, in which the search string "aMule" occurs.


Commands to run at each boot

Many programs are started every time Kanotix is booted, to do certain things, like linking devices or starting the x-server, to name just a few.

Eventually, you might want to start other programs, as well, at each boot. Editing the /etc/init.d/bootmisc.sh file offers that opportunity.

As the file cannot be modified by everybody (otherwise, the hackers would be laughing their heads off), it has to be modified by root.

So open a terminal, and open the file with the following command:
$ sudo vi /etc/init.d/bootmisc.sh 
and add at the end of it the command or call that will start the program. The sudo command allows a normal user to start certain programs with root privileges, without having to know the password.

You also have the possibility, naturally, to login as root.


Searching files with an expression (search string)

We often can find files with specific search strings or expressions. grep is used for that purpose.

grep looks through the files with the given string and then displays the corresponding line which contains the string being searched.

Example 1:
$ grep Hello ./HelloWorld.txt 
In this example, the word "Hello" will be searched for in the file "HelloWorld.txt". If the text "Hello World" is found in the file, the output will look like this:
$ Hello World
$ 
There is also the possibility to do a search with specified strings called Regular Expressions?.

Example 2:
$ grep ^Hello ./HelloWorld.txt 
grep displays all the lines which start with the word "Hello". This is achieved with the input of the ^ (caret character) at the beginning of the words being searched. With the $ character, you can search all lines where the corresponding string is at the end of the line.

Example 3:
$ grep World$ ./HelloWorld.txt 
You can find further help for grep and regexp in the man pages:
$ man grep 
$ man regexp 




locate - Searching for files

Debian has a very awesome tool named locate.

When a user is looking for a file, he can use the command
locate bin
and obtain in a jiffy a list of all files, whose (full) name, (including its path), contains the search string bin. This speed is only achieved because locate uses a database it creates, and that must be updated every now and then with the command updatedb (as the root user).



Command line text editor: vi

My favorite editor to tweak configuration files (very practical and it displays syntax in colour). Three modes are available: the viewing mode upon opening the program, the editing mode, and using the ESC key to toggle between modes. The editing mode is to some degree self-explanatory, and in the viewing mode commands are available, such as:


:q ........exit vi (when the file has not been modified)
:q! ......exit, without saving the changes made to the file
:wq ....save the changes, then exit vi (write, quit)
dd ......erase the active line
5dd ...erase the active line and the 4 following ones
x ........erase the active character (like "remove", not like backspace)
r 8 ......substitute the active character with an 8
/mnt ..search for "mnt" (gradual as you type "mnt"). All further "mnt" can be found using "n"


I can't tell you much more about vi. When you find yourself with strange results from a bad command, and are not sure how to get out of there, press ESC until you find yourself back in viewing mode.



searched
XML Revisions of $tag
Seiten-History :: Letzter Editor : Richard :: Eigentümer : OffTopic ::
Powered by pnWikka 1.0
 
 
Deutsch | English
Logos and trademarks are the property of their respective owners, comments are property of their posters, the rest is © 2004 - 2006 by Jörg Schirottke (Kano).
Consult Impressum and Legal Terms for details. Kanotix is Free Software released under the GNU/GPL license.
This CMS is powered by PostNuke, all themes used at this site are released under the GNU/GPL license. designed and hosted by w3you. Our web server is running on Kanotix64-2006.