<?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>Noop.lv. Живу я тут &#187; bash</title>
	<atom:link href="http://www.noop.lv/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.noop.lv</link>
	<description>Маленькая личная помойка</description>
	<lastBuildDate>Fri, 06 Jan 2012 09:15:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>bash &#8211; stripping newlines and replacing with spaces</title>
		<link>http://www.noop.lv/2011/11/06/bash-stripping-newlines-and-replacing-with-spaces/</link>
		<comments>http://www.noop.lv/2011/11/06/bash-stripping-newlines-and-replacing-with-spaces/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 22:27:53 +0000</pubDate>
		<dc:creator>melnays</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://www.noop.lv/?p=144</guid>
		<description><![CDATA[For example, if you have an linux shell command output, newline-separated, and need to convert output to space-separated, pipe it to tr "\n" " " like so: &#160; dpkg -l &#124; grep php &#124; cut -d &#34; &#34; -f 3 &#8230; <a href="http://www.noop.lv/2011/11/06/bash-stripping-newlines-and-replacing-with-spaces/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For example, if you have an linux shell command output, newline-separated, and need to convert output to space-separated, pipe it to tr "\n" " " like so:</p>
<pre class="bash">&nbsp;
dpkg -l | <span style="color: #c20cb9; font-weight: bold;">grep</span> php | <span style="color: #c20cb9; font-weight: bold;">cut</span> -d <span style="color: #ff0000;">&quot; &quot;</span> -f <span style="color: #000000;">3</span> | <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff0000;">&quot; &quot;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.noop.lv/2011/11/06/bash-stripping-newlines-and-replacing-with-spaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bash: how to copy permissions recursively</title>
		<link>http://www.noop.lv/2011/10/25/bash-how-to-copy-permission-recursively/</link>
		<comments>http://www.noop.lv/2011/10/25/bash-how-to-copy-permission-recursively/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 13:39:43 +0000</pubDate>
		<dc:creator>melnays</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[permissions]]></category>

		<guid isPermaLink="false">http://www.noop.lv/?p=122</guid>
		<description><![CDATA[Imagine you were copying an, eg, virtual server from /server to /newserver, and messed permissions in /etc; thre's a way to copy permissions with this simple script: &#160; #!/bin/bash &#160; source=$1 target=$2 &#160; echo &#34;Copy files from $source to $target&#34; &#8230; <a href="http://www.noop.lv/2011/10/25/bash-how-to-copy-permission-recursively/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Imagine you were copying an, eg, virtual server from /server to /newserver, and messed permissions in /etc; thre's a way to copy permissions with this simple script:</p>
<pre class="bash">&nbsp;
<span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">source=</span>$<span style="color: #000000;">1</span>
<span style="color: #007800;">target=</span>$<span style="color: #000000;">2</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Copy files from $source to $target&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$source</span>
<span style="color: #007800;">files=</span>`<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #007800;">$source</span>`
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$files</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #808080; font-style: italic;">#this is some bash voodoo - string part replacement</span>
  <span style="color: #007800;">targetFile=</span><span style="color: #007800;">$target</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span>file<span style="color: #808080; font-style: italic;">#<span style="color: #007800;">$source</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></span>
  <span style="color: #808080; font-style: italic;">#stat <span style="color: #7a0874; font-weight: bold;">command</span> can accept -c parameter and <span style="color: #7a0874; font-weight: bold;">return</span> data <span style="color: #000000; font-weight: bold;">in</span> needed format</span>
  <span style="color: #808080; font-style: italic;">#where %u and %g are numeric user/group ids, and %a - octal permissions</span>
  <span style="color: #007800;">permissions=</span>`<span style="color: #c20cb9; font-weight: bold;">stat</span> -c%a <span style="color: #007800;">$file</span>`
  <span style="color: #007800;">ownership=</span>`<span style="color: #c20cb9; font-weight: bold;">stat</span> -c%u:%g <span style="color: #007800;">$file</span>`
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$targetFile</span> to <span style="color: #007800;">$ownership</span> <span style="color: #007800;">$permissions</span>
  <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #007800;">$permissions</span> <span style="color: #007800;">$targetFile</span>
  <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #007800;">$ownership</span> <span style="color: #007800;">$targetFile</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;</pre>
<p>invoke this like </p>
<pre>&nbsp;
./permissions.sh /server/etc /newserver/etc
&nbsp;</pre>
<p>change <code>%u:%g</code> to <code>%U:%G</code> if you prefer string id's (www-data:www-data) more than numeric (0:0)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.noop.lv/2011/10/25/bash-how-to-copy-permission-recursively/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

