We often test the understanding of the command line scan by asking if the following will work:
$ > /tmp/file1 2> /tmp/file2 (*)
This week, been faced with questions exploring this further. For example, notice that:
$ >log ( ps; who; df )
will work, so will
$ > log10 < /etc/hosts (while read -r line; do print $line; done )
(*) It will (as long as file exists). The shell opens all three files during the scan, and cat will be the only word remaining on the command line. In simple terms. the shell will look after the 'connectivity' between cat's I/O streams and the files.
Twitter Updates
G-AVLN in front of her home
Mostly Unix and Linux topics. But flying might get a mention too.
Thursday, September 29, 2005
Wednesday, September 21, 2005
SCO is fighing back ?
I hear that SCO are teaming up with MySQL! Must check it out - should we await MySQL license requirement soon ? ;-))
Daily Hintlet
The ps command is one of the most underused tools! Experiment with -o, which allows you to format the output. For example, try the following:
$ ps -C ksirtet -o pid=
Obviously, if you are not currently playing tetris, substitute ksirtet for another active process ;-)
Daily Hintlet
The ps command is one of the most underused tools! Experiment with -o, which allows you to format the output. For example, try the following:
$ ps -C ksirtet -o pid=
Obviously, if you are not currently playing tetris, substitute ksirtet for another active process ;-)
Friday, September 16, 2005
Terminal capabilities
I remember going back years and years, having to use an application which was meant to be displayed on a Prestel terminal. Prestel is a simple screen protocol, of 40 columns x 24 rows, still used in some places (mostly in Europe). It's got some interesting features, such as fixed colours for certain facilities. Can't remember much of the detail anymore, but I'm sure that, for example, the background colour is like choosing an old Ford - any colour you want, as long as it is black. Quite peculiar.
This was the project, however, that tought me a lot about terminfo database and tools associated with creating and manipulating the terminal capability files. The terminfo database is in fact a collection of hundreds of individual files, each containing a description of one terminal type. These are data files, you can't 'touch' them with cat or more, but feel free (as root) to convert it into text with:
# infocmp /usr/share/terminfo/v/vt100 > /tmp/vt100.txt
If you needed to create a new terminal file, you'd pick up the most suitable (similar) existing one, modify it (using data from the hardware manual provided with your new terminal) and submit it into the terminfo system with the tic command (terminfo compiler).
These days one gets 'drivers' for every screen one can think of (and few more), but understanding of the terminfo still helps - as you can then implement scripts, menus, etc, using some of the more advanced screen control techniques.
For example, many people know of the tput command, that allows to manipulate the screen on an ad hoc bases. This command uses the capabilities file indicated by your TERM variable. To check, type:
$ echo $TERM
If you are looged into Linux, that is very likely xterm, and the file used is /usr/share/terminfo/x/xterm.
If you've never seen tput in action, log onto any Unix or Linux box, open any terminal session and type:
$ tput bold; echo hello world; tput rev; echo and again; tput rsg0
The fun starts when you begin to utilise some of the more obscure features, such a colour or placement control. Try the following:
$ red=$(tput setf 4)
$ echo "${red}$(tput cup 10 20)hello world"
The setf argument allows to control the character colour, whereas cup x y will send the cursor to column x row y of your screen.
DailyHintlet
To find out more about the screen capabiliites and arguments to tput look at the manual pages for terminfo, as well as tput. There is a lot more useful stuff there, for example there is an explanation of why setf 4 might mean red on one ocassion but green on another!
This was the project, however, that tought me a lot about terminfo database and tools associated with creating and manipulating the terminal capability files. The terminfo database is in fact a collection of hundreds of individual files, each containing a description of one terminal type. These are data files, you can't 'touch' them with cat or more, but feel free (as root) to convert it into text with:
# infocmp /usr/share/terminfo/v/vt100 > /tmp/vt100.txt
If you needed to create a new terminal file, you'd pick up the most suitable (similar) existing one, modify it (using data from the hardware manual provided with your new terminal) and submit it into the terminfo system with the tic command (terminfo compiler).
These days one gets 'drivers' for every screen one can think of (and few more), but understanding of the terminfo still helps - as you can then implement scripts, menus, etc, using some of the more advanced screen control techniques.
For example, many people know of the tput command, that allows to manipulate the screen on an ad hoc bases. This command uses the capabilities file indicated by your TERM variable. To check, type:
$ echo $TERM
If you are looged into Linux, that is very likely xterm, and the file used is /usr/share/terminfo/x/xterm.
If you've never seen tput in action, log onto any Unix or Linux box, open any terminal session and type:
$ tput bold; echo hello world; tput rev; echo and again; tput rsg0
The fun starts when you begin to utilise some of the more obscure features, such a colour or placement control. Try the following:
$ red=$(tput setf 4)
$ echo "${red}$(tput cup 10 20)hello world"
The setf argument allows to control the character colour, whereas cup x y will send the cursor to column x row y of your screen.
DailyHintlet
To find out more about the screen capabiliites and arguments to tput look at the manual pages for terminfo, as well as tput. There is a lot more useful stuff there, for example there is an explanation of why setf 4 might mean red on one ocassion but green on another!
Thursday, September 15, 2005
DailyHintlets
I found that doing a decent write-up on any particular thought or a 'discovery', etc takes time, and for that reason I often delay posting, to the point that the thought is gone, and opportunity for recording it missed.
So, from now on, in addition to sometimes longer ellaborations, I will now have a snappy entry, called "DailyHintlet". They will usually be one-liner solutions, examples, thoughts, etc. Often they will be bits of information I've learned from the delegates!
Despite the name, I don't really expect them to be posted daily, just liked the title ;-)
DailyHintlet
In GRUB configuration, the scope of the password directive changes, depending on where it is applied. If applied in the general definitions section, it controls ability to edit the configuration file. If applied within a stanza paragraph, it controls the access to (ability to boot) that kernel.
(Ghanny from CompuCentre - thank you for correcting my lab solutions)
Tuesday, September 06, 2005
grep with -E option
One of the most confusing things newbies face when learning Unix is having to grasp regular expressions. Having gone through the pains of learning the globbing (wildcards) and other shell specials, only a couple of days later we throw them all into air (characters, that is - not the delegates) and try to catch them again!
It's interesting to watch the delegates try to rationalise it all... What usually finishes them off, is the use of the counting mechanism, whereby one can specify how many instances of a character or a pattern is expected.
For example: to locate lines (in datafile) with at least 4 characters using grep could be done simply with (remember, in regular expressions dot means any one character):
$ grep '....' datafile
But if you want to locate lines containing exactly four characters, grep is taking on a bit more complex detail. The counting mechanism used needs to be 'switched on' with the use of the backslash.
$ grep '^.\{4\}$' datafile
The delegates are by this stage happy (ish) with the 'anchoring' characters (^ and $) and know that this means tying the pattern to the beginning and end of line, respectively. What freaks them out is that \{ \} notation.
I like using it, because it allows me to complete the explanation of the backslash usage in Unix - you use it to toggle a special-meaning of a character. We normally use it to turn the special meaning of a character off. In the counting notation of grep, we use it for the exactly opposite purpose. Here, it means turn the special meaning of the curly brackets on (and make it count the character specified in front of it).
But, I will have to find a different example to illustrate the use of the backslash; I just can't justify for much longer keeping quiet about the -E option one can use with grep. This allows the use of the set of extended regular expressions, in which counting is part of the default, and the { } notation is taken to mean counting without any additional measures...
Therefore, the last example could be re-written with:
$ grep -E '^.{4}' datafile
Much simpler, and less confusing...
Why sudden change of heart? Had an e-mail from a delegate along the lines of: "Alina, did you know that..."
It's interesting to watch the delegates try to rationalise it all... What usually finishes them off, is the use of the counting mechanism, whereby one can specify how many instances of a character or a pattern is expected.
For example: to locate lines (in datafile) with at least 4 characters using grep could be done simply with (remember, in regular expressions dot means any one character):
$ grep '....' datafile
But if you want to locate lines containing exactly four characters, grep is taking on a bit more complex detail. The counting mechanism used needs to be 'switched on' with the use of the backslash.
$ grep '^.\{4\}$' datafile
The delegates are by this stage happy (ish) with the 'anchoring' characters (^ and $) and know that this means tying the pattern to the beginning and end of line, respectively. What freaks them out is that \{ \} notation.
I like using it, because it allows me to complete the explanation of the backslash usage in Unix - you use it to toggle a special-meaning of a character. We normally use it to turn the special meaning of a character off. In the counting notation of grep, we use it for the exactly opposite purpose. Here, it means turn the special meaning of the curly brackets on (and make it count the character specified in front of it).
But, I will have to find a different example to illustrate the use of the backslash; I just can't justify for much longer keeping quiet about the -E option one can use with grep. This allows the use of the set of extended regular expressions, in which counting is part of the default, and the { } notation is taken to mean counting without any additional measures...
Therefore, the last example could be re-written with:
$ grep -E '^.{4}' datafile
Much simpler, and less confusing...
Why sudden change of heart? Had an e-mail from a delegate along the lines of: "Alina, did you know that..."
Thursday, September 01, 2005
Memory stick Duo and HP 6120...
...do not work together!
HP 6120 comes with a fancy digital card reader port. It takes every card. Apparently. What was not documented very well, is that the new format memory sticks, such as the Magic Gate ones, do not (and will not) work. Indeed, some of the sites on the web warn you against using them, as you can corrupt the card.
So, I thought I'd get a PCMCIA card, with the memory stick adapter. Guess what! I have found a way of predicatably generating a blue screen of death on XP!
And that's after being convinced by many that this is now in the past. It actually is blue, even if it doesn't last long, not even long enough for me to read the info (not that I would really want to).
So, off to Jessops again, to get a USB external reader. More bits to carry.
Lack of standards is getting at me.
HP 6120 comes with a fancy digital card reader port. It takes every card. Apparently. What was not documented very well, is that the new format memory sticks, such as the Magic Gate ones, do not (and will not) work. Indeed, some of the sites on the web warn you against using them, as you can corrupt the card.
So, I thought I'd get a PCMCIA card, with the memory stick adapter. Guess what! I have found a way of predicatably generating a blue screen of death on XP!
And that's after being convinced by many that this is now in the past. It actually is blue, even if it doesn't last long, not even long enough for me to read the info (not that I would really want to).
So, off to Jessops again, to get a USB external reader. More bits to carry.
Lack of standards is getting at me.
Subscribe to:
Posts (Atom)
Blog Archive
- October (1)
- June (1)
- April (2)
- February (3)
- June (1)
- March (1)
- August (3)
- July (2)
- June (1)
- March (1)
- June (3)
- May (1)
- April (5)
- February (1)
- January (5)
- October (1)
- September (3)
- July (4)
- June (5)
- April (3)
- March (1)
- February (3)
- January (3)
- October (7)
- August (2)
- July (3)
- May (1)
- November (4)
- October (1)
- September (1)
- August (2)
- July (2)
- June (3)
- May (3)
- April (2)
- March (2)
- February (3)
- January (1)
- December (2)
- November (1)
- October (6)
- September (6)
- August (1)
- July (2)
- June (8)
- May (3)
- April (4)
- March (3)