mobile version linux, last world news, last security news, last net4me news. all net 4me!
next
 
time

net4me logo

linux commands
shell script
protocol
ip, tcp, smtp, ntp, ftp
telnet terminal
java and javascript
ajax web technology
documentation
howto, man, info
cisco in network
linux server
linux in home
online utility
and more more more.
python development
туе4ьу дштгч

tux

  Содержание подраздела:

Cool commands

The following command saves stdout and stderr to the files "out.txt" and "err.txt", respectively.

[root@server /root]# ./cmd 1>out.txt 2>err.txt

The following command appends stdout and stderr to the files "out.txt" and "err.txt", respectively.

[root@server /root]# ./cmd 1>>out.txt 2>>err.txt

The following command functions similar to the above two commands, but also copies stdout and stderr to the files "stdout.txt" and "stderr.txt", respectively.

[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3\
|tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt

Note: Lines that end in a backslash are continued on the next line. Any such lines should be keyed in as one complete line. The lines are too long to fit on the web page without formatting them this way.

Cool Tar Command

[root@server /root]# (cd /var/ftp/pub/rh71prof/disk1.iso.dir \

&& tar -cvf - .) | (cd /var/ftp/pub/rh71prof/i386 && tar -xvf -)

Note: Lines that end in a backslash are continued on the next line. Any such lines should be keyed in as one complete line. The lines are too long to fit on the web page without formatting them this way.

Cool Find Command - looks in each file for searchstring

[root@server /root]# find . -type f -exec grep -i \
searchstring \{\} --with-filename \;

Note: Lines that end in a backslash are continued on the next line. Any such lines should be keyed in as one complete line. The lines are too long to fit on the web page without formatting them this way.

Sample Test Script

#!/bin/sh
#You can use this sample script for testing.  The echo
#    statements explain how this script works.
echo "This is Standard Out" >&1
echo "This is Standard Error" >&2

For loop demonstrating stderr and stdout

echo Standard Out >stdout.txt
echo Standard Error >stderr.txt
for X in bzImage modules modules_install; do
     make $X;
done 1>>stdout.txt 2>>stderr.txt

Redirection in Linux


0 = stdin
1 = stdout
2 = stderr

Using the tee command to save stdout to tee.txt. stdout is still displayed on the screen.

[root@server /root]# cmd | tee tee.txt

Using the tee command to append stdout to tee.txt. stdout is still displayed on the screen.

[root@server /root]# cmd | tee -a tee.txt

Using the script command to capture both stderr and stdout

[root@server stdout]# script

Script started, file is typescript
[root@server stdout]# ./cmd

This is Standard Out
This is Standard Error
[root@server stdout]# exit
exit
Script done, file is typescript
[root@server stdout]# cat typescript
Script started on Thu Oct 11 11:47:36 2001
[root@server stdout]# ./cmd
This is Standard Out
This is Standard Error
[root@server stdout]# exit
exit

Script done on Thu Oct 11 11:47:39 2001
[root@server stdout]#

Notes about pipe "|"

  • Lets consider a channel one of stdout or stderr.
  • The pipe can only carry one channel, namely stdout.
  • When you have a command line which utilizes the pipe command, stderr gets sent to the display while stdout gets sent through the pipe on to the other awaiting commands.
  • Swapping stdout and stderr will allow stdout to be sent to the display while stderr can be sent through the pipe.
  • Pipe by itself will only take stdout. If you swap stdout and stderr before you get to the pipe then the pipe will take stdout (which is now stderr).
  • stdout and stderr can be combined and sent through the pipe; however, you have now combined both stderr and stdout and there is no way to separate them.
  • using a pipe in a subshell "()" causes stdout to go through the pipe and causes stderr to pass through the subshell back to the display. This provides a way to grab stdout and stderr. Basically you could get both stdout and stderr out of a subshell.

Order of redirecting

Method 1

[root@server /root]# cmd 2>&1 1>outfile.txt

