Main Navigation

Secondary Navigation

Page Contents

Contents

Little Linux for daily use and appetizers for more

No matter how your login looks like, you always have the possibility to enter LINUX commands direct or in a command window opened for that purpose.

List of examples

  1. Search for AVX capabilites of a host

Examples explained

Search for AVX capabilites of a host

This type of information is listed in the special file /proc/cpuinfo. You can list that file with the command cat (like catalogue) but the file is too long. Therefore we extract the corresponding lines that contain avx and stream the output of the cat into the search command grep via the LINUX pipe |. Still there are too many lines because every core is listed in that file. To reduce output to a single (unique) line we want to remove duplicated output. Again we use the LINUX pipe in combination with the command uniq. So far we have:
cat /proc/cpuinfo |grep avx | uniq
Unfortunately the specified line lists all kind of features of the CPU besides the AVX capabilities. To avoid searching and overseeing we want to remove all other features from the output but we can not use grep for this task as the output consists of a single line. One way to break this single line into words is a for-loop acting on the output of the above command sequence. Perform a
for f in `cat /proc/cpuinfo |grep avx | uniq `;do echo $f;done
and you will see it working. Beware to use not the normal apostrophe ' but the directed one from left to right called grave (german/latin gravis). This tells the shell to execute the commands within the accents first and pass the result to the for loop. Typically the above line will be written in textbooks:
for f in `cat /proc/cpuinfo |grep avx | uniq `
do
echo $f
done
If you do so and press the arrow UP for command repetition you will be back to the one line form above.

But back to our problem. There is still too much information printed. We actually only want to see those lines that contain the word avx at the beginning. Again there are many ways to select those, like echo $f | grep avx but here we use a condition there we remove the leading avx as a pattern from each word. Does the result differ from the word then the word starts with avx. Written in LINUX we have

if [ "${f##avx}" != "$f" ]; then  echo $f; fi
and alltogether now reads in several lines
for f in `cat /proc/cpuinfo |grep avx | uniq `
do
if [ "${f##avx}" != "$f" ]
then
echo $f
fi
done
If you see nothing - there is no avx on the computer you are working. If you again use the UP arrow for command repetition you find the inline script given in the text.