<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>33dots &#187; Linux</title>
	<atom:link href="http://www.33dots.com/index.php/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.33dots.com</link>
	<description></description>
	<lastBuildDate>Wed, 12 Oct 2011 17:07:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux text processing tools &#8211; Part 2</title>
		<link>http://www.33dots.com/index.php/linux/linux-text-processing-tools-2.html</link>
		<comments>http://www.33dots.com/index.php/linux/linux-text-processing-tools-2.html#comments</comments>
		<pubDate>Wed, 12 Oct 2011 17:01:52 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=431</guid>
		<description><![CDATA[This is my attempt to get familiar with the various text processing tools in Linux. I am also noting down several oneliners that i found elsewhere.
Its a continuation of my earlier post Linux text processing tools &#8211; Part 1
This is NOT written as a tutorial. For details on usage and options check man pages.
sort &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>This is my attempt to get familiar with the various text processing tools in Linux. I am also noting down several oneliners that i found elsewhere.<br />
Its a continuation of my earlier post <a href="/index.php/linux/linux-text-processing-tools-1.html">Linux text processing tools &#8211; Part 1</a></p>
<p><span style="text-decoration: underline;">This is NOT written as a tutorial. For details on usage and options check man pages.</span></p>
<p><strong><code>sort</code> &#8211; sort lines of text files</strong></p>
<p>Sorting is done based on one or more sort <em>keys</em> extracted from each line of input.<br />
If no sort keys are specified, the entire line is taken as key.</p>
<p>some of the options for sort are,<br />
<code>-f</code> (ignore case), <code>-b</code> (ignore leading blanks),<code>-n</code> (numerically sort), <code>-r</code> (reverse), <code>-u</code> (unique), <code>-tx</code> (where x is the delimiter), <code>-k</code> (used to specify keys) <code>-o</code> (output file) </p>
<pre>
[tony@localhost tmp]$ sort List.txt
bbb
ccc
CCC
ddd
[tony@localhost tmp]$ sort -n age.txt
08mike
18john
23tony
60jose
[tony@localhost tmp]$ sort -bn
19
 9
06
  14   #press CTRL+D to stop inputting
06
 9
  14
19
[tony@localhost tmp]$ sort -c list.txt
sort: list.txt:2: disorder: aaa   #check whether sorted
[tony@localhost tmp]$ sort -m list.txt list2.txt
   #merge sorted files, each file must be sorted previously.

[tony@localhost tmp]$ sort list.txt -o list.txt     #sorts and saves in the same file
[tony@localhost tmp]$ sort -R list.txt -o list.txt    #shuffle a list of lines
</pre>
<p>sort keys(or fields) are specified using the <code>-k</code> option with the syntax<br />
<code>-k m[,n]</code> (start at field <code>m</code>, end at field <code>n</code> including it, or the end if <code>n</code> is omitted).<br />
By default <em>blank</em> is used as the field separator. It can also be specified using <code>-tx</code></p>
<p>Note that several of the options available can also be specified along with the key. </p>
<pre>
[tony@localhost tmp]$ sort -k 3b
   #sort using key from 3rd field to end of line. #Ignore any blanks preceding 3rd field.
[tony@localhost tmp]$ sort -k2n,2
   #this will sort numerically based on the 2nd field.

[tony@localhost tmp]$ sort -t : -k 2,2n -k 5.3,5.4
   #Sort numerically on the second field and then sort alphabetically on the third
   #and fourth characters of field five to break tie. Use `:' as the field delimiter.

[tony@localhost tmp]$ sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 IP.txt
   #sort a list of IPv4 addresses.
</pre>
<p><strong>Note</strong>: if you sometimes see strange sorting order(check below example), this is usually bcoz linux <em>locale</em> setting set to a non-POSIX locale. You could prefix sort (or any command) with &#8216;<code>LC_ALL=c</code>&#8216; to get the POSIX order.</p>
<pre>
[tony@localhost tmp]$ sort list
1 1
111
212
2 2
[tony@localhost tmp]$ LC_ALL=c sort list
1 1
111
2 2
212
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong><code>shuf</code> &#8211; shuffle lines </strong></p>
<pre>
[tony@localhost tmp]$ sort LIST | shuf
333   #shuf shuffles our sorted LIST
212
444
111
[tony@localhost tmp]$ shuf -i 1-4
2   #generates a shuffled list of numbers
3
4
1
[tony@localhost tmp]$ shuf -e clubs hearts diamonds spades
clubs
diamonds
hearts
spades
[tony@localhost tmp]$ shuf LIST -o LIST   #in place save
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong><code>uniq</code> &#8211; Uniquify files</strong></p>
<p>uniq discard adjacent duplicate lines. Non adjacent duplicate lines are not discarded. To discard non adjacent duplicate lines the file must be sorted before or we could use the <code>sort -u</code> command.</p>
<pre>
[tony@localhost tmp]$ cat list
aaa
bbb
bbb
ccc
bbb
[tony@localhost tmp]$ uniq list
aaa
bbb
ccc
bbb
[tony@localhost tmp]$ uniq -c list
      1 aaa   #prefixes repetition count
      2 bbb
      1 ccc
      1 bbb
[tony@localhost tmp]$ uniq -d list
bbb   #only repeated lines
[tony@localhost tmp]$ uniq -i list2
ccc   #ignores case when comparing
</pre>
<p>Fields or characters can be ignored before comparison, by using the <code>-fn</code> and -<code>sn</code> options.</p>
<pre>
[tony@localhost tmp]$ cat > list2
aa bb
ad bb
ad cc
ad dd
[tony@localhost tmp]$ uniq -f 1 list2
aa bb   #we skipped first field from comparison check
ad cc
ad dd
[tony@localhost tmp]$ uniq -s 4 list2
aa bb   #we skipped the first 4 characters
ad cc
ad dd
[tony@localhost tmp]$ uniq -s 2 -w 1 list2
aa bb   #-w option specifies number of characters to compare after
   # any characters and fields have been skipped

[tony@localhost tmp]$ sort file | uniq -c | sort -n
#displays the unique lines along with the number of times they occur
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><code>comm</code> -: Compare two sorted files line by line</p>
<p>Comm output 3 columns, the first two columns contain lines unique to the first and second file, respectively. The last column contains lines common to both.<br />
The columns are separated by <em>tabs</em>. The files must be sorted before.</p>
<p>Option <code>-1</code>,<code>-2</code>.<code>-3</code> can be specified to remove the corresponding column from output.</p>
<pre>
[tony@localhost tmp]$ cat > list
aaa
bbb   # press CTRL+D to stop inputting
[tony@localhost tmp]$ cat > list2
bbb
bbb
ccc
[tony@localhost tmp]$ comm list list2
aaa
		bbb   #bbb is common to both
	bbb           #this bbb is only in list2
	ccc
[tony@localhost tmp]$ comm -32 list list2
aaa   #only the lines unique in first file.
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong><code>head</code> &#8211; Output the first part (10 lines) of files</strong></p>
<p>supports the options<code> -nK</code>, <code>-cK</code> where <code>K</code> is the number of lines or bytes to be printed.</p>
<pre>
[tony@localhost ~]$ head -n5 .bash_history #prints 1st 5 lines
su -
lspci
/etc/init.d/NetworkManager restart
/etc/init.d/NetworkManager status
tail -f /var/log/messages
[tony@localhost ~]$ head -c10 .bash_history   #1st 10 bytes
su -
lspci
[tony@localhost ~]$ head -n-5 .bash_history #prints all but last 5 lines
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong><code>tail</code> &#8211; Output the last part(10 lines) of files</strong></p>
<p>tail supports <code>-nk</code> and -<code>ck </code>as in the case of head.<br />
<code>tail -f</code> periodically (default 1sec) checks to read from the end of the line</p>
<pre>
[root@localhost ~]# tail -f /var/log/messages
   # is used to scan system messages especially when isolating a problem
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<strong><code>split</code> &#8211; Split a file into pieces</strong></p>
<p>Usage:  <code>split [OPTION] [INPUT [PREFIX]]</code></p>
<p>Split is generally used to split a file based on lines (<code>-l LINES</code>) or bytes (<code>-b SIZE</code>)<br />
By default files are split by 1000 lines. The files are named by appending aa, ab, ac, etc. to <code>PREFIX</code> (if ommitted x is used)</p>
<pre>

[tony@localhost tmp]$ cat > file
aaa
bbb
ggg
ccc
kkk   # Press CTRL+D to stop inputting
[tony@localhost tmp]$ split -l2 file   #split into files with 2 lines
[tony@localhost tmp]$ head xa?   # viewing each of them
==> xaa <==
aaa
bbb

==> xab <==
ggg
ccc

==> xac <==
kkk

[tony@localhost tmp]$ split -b100KB thriller.ogg part
   # splitting music file by size 100KB
[tony@localhost tmp]$ ls -l parta?
-rw-rw-r--. 1 tony tony 100000 Oct 12 14:47 partaa
-rw-rw-r--. 1 tony tony 100000 Oct 12 14:47 partab
-rw-rw-r--. 1 tony tony   9305 Oct 12 14:47 partac
[tony@localhost tmp]$ cat parta? > thriller2.ogg
   # Joining them back
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong><code>paste</code> &#8211; merge lines of files</strong></p>
<p>Paste joins file by horizontally by outputting lines consisting of the sequentially corresponding lines of each file specified.</p>
<pre>
[tony@localhost tmp]$ cat > Name
john
tom   # Press CTRL+D to stop inputting
[tony@localhost tmp]$ cat > Age
20
19
[tony@localhost tmp]$ paste Name Age
john	20
tom	19
</pre>
<p><code>-s</code> opton pastes the lines of one file at a time rather than one line from each file.</p>
<pre>
[tony@localhost tmp]$ paste -s Name Age
john	tom
20	19
</pre>
<p>a delimiter list can be specified using<code> -d</code></p>
<pre>
[tony@localhost tmp]$ paste -d ':-' Name Age Name
john:20-john
tom:19-tom
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong><code>join</code> &#8211; join lines of two files on a common field</strong></p>
<p>Usage: <code>join [OPTION] FILE1 FILE2</code></p>
<p>Join outputs a line for each pair of input lines with identical join fields. Each output line consists of the join field, the remaining fields from FILE1, then the remaining fields from FILE2.<br />
The default join field is the first, delimited  by whitespace and leading blanks on the line are ignored;<br />
Both files have to be sorted on the join field.</p>
<pre>
[tony@localhost tmp]$ cat > j1
a ac
b bc
c cd   # Press CTRL+D to stop inputting
[tony@localhost tmp]$ cat > j2
a acc
b bcc
c cdd
[tony@localhost tmp]$ join j1 j2
a ac acc
b bc bcc
c cd cdd
[tony@localhost tmp]$ cat >> j2
c dcccc
[tony@localhost tmp]$ join j1 j2
a ac acc
b bc bcc
c cd cdd
c cd dcccc
</pre>
<p>Join supports options like the (<code>-1 N</code>) join field in first file ,(<code>-2 N</code>) join field in sec file, (<code>-i</code>) ignore case, (<code>-t x</code>) separator in output, (<code>-v N</code>) print non joined lines of file 1[or 2] </p>
<pre>
[tony@localhost tmp]$ join -1 2 -2 1 -t '-' file1 file2
   # this joins based on 2nd field on first file and 1st field of sec file and uses - as separator in output
</pre>
<p>&nbsp;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/linux/linux-text-processing-tools-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux text processing tools &#8211; Part 1</title>
		<link>http://www.33dots.com/index.php/linux/linux-text-processing-tools-1.html</link>
		<comments>http://www.33dots.com/index.php/linux/linux-text-processing-tools-1.html#comments</comments>
		<pubDate>Sat, 08 Oct 2011 10:28:39 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=417</guid>
		<description><![CDATA[This is my attempt to get familiar with the various small yet powerful text processing tools in linux. I am also noting down several oneliners that i found elsewhere.
This is NOT written as a tutorial. For details on usage and options check man pages
tr &#8211; tanslate or delete characters
Usage:     tr [OPTIONS] [...]]]></description>
			<content:encoded><![CDATA[<p>This is my attempt to get familiar with the various small yet powerful text processing tools in linux. I am also noting down several oneliners that i found elsewhere.</p>
<p><span style="text-decoration: underline;">This is NOT written as a tutorial. For details on usage and options check man pages</span></p>
<p><strong><code>tr</code> &#8211; tanslate or delete characters</strong></p>
<p>Usage:     <code>tr [OPTIONS] SET1 [SET2]</code></p>
<p>Options include <code>-d</code> (delete), <code>-s</code> (squeeze), <code>-c</code> (complement) etc.</p>
<p><code>tr</code> supports certain sequences like, <code>[:alnum:],[:alpha:],[:blank:],[:lower:],[:upper:]</code> etc and <em>regular expressions</em> for <code>SET</code></p>
<pre>
[tony@localhost tmp]$ tr g e
grgat
great   #pressing CTRL+D quits
[tony@localhost tmp]$ echo tgst | tr g e
test   #adding quotes around SETs are recommended
[tony@localhost tmp]$ echo taxt | tr 'xa' 'se'
test   #Note the translation, x to s and a to e
[tony@localhost tmp]$ echo abCDef | tr '[:lower:]' '[:upper:]'
ABCDEF
[tony@localhost tmp]$tr A-Z a-z
abCDe
abcde
</pre>
<pre>
[tony@localhost tmp]$ echo test | tr -d 'e'
tst
[tony@localhost tmp]$ echo abc44jk | tr -d  0-9
abcjk
[tony@localhost tmp]$ echo 12d34sS5c | tr -d  a-z
12345
[tony@localhost tmp]$ echo abCDef | tr -d  [:upper:]
abef
[tony@localhost tmp]$ tr -cd '[:alnum:]'   #strip all symbols
</pre>
<pre>
[tony@localhost tmp]$ echo ttest | tr -s 't'
test
[tony@localhost tmp]$ echo tteesttt | tr -s 'et'
test
[tony@localhost ~]$ tr -s '\n' #strip empty lines.
</pre>
<pre>
[tony@localhost tmp]$ echo test | tr -c 'e' 'g'
geggg
[tony@localhost tmp]$ tr -cs 'a-zA-Z0-9_' '\n'< source.c
   #extract keywords, identifiers and comments from C source. ofcourse not perfect!
</pre>
<pre>
[tony@localhost tmp]$ tr '[:lower:]' '[:upper:]' &lt;small.txt  >big.txt
[tony@localhost tmp]$ tr -d '\r' &lt;windows.txt  >linux.txt
[tony@localhost tmp]$ tr '\r' '\n' &lt;mac.txt  >linux.txt
</pre>
<p>&nbsp;</p>
<p>--------------------</p>
<p><strong><code>nl</code> - number lines</strong></p>
<pre>
[tony@localhost tmp]$ cat > list.txt
aaa
bbb

ccc
[tony@localhost tmp]$ nl list.txt
     1	aaa
     2	bbb

     3	ccc
[tony@localhost tmp]$ nl -ba list.txt
     1	aaa # -b is numbering syle
     2	bbb
     3
     4	ccc
[tony@localhost tmp]$ nl -i10 -nrz -s:: -v10 -w4 list.txt
0010::aaa  #-i increment, -s separator, -v start no, -w width, -n is Format
0020::bbb

0030::ccc
</pre>
<p>&nbsp;</p>
<p>----------------------</p>
<p><strong><code>wc</code> - print line, word, and byte counts</strong></p>
<pre>
[tony@localhost tmp]$ wc list.txt list2.txt
 3  3 12 list.txt   # the counts are line, word, bytes
 4  3 13 list2.txt
 7  6 25 total
[tony@localhost tmp]$ wc -m list.txt
12 list.txt   #character count
[tony@localhost tmp]$ wc -L sample.txt
82 sample.txt   #longest line length
[tony@localhost tmp]$ ls -1 | wc -l
13   #no of files in current directory
[tony@localhost tmp]$ ps -e | wc -l
178   #no of processes running
[tony@localhost tmp]$ cat /etc/group | wc -l
72
</pre>
<p>&nbsp;</p>
<p>----------------------</p>
<p><strong><code>cat</code> - concatenate or write files, text or binary</strong></p>
<pre>
[tony@localhost tmp]$ cat > list.txt
aaa

bbb
ccc   #press CTRL+D to stop inputting and save file
[tony@localhost tmp]$ cat list.txt
aaa

bbb
ccc
[tony@localhost tmp]$ cat f1 f2
aaa
bbb
[tony@localhost tmp]$ cat f1 f2 > f3
[tony@localhost tmp]$ cat f3
aaa
bbb
[tony@localhost tmp]$ cat >> f3
ddd   #append input to file
[tony@localhost tmp]$ cat f1 - f2 > f3
this is what i entered in the middle
[tony@localhost tmp]$ cat f3
aaa
this is what i entered in the middle
bbb
[tony@localhost tmp]$ cat video.001 video.002 video.003 > vid.avi
  # joining split binary files
</pre>
<p>&nbsp;</p>
<p>----------------------------</p>
<p><strong><code>tac</code> - concatenate or print in reverse (last line first)</strong></p>
<pre>
[tony@localhost tmp]$ tac > f1
1
2   #press CTRL+D to stop
[tony@localhost tmp]$ tac f1
1
2
[tony@localhost tmp]$ tac vid.avi > vid2.avi ; mv vid2.avi vid.avi #it wont play
[tony@localhost tmp]$ tac vid.avi > vid2.avi ; mv vid2.avi vid.avi # back to playable.
  #This is like a mini encryption for binary files.
</pre>
<p>&nbsp;</p>
<p>----------------------------</p>
<p><strong><code>rev</code> — reverse lines of a file or files</strong></p>
<pre>
[tony@localhost tmp]$ echo this is to be reversed | rev
desrever eb ot si siht
[tony@localhost ~]$ rev .bash_profile
eliforp_hsab. #

snoitcnuf dna sesaila eht teG #
neht ;] crhsab./~ f- [ fi
crhsab./~ .
if

smargorp putrats dna tnemnorivne cificeps resU #

nib/EMOH$:HTAP$=HTAP

HTAP tropxe
</pre>
<p>&nbsp;</p>
<p>----------------------------</p>
<p><strong><code>cut</code> - remove sections from each line of files</strong></p>
<p><code>cut</code> can return section based on no: of bytes (<code>-b</code>), characters (<code>-c</code>), or fields (<code>-f</code>)  when fields are separated by a delimiter(<code>-d</code>). Default delimiter is <em>tab</em>.</p>
<p>A range must be provided in each case which consists of one of <code>N, N-M, N-</code>(<code>N</code> to last) or <code>-M</code> (first to <code>M</code>)</p>
<pre>
[tony@localhost tmp]# cut -c 2-4
abcdef #press CTRL+D to stop inputting
bcd
[tony@localhost tmp]# cut -c 3
abcdef
c
[tony@localhost tmp]$ cut -c 2,4,7
alongtext
lne
[tony@localhost tmp]# cut -c -2
abcdef
ab
[tony@localhost tmp]# cut -c 2-
abcdef
bcdef
[tony@localhost tmp]$ cut -c 1,6-9,16-
alongtextwithnospaces
atextspaces
</pre>
<pre>
[tony@localhost tmp]# cut -f 2- -d ':'
23:34:45:56 # -d specifies delimiter
34:45:56
[tony@localhost tmp]$ cut -f 2
er rt fg wd ji
er rt fg wd ji   #cut didnt find the delimiter (default is tab)
   #so returns whole line
[tony@localhost tmp]$ cut -f 2 -s
er rt fg wd ji    #cut wont print as -s flag is used to
   # prevent printing when delimiter not found.
[tony@localhost tmp]$ cut -d: -f1 /etc/passwd >users.txt
</pre>
<p>&nbsp;</p>
<p>-----------------------------<br />
<br />
Continued on <a href="/index.php/linux/linux-text-processing-tools-2.html">Linux text processing tools - Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/linux/linux-text-processing-tools-1.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hybrid graphics in Sony VAIO and Fedora 15</title>
		<link>http://www.33dots.com/index.php/linux/hybrid-graphics-in-sony-vaio-and-fedora.html</link>
		<comments>http://www.33dots.com/index.php/linux/hybrid-graphics-in-sony-vaio-and-fedora.html#comments</comments>
		<pubDate>Wed, 20 Jul 2011 15:54:17 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=395</guid>
		<description><![CDATA[This a report on how i solved radeon driver related booting problem and automatically switched OFF the Radeon card of my Sony VAIO C series laptop in Fedora 15. This laptop has a AMD Radeon and Intel combination.
The steps may be somewhat similar for other laptops with ATI/Intel combinations in Fedora.
NOTE: This method disables the [...]]]></description>
			<content:encoded><![CDATA[<p>This a report on how i solved <em>radeon</em> driver related booting problem and automatically switched OFF the Radeon card of <a href="/index.php/linux/fedora-15-in-sony-vaio-vpc-cb-15fg.html">my Sony VAIO C series laptop</a> in Fedora 15. This laptop has a AMD Radeon and Intel combination.<br />
The steps may be somewhat similar for other laptops with ATI/Intel combinations in Fedora.</p>
<p><strong>NOTE</strong>: This method disables the AMD Radeon card upon booting. The aim is to increase battery life(about 1.5 hrs in mine) and reduce the heat. I dont use any graphic intensive applications in linux, so the Radeon is better switched OFF. <span style="text-decoration: underline;">If you want 3D acceleration or looking for a method for hot switching of cards, you have no luck here</span>.</p>
<p><strong>Background</strong><br />
Fedora 15 comes with a open source <em>radeon</em> driver(not catalyst driver) and includes <em>vgaswitcheroo</em> a mechanism to support switch ON/OFF cards and login out/login card switching.</p>
<p>Upon booting, if the kernel detects hybrid graphics, a directory <em>/sys/kernel/debug/vgaswitcheroo</em> will be created with a file named <em>switch</em>.</p>
<p>The following commands are available,<br />
<code>cat switch</code> &#8211; Displays the status of the cards.</p>
<pre>[root@localhost ~]# cd /sys/kernel/debug/vgaswitcheroo/
[root@localhost vgaswitcheroo]# cat switch
0:IGD:+:Pwr:0000:00:02.0
1:DIS: :Off:0000:01:00.0</pre>
<p>IGD &#8211; integrated ie Intel, DIS &#8211; discrete ie Radeon, Pwr &#8211; power ON, Off &#8211; power OFF, and + sign indicates which card if active.</p>
<p><code>echo OFF &gt; switch</code> &#8211; Turns OFF the inactive one.<br />
<code>echo ON &gt; switch</code> &#8211; Turns ON the card that is OFF<br />
<code>echo DIS[IGD] &gt; switch</code> &#8211; Switches the discrete card [or the IGD] active. You need to logout and login for this to take effect.</p>
<p>GNOME 3 doesnt load in my system with discrete card. So switching to discrete is pretty useless at the moment.</p>
<p>Note that <em>vgaswitcheroo</em> is gone if you have installed the proprietary &#8216;catalyst&#8217; drivers either using RPMFusion or using the binaries provided at the AMD site.</p>
<p><strong>Booting issue</strong><br />
I often had problem while booting with the system hangs at &#8220;<em>dracut: starting plymouth daemon</em>&#8220;.</p>
<p>I guess this was due to <em>radeon</em> driver. Not sure though.</p>
<p>The trick was to &#8216;blacklist&#8217; the <em>radeon</em> driver, and load it once the system has finished booting. And then switch OFF the Radeon card. It worked for me.</p>
<p><span style="text-decoration: underline;">You have to do this step only if you have problems during booting caused by the <em>radeon</em> driver. Else skip <a href="#switch">to here</a>.</span></p>
<p>Add &#8216;blacklist radeon&#8217; to the  <em>/etc/modprobe.d/blacklist.conf</em>. This will cause the <em>radeon</em> driver not to load during boot.</p>
<pre>[root@localhost ~]#echo blacklist radeon &gt;&gt; /etc/modprobe.d/blacklist.conf</pre>
<p>Backup and then rebuild the <em>initramfs</em>.</p>
<pre>[root@localhost ~]# mv /boot/initramfs-$(uname -r).img{,.bak}
[root@localhost ~]# dracut -f /boot/initramfs-$(uname -r).img $(uname -r)</pre>
<p>The <code>dracut</code> command may take a while to finish, and may report some warnings.</p>
<p>If you want, you can reboot now and see whether your issue at boot has resolved.</p>
<p>To load the <em>radeon</em> driver automatically once the boot is fine. We add the script to <em>rc.local</em>.</p>
<pre>[root@localhost ~]# echo modprobe radeon &gt;&gt; /etc/rc.local</pre>
<p>Note that Radeon is ON after booting whether driver is loaded or not. And <em>radeon</em> driver must be loaded to switch OFF the card,</p>
<p><a name="switch">..</a></p>
<p>Add the script to switch OFF the Radeon automatically after booting.</p>
<pre>[root@localhost ~]# echo "echo OFF &gt; /sys/kernel/debug/vgaswitcheroo/switch" &gt;&gt; /etc/rc.local</pre>
<p><strong>Suspend/Hibernate Issue</strong><br />
After a suspend or hibernate, the Radeon card gets switched ON. However,  <code>cat /sys/kernel/debug/vgaswitcheroo/switch</code> wrongly shows the Discrete card as OFF. This can be confirmed by checking the remaining battery time or system temperature.</p>
<p>Now to switch the card OFF again, do</p>
<pre>[root@localhost ~]# echo ON &gt; /sys/kernel/debug/vgaswitcheroo/switch
[root@localhost ~]# echo OFF &gt; /sys/kernel/debug/vgaswitcheroo/switch</pre>
<p>== To  Do: automate this  ==</p>
<p><strong>To confirm whether the Radeon is switched OFF</strong><br />
One method is to check the remaining battery time before and after switching OFF. There should be a 1-2hrs difference.</p>
<p>Another method i use, is to check the system temperature by installing <em>lm-sensors</em></p>
<pre>[root@localhost ~]# yum install lm_sensors
[root@localhost ~]# sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +42.0°C  (crit = +96.0°C)
temp2:        +42.0°C  (crit = +96.0°C)

radeon-pci-0100
Adapter: PCI adapter
temp1:       -128.0°C</pre>
<p>Here, the &#8216;-&#8217; value indicates that the card is OFF.<br />
A system temperature &gt; 50C at idle also means Radeon ON in my system.</p>
<p>&#8211;<br />
Thanks to,<br />
http://ubuntuforums.org/showthread.php?t=1744188&#038;page=1<br />
doskey @ http://forums.fedoraforum.org/showpost.php?p=1492290&#038;postcount=11</p>
<p>Tags: vgaswitcheroo howto,  switchable graphics in fedora 15,  turn off AMD/ATI, Hybrid graphics in fedora, switch off dedicated card in fedora, Sony VAIO VPCCB15FG</p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/linux/hybrid-graphics-in-sony-vaio-and-fedora.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Accessing the Linux Virtual Console from X</title>
		<link>http://www.33dots.com/index.php/linux/accessing-the-linux-virtual-console-from-x.html</link>
		<comments>http://www.33dots.com/index.php/linux/accessing-the-linux-virtual-console-from-x.html#comments</comments>
		<pubDate>Mon, 18 Jul 2011 15:52:03 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=356</guid>
		<description><![CDATA[I wanted to copy some text from my Virtual Console (Ctrl + Alt +F[1-6]).
Each of the Virtual Console have a corresponding /dev/vcs[1-6] file.
So doing a cat /dev/vcs2 you get the screen dump of Virtual Console 2.
Note that the output does not contain newline characters, so not properly formatted.
Now the /dev/ttyX files can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to copy some text from my Virtual Console (Ctrl + Alt +F[1-6]).<br />
Each of the Virtual Console have a corresponding <em>/dev/vcs[1-6]</em> file.</p>
<p>So doing a <code>cat /dev/vcs2</code> you get the screen dump of Virtual Console 2.<br />
Note that the output does not contain newline characters, so not properly formatted.</p>
<p>Now the <em>/dev/ttyX</em> files can be used to output text to the corresponding virtual console.</p>
<pre>
[root@localhost ~]# echo "what is the use of this?" > /dev/tty3
</pre>
<p>This will print &#8216;what is the use of this?&#8217; to the virtual console 3 </p>
<p>&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/linux/accessing-the-linux-virtual-console-from-x.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shrinking and growing a logical volume in Fedora 15</title>
		<link>http://www.33dots.com/index.php/linux/shrinking-and-growing-logica-volume.html</link>
		<comments>http://www.33dots.com/index.php/linux/shrinking-and-growing-logica-volume.html#comments</comments>
		<pubDate>Mon, 18 Jul 2011 15:44:34 +0000</pubDate>
		<dc:creator>tony</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.33dots.com/?p=346</guid>
		<description><![CDATA[During my Fedora 15 installation, i made two Logical Volumes, HomeLV 50GB for /home and RootLV 5GB for /. This was a mistake and very soon the / was full.

[root@localhost ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/FedVG-RootLV
4.8G  4.5G  4.9G  94% /

So i now wanted to shrink the /home and extend the /.
To [...]]]></description>
			<content:encoded><![CDATA[<p>During my Fedora 15 installation, i made two <strong>Logical Volumes</strong>, <em>HomeLV</em> 50GB for <em>/home</em> and <em>RootLV</em> 5GB for /. This was a mistake and very soon the / was full.</p>
<pre>
[root@localhost ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/FedVG-RootLV
4.8G  4.5G  4.9G  94% /
</pre>
<p>So i now wanted to shrink the<em> /home</em> and extend the /.</p>
<p>To reduce a logical volume. We first need to reduce the filesystem on it using <code>resize2fs</code> or <code>fsadm</code>. Then use <code>lvresize</code> (or <code>lvreduce</code>) to resize the logical volume.</p>
<pre>
[root@localhost ~]# resize2fs /dev/mapper/FedVG-HomLV 45G
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/mapper/FedVG-HomLV is mounted on /home; on-line resizing required
resize2fs: On-line shrinking not supported
</pre>
<p>Online shrinking is not supported. So now the option is to unmount  the underlying filesystem ie,<em> /home</em>. For that i had to logout of the GNOME and work in a Virtual console (Ctrl+Alt+F[1-6]).</p>
<p>Now, a bit more reading of the man page of <code>lvresize</code> and i found that by using <code>-r</code> switch, we can resize the underlying  filesystem  together with the logical volume.</p>
<pre>
[root@localhost ~]# umount /dev/mapper/FedVG-HomLV
[root@localhost ~]# lvresize -r -L -5G /dev/mapper/FedVG-HomLV
fsck from util-linux2.19.1
dev/mapper/FedVG-HomLV: 900/2949120 files (1.2% non-contiguous), 250200/11796480 blocks

resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/mapper/FedVG-HomLV to 10977280 (4k) blocks.
The filesystem on /dev/mapper/FedVG-HomLV is now 10977280 blocks long.

Reducing logical volume HomLV to 41.88 GiB
Logical volume HomLV successfully resized
</pre>
<p>The <code>-L</code> switch with <code>+/-nG</code> directs <code>lvresize</code> it to add or reduce <code>n</code> GB.</p>
<pre>
[root@localhost ~]# mount /home
[root@localhost ~]# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/FedVG-HomLV
42G  253M   39G   1% /home
</pre>
<p >
&nbsp;</p>
<p />
The next step is to extend the <em>RootLV</em> logical volume and then grow the root filesystem.</p>
<pre>
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/FedVG-RootLV
Extending logical volume RootLV to 10.00 GiB
Logical volume RootLV successfully resized
</pre>
<p>The <code>+100%FREE</code> option directs the <code>lvextend</code> to use the available free extents(free space). Note that the <code>-r</code> switch to resize the underlying filesystem is available here too though i didnt use it.</p>
<p>Grow the filesystem using <code>resizefs</code>. By default, most file system resizing tools will increase the size of the file system to be the size of the underlying logical volume so you do not need to worry about specifying the same size for each of the two commands.</p>
<pre>
[root@localhost ~]# resize2fs /dev/mapper/FedVG-RootLV
resize2fs 1.41.14 (22-Dec-2010)
Filesystem at /dev/mapper/FedVG-RootLV is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/FedVG-RootLV to 2621440 (4k) blocks.
The filesystem on /dev/mapper/FedVG-RootLV is now 2621440 blocks long.
</pre>
<p>Online growing of filesystem is supported although online shrinking not supported as we saw earlier.</p>
<pre>
[root@localhost ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/FedVG-RootLV
9.9G  4.5G  4.9G  48% /
</pre>
<p>&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.33dots.com/index.php/linux/shrinking-and-growing-logica-volume.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