#The above command causes the original stderr to go to stdout,
# and causes the original stdout to go to outfile.txt.
#Notice at the time that fd (file descriptor) 2 is redefined, fd 1 still pointed to stdout; therefore, fd 2 will continue to point to stdout independently of what later happens to fd 1. Basically fd 2 copies the item (or address) that fd 1 is pointing to.
(Corrected an incorrect statement - Thanks to Morten for bringing it to my attention.)

Method 2

#The following command causes both the original stdout and stderr to go to outfile.txt.
[root@server /root]# cmd 1>outfile.txt 2>&1

#Notice that 1=outfile.txt when 2 is redefined, so 2 goes to outfile.txt too (the two
# channels are combined).

Capturing stderr with tee. Swapping stderr and stdout

The full command

[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt

The walk through

The following section will walk through the theory behind this command. Once you have a general understanding of this theory, you should be able to easily regenerate this entire command without notes.

Contents of the ./cmd script

#!/bin/sh
#You can use this sample script for testing.  The echo
#    statements explain how this script works.
echo "This is Standard Out" >&1
echo "This is Standard Error" >&2

Results from running the ./cmd script

[root@server /root]# ./cmd

This is Standard Out
This is Standard Error
[root@server /root]#

Although you see both lines printed on the screen, behind the scenes one actually went to stdout and the other went to stderr. If you were to do a pipe, only stdout goes through the pipe. Normally this is the desired effect.

Capturing stdout

The following will capture a copy of stdout and save it to a file called "stdout.txt"
[root@server /root]# ./cmd | tee stdout.txt

stdout goes through the pipe and tee is able to save a copy of it to the file "stdout.txt"; however, we just lost control of stderr. stderr will not go through the pipe, instead it goes directly to our display.

Gaining control of stderr and stdout.

Lets gain control again of stderr and stdout. We do this by surrounding our command with a set of parenthesis.
[root@server /root]# (./cmd | tee stdout.txt)

Swapping stdout and stderr.

Now that we have captured stdout, we wish to capture stderr using tee as well. The pipe will only accept stdout, so we must swap stderr and stdout to do this.
Note: The switch is using the standard variable switch method -- 3 variables (buckets) are required to swap 2 variables with each other. (you have 2 variables and you need to switch the contents - you must bring in a 3rd temporary variable to hold the contents of one value so you can properly swap them).
[root@server /root]# (./cmd | tee stdout.txt) 3>&1 1>&2 2>&3

Capturing stderr

Now that we have swapped our stdout and stderr, lets hook up tee once again. tee will now capture stderr (tee believes that it is really stdout because stdout is the only thing that can come through the pipe).
[root@server /root]# (./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt

Gaining control of stderr and stdout, for the 2nd time.

Tee grabs stderr, but once again the channel that doesn't go through the pipe gets sent to the display and we loose it. Lets capture both our stderr and stdout, once again, by using parenthesis.
[root@server /root]# ((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt)

Swapping stdout and stderr back to their normal state.

Now we have, once again, captured both stderr and stdout for our use. Currently they are reversed. Lets switch them back for proper use in our pipeline. Again, lets use the standard variable switch to swap them around.
[root@server /root]# ((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt) 3>&1 1>&2 2>&3

Gaining control of stderr and stdout, for the 3rd time.

At this point we have swapped stdout and stderr back to their normal positions; however, if we will be manipulating stdout and stderr any further, we should complete this command with either a pipe or another set of parenthesis.

Since we want to be as complete as possible in this example we will use parenthesis. Using parenthesis will gain control over both stdout and stderr. Using a pipe will only gain control over stdout.

Note: If we use a pipe or parenthesis the next process that hooks up to this command will see stderr and stdout in their proper place. If we don't add the last set of parenthesis, or go through a pipe, the order will remain messed up.
[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt) 3>&1 1>&2 2>&3)

Redirecting stdout and stderr to separate files

Now lets do something productive with stdout and stderr so that we can really prove that everything went back to their proper place. Lets tell our command to redirect stdout to "out" and stderr to "err".
[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3 \
| tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt

Note: This last step is optional, normally you would insert your other required commands here, commands that would more than likely operate on stdout.
Please note that the results for "out" and "err" are the same as when you run the following command. This proves that we restored stdout and stderr back to their normal usable posisitions. The above command; however, gives us the capability to copy out stdout and stderr using tee and still be able to use stdout and stderr like we always have.
[root@server /root]# ./cmd 1>out.txt 2>err.txt


Capturing stderr in one file and stderr and stdout combined in another file

I had a request for stderr in 1 file and stderr and stdout combined in another file so here it is:
Here is our testing command we will use to generate both stderr
and stdout on proper channels:
root@server:~> (echo out >&1; echo err >&2)
out
err
And here is the command to do the work:
root@server:~> (((echo out >&1; echo err >&2) 3>&2 2>&1 1>&3 | \
tee stderr.txt ) 3>&2 2>&1 1>&3 ) > combined.txt 2>&1

root@server:~> cat stderr.txt
err
root@server:~> cat combined.txt
out
err
root@server:~>

Please keep in mind when reading a book or web page with command line documentation
that the trailing slash signifies continuation of the current line. The reason for
this is due to the line width available on the screen and printed page. Note that
the trailing slash must be the last character on the line followed by enter. Spaces,
tabs, etc., may not apear after the trailing backslash because that does not signify
line continuation but rather some form of escape character. There are two ways that
you may enter this information at the command line:

1. Exactly as show, with the backslashes, followed by enter marks or

(((echo out >&1; echo err >&2) 3>&2 2>&1 1>&3 | \
tee stderr.txt ) 3>&2 2>&1 1>&3 ) > combined.txt 2>&1


2. Remove the trailing backslashes and do not press enter after each line, just word wrap
the lines together at the command prompt.

(((echo out >&1; echo err >&2) 3>&2 2>&1 1>&3 | tee stderr.txt ) 3>&2 2>&1 1>&3 ) > combined.txt 2>&1

Other Good Reading:

jobcontrol.html
man bash


Contents of ./myprog.sh
#!/bin/bash
echo "Standard Out" >&1
echo "Standard Error" >&2

Break out Standard Out into stdout.log, Standard Error into stderror.log, then display both on the screen:

((( ./myprog.sh | tee stdout.log ) 3>&2 2>&1 1>&3 | tee stderr.log ) 3>&2 2>&1 1>&3 )

Note, the lines may not come in the same order as without the redirection.
Note, the outside set of parenthesis (and the last set of movement just inside that last set of parenthesis) places stdout back on "1" and stderr back on "2" just in case you want to manipulate them further.

Break out Standard Out into stdout.log, Standard Error into stderror.log, combine the output (stdout and stderr), then display both on the screen:

((( ./myprog.sh | tee stdout.log ) 3>&2 2>&1 1>&3 | tee stderr.log ) 3>&2 2>&1 1>&3 ) 2>&1 | tee combined.log


* Hint from Ben-Ja: If you are interested in the command tee, you can see the "man tee".
* Hint2 from Ben-Ja: See also new command script to copy your terminal session in the file. See "man script".

* Подсказка от Бэни: Если вас заинтересвала команда tee, вы можете посмотреть man tee.
* Подсказка2 от Бэни: Также вас может заинтересовать сравнительно новая команда script, дублирующая терминальную сессию в файл. См. man script.



home back top
При копировании материалов нашего портала, сылка на net4me обязательна.
Рейтинг@Mail.ru   Rambler's Top100   Valid HTML 4.01 Transitional  

 



...

net4me snowflake
 
net4me portal This page last modified: Friday, May 21, 2010   be in net. net4me

portal net4me linux education center

Network to the internet. Open source laboratory must have Linux online services on net4me portal. web develop and information about OpenSource creation project in net. Example of javascript code is wonderful. Download software and drivers for Linux Geeks on net4me and have fun!
Microsoft’s marketing team considers ridiculously skewed charts to be a killer weapon in the war on competitors, so it’s only natural that they’d provide retail store employees with a surreal “comparison” between Windows 7 and Linux to explain for customers.
The chart is part of an ExpertZone training course provided by Microsoft to retail employees at stores like Best Buy. After the training, the employees are expected to be able to better explain the merits of software like the soon-to-launch Windows 7. Microsoft felt it necessary, however, to specifically compare Windows 7 to Linux—something we usually save for the particularly emotional commenters.
In this case, though, it has to be pointed out that Linux can and does play “the games your customers want”, specifically the World of Warcraft (wow) example mentioned, through the WINE project, and the idea that Linux has compatibility with “few” cameras, iPods, MP3 players, printers and scanners is definitely a stretch of a justification for a stark comparison. Linux, in fact, keeps legacy support intact for many of the printers, scanners, and other devices that Windows Vista and 7 have left behind, and generally supports models from the major manufacturers.
Video chat on “all major IM networks” just got better on Linux moemo, actually, with the release of Pidgin 2.6, and the lack of access to Windows Live Essentials has likely not caused many a netbook owner to make a red-faced return trip.
All that is not to say that a Linux machine, presumably a netbook in this case, is the best choice for any computer user not interested in configuring his machine a little if they’re looking for app use beyond basic web surfing and document access. Let’s hear your take on Microsoft’s talking points in the comments on net4me.

After releasing with much fanfare 20,000 lines of driver code under the GNU General Public License (GPL) for inclusion in the Linux kernel, Microsoft hasn’t followed through with the necessary updates and fixes required by the community, according to one Linux leader on net4me.
Greg Kroah-Hartman, a Novell fellow with SuSE Labs and Linux Driver Project lead, posted on September 9 a status update on the drivers being assembled for inclusion in the Linux 2.6.32 kernel, Kroah-Hartman had some harsh words about Microsoft’s participation since its original announcement of its GPL plans in late July.
Поток знания поможет определить поисковикам пользу для бизнеса от web-сервисов и скачать эту страницу на первые места download рейтингов.
Маркетинг и сеть. Разве может менеджер в галстуке продавать сеть? Сеть для сетевиков в джинсах и свитере. Это же ошибка. Почти как microsoft windows 7 в своей бете.
Сеть в интернет. Любая Open Source лаборатория должна иметь онлайн linux сервисы на портале net4me. Примеры скриптов и подробная документация по фофч, то есть ajax, помогут программистам в разработке web страниц и software не только в линукс, но и в windows. И даже простой сисадмин сможет научиться как правильно сделать javascript сайт и написать правильный скрипт bash или программу python на сервер в сети.
Даже обжим провода с названием витуха станет доступен простым языком войны. А про обжим розетки под rj45 и говорить нечего! Всё описание сетевых протоколов и консольных команд линукса тут, net 4 me рулит! Настройка роутера как и любого сервера под линуксом связана с конфигами. Править конфиг удобно в linux редакторе vim.
В общем, net4me это подробное описание как провести время хорошо и с пользой для знаний. Онлайн игры, wow и война в наши дни тут не уместны. Net это значит сеть. Сеть для меня. Именно так можно перевести название net4me.

В продолжение статьи о бизнесе и раскрутке сайтов посредством добавления букв и цифр на сравнительные страницы сайта о сетях, хочется сказать:
Раскрутить страницу благодаря справочнику net4me может каждый. Надо только захотеть. А вот построить сеть на основе витой пары, даже зная раскладку кабеля по цветам, дано не каждому программисту без умения обжать витуху.

Английский в плане оптимизации сайтов для поисковых систем конечно удобнее. Там нет падежей и склонений. И это не бред. Это долбанный SEO не по GPL. Интересно, кому это надо? Зачем заставлять людей писать, а со временем и даже думать SEO фразами и готовыми шаблонами для поисковиков? Неужели пришла пора и понятие "люди для машин" уже более актуально, нежели "машины для людей"? =((

Ладно. Оставим как есть. И заменим импортный бред про майкрософт и линукс нашим отечественного производства. Ой! Забыл про games, download driver и про туе4ьу is net4me сказать! =)) Ошибка которую можно и нужно исправить.
Найдется команда и пример на все случаи жизни в линукс и подробное описание любой команды простым языком.
И даже утилита из pdf 2 tf2 > pdf2fb2 utilites for moemo docs окажется здесь. Driver code under the GNU General Public License (GPL) for inclusion (install) in the Linux kernel as nvidia not nv.