<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
        <title>Yangyankai Blog</title>
        <description>Yangyankai Blog - Yankai Yang</description>
        <link>http://yangyankai.github.io</link>
        <atom:link href="http://yangyankai.github.io/rss.xml" rel="self" type="application/rss+xml" />
        <lastBuildDate>Thu, 06 Jan 2022 13:08:24 +0000</lastBuildDate>
        <pubDate>Thu, 06 Jan 2022 13:08:24 +0000</pubDate>
        <ttl>60</ttl>


        <item>
                <title>16 Bluetooth Key</title>
                <description>
&lt;p&gt;&lt;a href=&quot;/assets/images/bluetooth_key.pdf&quot;&gt;原文链接&lt;/a&gt;&lt;/p&gt;

</description>
                <link>http://yangyankai.github.io/post/2018/04/05/16-Bluetooth-Key</link>
                <guid>http://yangyankai.github.io/post/2018/04/05/16-Bluetooth-Key</guid>
                <pubDate>Thu, 05 Apr 2018 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>15 Android Framework</title>
                <description>
&lt;h3 id=&quot;android-system-has-more-than-1000-modules-in-general-each-mobile-phone-manufacturers-need-to-modify-the-more-than-100-modules-including-the-most-frequently-modified-36-modules&quot;&gt;&lt;em&gt;Android system has more than 1000 modules, in general, each mobile phone manufacturers need to modify the more than 100 modules, including the most frequently modified 36 modules.&lt;/em&gt;&lt;/h3&gt;

&lt;h3 id=&quot;services&quot;&gt;services&lt;/h3&gt;
&lt;h3 id=&quot;manager&quot;&gt;manager&lt;/h3&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/08/13/15-Android-Framework</link>
                <guid>http://yangyankai.github.io/post/2017/08/13/15-Android-Framework</guid>
                <pubDate>Sun, 13 Aug 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>14 Times At Lenovo</title>
                <description>
&lt;h4 id=&quot;has-been-a-levono-employee-for-one-year&quot;&gt;&lt;em&gt;Has been a levono employee for one year&lt;/em&gt;&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Be a highly motivated employee;&lt;/li&gt;
  &lt;li&gt;Make it clear why are you willing to do something or you don’t want to do it;&lt;/li&gt;
  &lt;li&gt;Be ready to ask for help AND give help to others;&lt;/li&gt;
  &lt;li&gt;Be primarily oriented towards solving problems;&lt;/li&gt;
  &lt;li&gt;Be modest.&lt;/li&gt;
&lt;/ul&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/08/13/14-times-at-lenovo</link>
                <guid>http://yangyankai.github.io/post/2017/08/13/14-times-at-lenovo</guid>
                <pubDate>Sun, 13 Aug 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>About</title>
                <description>&lt;p&gt;写字楼里写字间，写字间里程序员；&lt;/p&gt;

&lt;p&gt;程序人员写程序，又拿程序换酒钱。&lt;/p&gt;

&lt;p&gt;酒醒只在网上坐，酒醉还来网下眠；&lt;/p&gt;

&lt;p&gt;酒醉酒醒日复日，网上网下年复年。&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
             &lt;span class=&quot;o&quot;&gt;,----------------,&lt;/span&gt;              &lt;span class=&quot;o&quot;&gt;,---------,&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;,-----------------------,&lt;/span&gt;          &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;        ,&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;                      ,&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;        ,&quot;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+-----------------------+&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;        ,&quot;&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;.-----------------.&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;+---------+&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-==----&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;no&quot;&gt;I&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;LOVE&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;JAVA&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|/----|&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;---=&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;,/|====&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ooo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;      &lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// |(((( [33]|    ,&quot;&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-----------------&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; .;'| |((((     |  ,&quot;&lt;/span&gt;
     &lt;span class=&quot;o&quot;&gt;+-----------------------+&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;;;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;|,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;
        /_)______________(_/  //'   | +---------+
   ___________________________/___  `,
  /  oooooooooooooooo  .o.  oooo /,   \,&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-----------&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ooooooooooooooo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;o&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;ooo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//   ,`\--{)B     ,&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==========&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_ooo__ooo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;___________&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-----------------------------&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;29 Jul 2017&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/2017/07/29/13-about</link>
                <guid>http://yangyankai.github.io/2017/07/29/13-about</guid>
                <pubDate>Sat, 29 Jul 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>12 Vim_basic</title>
                <description>
&lt;h3 id=&quot;打开文件&quot;&gt;打开文件&lt;/h3&gt;
&lt;p&gt;vim +n FileName&lt;/p&gt;

&lt;h3 id=&quot;查找光标所在单词&quot;&gt;查找光标所在单词&lt;/h3&gt;
&lt;p&gt;shift + *&lt;/p&gt;

&lt;p&gt;### 查找
命令模式下，输入 /word 后回车，即查找word，
按 n 查找下一个匹配单词，按 N 查找上一个匹配单词&lt;/p&gt;

&lt;h3 id=&quot;移动光标&quot;&gt;移动光标&lt;/h3&gt;
&lt;p&gt;http://blog.csdn.net/bruce0532/article/details/8312933
以单词向前移动 w，以单词向后移动b&lt;/p&gt;

&lt;h3 id=&quot;替换&quot;&gt;替换&lt;/h3&gt;
&lt;p&gt;http://www.cnblogs.com/jianyungsun/archive/2011/03/20/1989276.html&lt;/p&gt;

&lt;h3 id=&quot;delete&quot;&gt;delete&lt;/h3&gt;
&lt;p&gt;x 删除当前光标下的字符
dw 删除光标之后的单词剩余部分。
d$ 删除光标之后的该行剩余部分。
dd 删除当前行。&lt;/p&gt;

&lt;p&gt;c 功能和d相同，区别在于完成删除操作后进入INSERT MODE
cc 也是删除当前行，然后进入INSERT MODE&lt;/p&gt;

&lt;h3 id=&quot;拷贝与粘贴&quot;&gt;拷贝与粘贴&lt;/h3&gt;
&lt;p&gt;拷贝文本
y: 拷贝选中内容
yy: 拷贝当前行
粘贴
p&lt;/p&gt;

&lt;h3 id=&quot;撤销与重做&quot;&gt;撤销与重做&lt;/h3&gt;
&lt;p&gt;u: 撤销上一个动作
Ctrl-r: 重做上一个动作&lt;/p&gt;

&lt;h3 id=&quot;设置vim-默认显示行号&quot;&gt;设置vim 默认显示行号&lt;/h3&gt;
&lt;p&gt;在VI的命令模式下输入“:set nu”
  或者修改vi配置文件“vi ~/.vimrc”，在其中添加“set nu”
  在VI的命令模式下输入“:set nu”，就有行号了。
  但是想将这个设置写进VI的配置文件，就
  # vi ~/.vimre
  在这个文件中，添加
  set nu&lt;/p&gt;

&lt;h3 id=&quot;跳转指定行数&quot;&gt;跳转指定行数&lt;/h3&gt;
&lt;dl&gt;
  &lt;dt&gt;在编辑模式下输入&lt;/dt&gt;
  &lt;dt&gt;ngg 或者 nG&lt;/dt&gt;
  &lt;dt&gt;n为指定的行数(如25)&lt;/dt&gt;
  &lt;dt&gt;25gg或者25G 跳转到第25行.&lt;/dt&gt;
  &lt;dt&gt;在命令模式下输入行号n&lt;/dt&gt;
  &lt;dd&gt;n&lt;/dd&gt;
&lt;/dl&gt;

&lt;h3 id=&quot;查看当然光标所在的行&quot;&gt;查看当然光标所在的行&lt;/h3&gt;
&lt;p&gt;Ctrl+g&lt;/p&gt;

&lt;p&gt;教程&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.csdn.net/niushuai666/article/details/7275406&quot;&gt;http://blog.csdn.net/niushuai666/article/details/7275406&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.chinaunix.net/uid-24567872-id-3425929.html&quot;&gt;http://blog.chinaunix.net/uid-24567872-id-3425929.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.cnblogs.com/Jack47/p/vim-resources-and-tips.html&quot;&gt;http://www.cnblogs.com/Jack47/p/vim-resources-and-tips.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.jobbole.com/86132/&quot;&gt;http://blog.jobbole.com/86132/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.jianshu.com/p/bcbe916f97e1&quot;&gt;http://www.jianshu.com/p/bcbe916f97e1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ruanyf/articles/blob/master/dev/vim/operation.md&quot;&gt;https://github.com/ruanyf/articles/blob/master/dev/vim/operation.md&lt;/a&gt;&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/06/19/12-vim_basic</link>
                <guid>http://yangyankai.github.io/post/2017/06/19/12-vim_basic</guid>
                <pubDate>Mon, 19 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>11 Algorithms</title>
                <description>
&lt;h4 id=&quot;选了10个编程题目复习一下基础的算法挑选的时候找了尽可能少的数量去覆盖尽可能多的算法思想&quot;&gt;选了10个编程题目，复习一下基础的算法。挑选的时候找了尽可能少的数量，去覆盖尽可能多的算法思想。&lt;/h4&gt;
&lt;h4 id=&quot;分别是以下10个&quot;&gt;分别是以下10个：&lt;/h4&gt;

&lt;p&gt;1 快速排序&lt;br /&gt;
2 全排列 &lt;br /&gt;
3 平衡二叉树&lt;br /&gt;
4 最大堆 &lt;br /&gt;
5 并查集  &lt;br /&gt;
6 Prim最小生成树&lt;br /&gt;
7 Dijkstra 最短路径&lt;br /&gt;
8 KMP&lt;br /&gt;
9 LCS&lt;br /&gt;
10 反转链表保存的字符串&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;

&lt;h4 id=&quot;分割线后面的是这个编程问题包含的知识点&quot;&gt;分割线后面的是这个编程问题包含的知识点&lt;/h4&gt;

&lt;p&gt;1 快速排序 | 分治、递归、排序&lt;br /&gt;
2 全排列 | 递归、排列问题&lt;br /&gt;
3 平衡二叉树 | 排序、数据结构树及其遍历、递归&lt;br /&gt;
4 最大堆  | 排序、数据结构堆和数组&lt;br /&gt;
5 并查集  | 数据结构、连通问题&lt;br /&gt;
6 Prim 最小生成树 | 数据结构图及其遍历、最小生成树问题、贪心&lt;br /&gt;
7 Dijkstra 最短路径 | 数据结构图及其遍历、最短路径、动态规划&lt;br /&gt;
8 字符串匹配 KMP | 字符串&lt;br /&gt;
9 最长公共子序列 LCS | 二维数组、递归、动态规划&lt;br /&gt;
10 反转链表保存的字符串 ｜ 数据结构链表操作：创建、添加和遍历。&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;
&lt;h4 id=&quot;代码不贴出来了这些最常见的算法网上一搜就有&quot;&gt;代码不贴出来了，这些最常见的算法网上一搜就有。&lt;/h4&gt;
&lt;p&gt;最好做到可以默写，并独自生成测试数据来测试自己的程序。&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/06/19/11-algorithms</link>
                <guid>http://yangyankai.github.io/post/2017/06/19/11-algorithms</guid>
                <pubDate>Mon, 19 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Android tools</title>
                <description>&lt;h2&gt;Android tools&lt;/h2&gt;

&lt;p&gt;Topic about Android tools&lt;/p&gt;


&lt;p&gt;19 Jun 2017&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/2017/06/19/10-android_tools</link>
                <guid>http://yangyankai.github.io/2017/06/19/10-android_tools</guid>
                <pubDate>Mon, 19 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Chat Java</title>
                <description>&lt;h2&gt;Chat Java&lt;/h2&gt;

&lt;p&gt;Topic about Java&lt;/p&gt;


&lt;p&gt;18 Jun 2017&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/2017/06/18/9-chat_java</link>
                <guid>http://yangyankai.github.io/2017/06/18/9-chat_java</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>8 Android_power_consumption</title>
                <description>
&lt;p&gt;1 看是否存在耗电异常情况。
Android 耗电情况记录在 batterystats 文件中，使用 adb shell dumpsys batterystats 命令查看。主要看经过了多长时间，耗了多少电，有多少应用在后台运行，并分析这些运行情况。&lt;/p&gt;

&lt;p&gt;standby for a night 
耗电&lt;/p&gt;

&lt;p&gt;3%-5%	良&lt;/p&gt;

&lt;p&gt;5%-8%	较好&lt;/p&gt;

&lt;p&gt;8%-10%	较差&lt;/p&gt;

&lt;p&gt;一晚上待机耗电超过 10% 以上不合格的，需要找出耗电多的原因并分析解决。&lt;/p&gt;

&lt;h3 id=&quot;1-text-analysic&quot;&gt;1 text analysic&lt;/h3&gt;

&lt;p&gt;我一般会看 batterystats 文件中  Estimated power use (mAh) 项，查看主要耗电的 uid，&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Estimated power use (mAh):
  Capacity: 3500, Computed drain: 1987, actual drain: 3150-3185
  Uid 9999: 1239 ( cpu=1239 )
  Unaccounted: 1163 ( )
  Screen: 241
  Idle: 232
  Uid 0: 83.1 ( cpu=82.8 radio=0.314 wifi=0.00000209 )
  Uid u0a192: 53.8 ( cpu=53.7 wifi=0.0960 sensor=0.0103 )
  Uid 1000: 44.5 ( cpu=42.3 wake=0.716 radio=1.01 wifi=0.125 gps=0.254 sensor=0.0744 )
  Uid u0a169: 20.0 ( cpu=19.9 sensor=0.0224 )
  Uid u0a126: 16.8 ( cpu=16.6 wifi=0.197 sensor=0.00712 )
  Uid u0a39: 13.2 ( cpu=13.2 wake=0.00348 sensor=0.000364 )
  Wifi: 12.3 ( cpu=0.192 wifi=12.1 )
  Uid u0a167: 4.49 ( cpu=4.05 radio=0.432 sensor=0.0110 )
  Uid u0a35: 3.81 ( cpu=2.22 wake=0.0645 radio=1.53 )
  Uid 1036: 2.86 ( cpu=2.86 )
  Uid u0a67: 2.74 ( cpu=2.51 wake=0.0120 wifi=0.205 gps=0.0160 sensor=0.0000576 )
  ......
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;如果 uid &amp;lt; 10000 是系统耗电，如果是 uid &amp;gt;= 10000 是应用耗电。这一步可以判断是哪个 uid 耗电过多。
接下来可以结合应用持有的 wake locks 看，在 batterystats 中有两项 wakelocks。All partial wake locks 和 All kernel wake locks。&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;All partial wake locks:
Wake lock 1000 deviceidle_maint: 55s 242ms (5 times) realtime
Wake lock u0a70 httpGet: 23s 1ms (2 times) realtime
Wake lock u0a70 PTWakeLock: 12s 147ms (24 times) realtime
Wake lock 1000 WakeLock for Memory Clean: 11s 19ms (2 times) realtime
Wake lock 1000 AnyMotionDetector: 10s 26ms (1 times) realtime

......
All kernel wake locks:
Kernel Wake lock wcnss_filter_lock: 5h 9m 11s 31ms (0 times) realtime
Kernel Wake lock PowerManagerService.WakeLocks: 2m 22s 356ms (178 times) realtime
Kernel Wake lock qcom_rx_wakelock: 1m 44s 679ms (1860 times) realtime
Kernel Wake lock qpnp_fg_update_sram: 1m 5s 293ms (3696 times) realtime
Kernel Wake lock qpnp_fg_memaccess: 1m 3s 433ms (72127 times) realtime
Kernel Wake lock wlan        : 11s 603ms (6 times) realtime
Kernel Wake lock NETLINK     : 11s 469ms (12000 times) realtime
......
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;到这一步可以确认哪个 uid 持有哪个 wakelock 导致系统耗电过多。
如果是 App 导致耗电过多，能排除系统原因就可以归到 APP 原因，如不能排除系统原因接着需要分析。
如果是 uid &amp;lt; 10000,则是系统原因，需要继续分析。&lt;/p&gt;

&lt;h3 id=&quot;2-谷歌电量分析工具&quot;&gt;2 谷歌电量分析工具&lt;/h3&gt;
&lt;p&gt;通用的耗电信息 battery stats&lt;/p&gt;

&lt;h4 id=&quot;battery-historian-v1-needs-python-environment&quot;&gt;Battery-Historian V1 (needs Python environment)&lt;/h4&gt;

&lt;p&gt;数据源：         adb shell dumpsys batterystats &amp;gt; data_v1 &lt;br /&gt;
分析工具：     执行Python脚本 historian.py &lt;br /&gt;
命令：              Python historian.py –a data_v1 &amp;gt; data_v1.html&lt;br /&gt;
运行：              用谷歌浏览打开 data_v1.html（需要VPN），就可以看到图形化界面&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/BatteryHistorian_1.png&quot; alt=&quot;v1&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;battery-historian-v2-needs-go-environment&quot;&gt;Battery-Historian V2 (needs Go environment)&lt;/h4&gt;

&lt;p&gt;数据源：         adb bugreport data_v2.zip  &lt;br /&gt;
分析工具：     使用Battery-Historian V2 Go 项目分析数据 &lt;br /&gt;
命令：              go run cmd\battery-historian\battery-historian.go&lt;br /&gt;
运行：              用谷歌浏览打开http://localhost:9999/ （需要VPN），在界面中选择data_v2.zip
&lt;img src=&quot;/assets/images/BatteryHistorian_2.png&quot; alt=&quot;v2&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;2-other&quot;&gt;2 other&lt;/h3&gt;
&lt;p&gt;除了从android batterystats 中分析问题，各厂商可能会加入自己的一些feature，记录耗电和 CPU 实用信息等，可辅助分析异常耗电、发热等问题&lt;/p&gt;

</description>
                <link>http://yangyankai.github.io/post/2017/06/18/8-android_power_consumption</link>
                <guid>http://yangyankai.github.io/post/2017/06/18/8-android_power_consumption</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>7 Aosp_battery_statistics</title>
                <description>
&lt;h3 id=&quot;1电量分类batterysipper&quot;&gt;1.电量分类BatterySipper&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;public enum DrainType {
        IDLE,  // 手机待机
        CELL,  // 移动网络待机
        PHONE,    // 语音通话
        WIFI,           //   WiFi
        BLUETOOTH, //  蓝牙
        FLASHLIGHT, //闪光灯
        SCREEN,      屏幕
        APP,          // App，软件
        USER, // UserManager
        UNACCOUNTED, // 系统耗电比计算的多
        OVERCOUNTED, // 系统耗电比计算的少
        CAMERA    // 摄像头
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;电量统计各类型在其他语言中如何如何命名，参看考 Settings 中的下面代码，找到xml/value 中 string 对应翻译&lt;/p&gt;

&lt;p&gt;BatterySipper&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
        switch (sipper.drainType) {
            case IDLE: 
                name = context.getResources().getString(R.string.power_idle);
                iconId = R.drawable.ic_settings_phone_idle;
                break;
            case CELL:
                name = context.getResources().getString(R.string.power_cell);
                iconId = R.drawable.ic_settings_cell_standby;
                break;
            case PHONE:
                name = context.getResources().getString(R.string.power_phone);
                iconId = R.drawable.ic_settings_voice_calls;
                break;
            case WIFI:  
                name = context.getResources().getString(R.string.power_wifi);
                iconId = R.drawable.ic_settings_wifi;
                break;
            case BLUETOOTH: 
                name = context.getResources().getString(R.string.power_bluetooth);
                iconId = R.drawable.ic_settings_bluetooth;
                break;
            case SCREEN:
                name = context.getResources().getString(R.string.power_screen);
                iconId = R.drawable.ic_settings_display;
                break;
            case FLASHLIGHT:
                name = context.getResources().getString(R.string.power_flashlight);
                iconId = R.drawable.ic_settings_display;
                break;
            case APP:
                name = sipper.packageWithHighestDrain;
                break;
            case USER: {
                UserInfo info = um.getUserInfo(sipper.userId); 
                if (info != null) {
                    icon = Utils.getUserIcon(context, um, info);
                    name = Utils.getUserLabel(context, info);
                } else {
                    icon = null;
                    name = context.getResources().getString(
                            R.string.running_process_item_removed_user_label);
                }
            } break;
            case UNACCOUNTED:
                name = context.getResources().getString(R.string.power_unaccounted);
                iconId = R.drawable.ic_power_system;
                break;
            case OVERCOUNTED:
                name = context.getResources().getString(R.string.power_overcounted);
                iconId = R.drawable.ic_power_system;
                break;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2软硬件耗电统计&quot;&gt;2软硬件耗电统计&lt;/h3&gt;
&lt;p&gt;硬件耗电&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;                case PHONE :
                case SCREEN : 屏幕
                case FLASHLIGHT:
                case WIFI :
                case BLUETOOTH:
                case IDLE:
                case CELL:
                        isMisc = true;
                        percentOfTotal = (sipper.totalPowerMah * 100)/ hardwareTotal;
                        Log.d(TAG,&quot;percentOfTotal : &quot;+hardwareTotal);
                    break;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;软件耗电&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;                case APP:
                    break;
                default:
                    break;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
                <link>http://yangyankai.github.io/post/2017/06/18/7-aosp_battery_statistics</link>
                <guid>http://yangyankai.github.io/post/2017/06/18/7-aosp_battery_statistics</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>6 Aosp_brighten_screen</title>
                <description>
&lt;h3 id=&quot;phonewindowmanagejava--&quot;&gt;PhoneWindowManage.java  :&lt;/h3&gt;

&lt;p&gt;KEYCODE_POWER -&amp;gt;  interceptPowerKeyDown(…) -&amp;gt; wakeUpFromPowerKey() -&amp;gt; wakeUp()  -&amp;gt; mPowerManager.wakeUp(…)&lt;/p&gt;

&lt;h3 id=&quot;powermanagerservice&quot;&gt;PowerManagerService:&lt;/h3&gt;

&lt;p&gt;wakeUp(..) -&amp;gt; wakeUpInternal(…) -&amp;gt; updatePowerStateLock -&amp;gt; updateDisplayPowerStateLocked -&amp;gt; mDisplayManagerInternal.requestPowerState(…)&lt;/p&gt;

&lt;h3 id=&quot;diaplaypowercontrollerjava&quot;&gt;DiaplayPowerController.java:&lt;/h3&gt;
&lt;p&gt;requestPowerState(…) -&amp;gt; sendUpdatePowerStateLocked() -&amp;gt; sendMessage(MSG_UPDATE_POWER_STATE) -&amp;gt; updatePowerState() -&amp;gt; animateScreenStateChange -&amp;gt; setScreenState()&lt;/p&gt;

&lt;p&gt;picture from other person’s blog
&lt;img src=&quot;/assets/images/brighten_screen.png&quot; alt=&quot;brighten_screen&quot; /&gt;&lt;/p&gt;

</description>
                <link>http://yangyankai.github.io/post/2017/06/18/6-aosp_brighten_screen</link>
                <guid>http://yangyankai.github.io/post/2017/06/18/6-aosp_brighten_screen</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>5 Aosp_automatic_brightness</title>
                <description>
&lt;p&gt;源码阅读：Android 自动背光机制&lt;/p&gt;

&lt;p&gt;0 刷新机制概览（使用handler实现）
1 传感器和缓存
2 计算buffer中的加权后的光强。
3 通过光强计算亮度
4 更新亮度
5 流程总结
附: RampAnimator.java 背光动画&lt;/p&gt;

&lt;p&gt;DisplayPowerController 中调用AutomaticBrightnessController 实现自动背光，AutomaticBrightnessController 采集缓存和计算自动背光&lt;/p&gt;
&lt;h3 id=&quot;0-刷新机制概览使用handler实现&quot;&gt;0 刷新机制概览（使用handler实现）&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/AOSP-automatic-brightness-1.png&quot; alt=&quot;picture-1 refresh&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;1-传感器和缓存&quot;&gt;1 传感器和缓存&lt;/h3&gt;

&lt;p&gt;1-1从传感器获取光强，单位Lux，并记录时间。 时间和光强作为键值对保存到缓存中
  private final SensorEventListener mLightSensorListener = new SensorEventListener() {
        @Override
        public void onSensorChanged(SensorEvent event) {&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;            final long time = SystemClock.uptimeMillis();
            final float lux = event.values[0];
            handleLightSensorEvent(time, lux);
        }
    } }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;1-2 缓存AmbientLightRingBuffer&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; AutomaticBrightnessController 中定义了一个AmbientLightRingBuffer环形缓存。 里面存放键值对 （时间和光强）
 private float[] mRingLux;
 private long[] mRingTime; 这里的时间是：SystemClock.uptimeMillis()//从boot开始的毫秒数

 添加元素
 public void push(long time, float lux) { }

 每次给buffer中放数据的时候回清理掉5s以前的数据，只保存5s内的数据。
 public void prune(long horizon) { }

 缓存时间为 horizon =time - AMBIENT_LIGHT_HORIZON； 就是最近5000ms的光强缓存。（谷歌原生为最近10000ms缓存）
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;注意：
     是最近5s的缓存。一般来说光敏传感器最快为100ms接受几个lux，buffer中有50个数据，但是当光强稳定的时候不在接收数据。只有周围光强变化的时候，这个事件 public void onSensorChanged(SensorEvent event) { } 才会触发。这时候buffer中数据个数会小于50个。&lt;/p&gt;

&lt;h3 id=&quot;2-计算buffer中的加权后的光强&quot;&gt;2 计算buffer中的加权后的光强。&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/assets/images/AOSP-automatic-brightness-2.png&quot; alt=&quot;picture-3 refresh&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  Lux i 是buffer中的光强，Weighti是对应光强的权重。Weighti：Luxi的Timei通过积分后算出来的
       
           Weighti=Time1*（Time1*0.5 + b）-Time2*（Time2*0.5 + b）

 mBrighteningLuxThreshold = mAmbientLux * (1.0f + BRIGHTENING_LIGHT_HYSTERESIS); // 增亮阈值
 mDarkeningLuxThreshold = mAmbientLux * (1.0f - DARKENING_LIGHT_HYSTERESIS);       // 变暗阈值 如新计算出来的 mAmbientLux 大于的mBrighteningLuxThreshold或小于mDarkeningLuxThreshold，则去计算brightness并更新亮度。

 开始下一次递归： mHandler.sendEmptyMessageAtTime(MSG_UPDATE_AMBIENT_LUX, nextTransitionTime); 递归周期：nextTransitionTime 是根据buffer中的数据与增亮阈值和变暗阈值计算出来的。  遍历检测buffer中是否数据达到阈值，再根据变亮mBrighteningLightDebounceConfig 或者变暗延时mDarkeningLightDebounceConfig 和;mLightSensorRate，计算出最终nextTransitionTime；
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-通过光强计算亮度&quot;&gt;3 通过光强计算亮度&lt;/h3&gt;

&lt;p&gt;3-1 计算value，value范围 0 - 1
 float value = mScreenAutoBrightnessSpline.interpolate(mAmbientLux);
mScreenAutoBrightnessSpline.interpolate()//BSP首先给出一些点的映射，这个函数会自动补齐其他的点。得出光强和lux的映射关系。
BSP给出点的映射所在目录： platform/LINUX/android/device/fancymaker/z2x/overlay/frameworks/base/core/res/res/values.config_autobrightness.xml&lt;/p&gt;

&lt;p&gt;3-2 计算亮度，brighness范围0-255
亮度 brightness=value * 255;&lt;/p&gt;

&lt;h3 id=&quot;4-更新亮度&quot;&gt;4 更新亮度&lt;/h3&gt;
&lt;p&gt;mCallbacks.updateBrightness();&lt;/p&gt;

&lt;h3 id=&quot;5-流程总结&quot;&gt;5 流程总结&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/AOSP-automatic-brightness-3.png&quot; alt=&quot;picture-3 refresh&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;附&quot;&gt;附：&lt;/h3&gt;
&lt;h3 id=&quot;rampanimatorjava-背光动画&quot;&gt;RampAnimator.java 背光动画&lt;/h3&gt;

&lt;p&gt;速度：                   mRate，表示帧数，亮度为0-255，一共256帧
过渡间隔：             Math.abs(target - mCurrentValue);
过渡时间：             Math.abs(target - mCurrentValue) / mRate
举个例子：
     亮度从100到200，帧数mRate为50.这时候过渡时间为t =（200-100）/50 = 2s,需要两秒完成这个动画。&lt;/p&gt;

&lt;p&gt;注意：
当正在发生一个动画的时候，出现一个新的动画，这时候采取最接近当前动画的一个去更新。
举个例子：
     a. 刚开始亮度为0；
     b. 第一个动画到200；
     c. 当b中的动画没有完成时，如果有一个新的动画x。
          若 x &amp;lt;= 200,则直接到x，不再向200过渡；
          若 x&amp;gt; 200,则匀速经过200，然后匀速达到x；&lt;/p&gt;

&lt;h3 id=&quot;动画机制来自递归&quot;&gt;动画机制来自递归：&lt;/h3&gt;
&lt;p&gt;1： 
     postAnimationCallback(){
          mAnimationCallback()；
     }
2：
     mAnimationCallback(){
          if(mTargetValue!=mCurrentValue){
               postAnimationCallback
          }&lt;br /&gt;
     }&lt;/p&gt;

&lt;h3 id=&quot;自动背光修改亮度流程&quot;&gt;自动背光修改亮度流程&lt;/h3&gt;
&lt;p&gt;AutomaticBrightnessController&lt;/p&gt;

&lt;p&gt;RampAnimator.java  mProperty.setValue(mObject, mCurrentValue)&lt;/p&gt;

&lt;p&gt;DisplayPowerController.java 中实例化 new RampAnimator&lt;DispalyPowerState&gt;(mPowerState,DispalyPowerState.SCREEN_BRIGHTNESS);&lt;/DispalyPowerState&gt;&lt;/p&gt;

&lt;p&gt;DispalyPowerState.java  DispalyPowerState.setValue(){object.setScreenBrightness(value)};  …… -&amp;gt;  listener.run()  run(){  requestDisplayState()}&lt;/p&gt;

&lt;p&gt;ZuiDispalyPowerState.java setBrightnessChangedListener_ZUK( ){mBrightnessChangedListener.onBrightnessChanged(Brightness);}&lt;/p&gt;

&lt;p&gt;ZuiDisplayPowerControlle.java  setBrightnessChangedListener_ZUK(mZuiBrightnessChangedListener )   =new ZuiBrightnessChangedListener{
onBrightnessChanghe(){
//修改数据库,字段为：Settings.System.SCREEN_BRIGHTNESS
}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

</description>
                <link>http://yangyankai.github.io/post/2017/06/18/5-aosp_automatic_brightness</link>
                <guid>http://yangyankai.github.io/post/2017/06/18/5-aosp_automatic_brightness</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>4 Adb_command</title>
                <description>
&lt;p&gt; 
 
 &lt;/p&gt;
&lt;h3 id=&quot;adb-选择链接指定devices&quot;&gt;adb 选择链接指定devices&lt;/h3&gt;
&lt;p&gt;adb  -s NHTC170052 shell
 
 &lt;/p&gt;
&lt;h3 id=&quot;关机命令&quot;&gt;关机命令&lt;/h3&gt;
&lt;p&gt;adb shell reboot -p
 &lt;/p&gt;
&lt;h3 id=&quot;拷贝东西到电脑&quot;&gt;拷贝东西到电脑&lt;/h3&gt;
&lt;p&gt;adb pull xxx D:/ 不行的时候，再给D盘下指定个目录
adb pull data/user_de/0/com.android.shell/files/bugreports/bugreport-NZS26.71-19-2017-05-27-14-25-15.zip D:\Zuisys
adb pull system/framework/services.jar D:/
 &lt;/p&gt;
&lt;h3 id=&quot;通过命令行执行adb-shell-am-broadcast发送广播通知&quot;&gt;通过命令行执行adb shell am broadcast发送广播通知。&lt;/h3&gt;
&lt;p&gt;adb shell am broadcast 后面的参数有：
 
[-a &lt;ACTION&gt;]
[-d &lt;DATA_URI&gt;]
[-t &lt;MIME_TYPE&gt;]
[-c &lt;CATEGORY&gt; [-c &lt;CATEGORY&gt;] ...]
[-e|--es &lt;EXTRA_KEY&gt; &lt;EXTRA_STRING_VALUE&gt; ...]
[--ez &lt;EXTRA_KEY&gt; &lt;EXTRA_BOOLEAN_VALUE&gt; ...]
[-e|--ei &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt; ...]
[-n &lt;COMPONENT&gt;]
[-f &lt;FLAGS&gt;] [&lt;URI&gt;]
 
例如：
adb shell am broadcast -a com.Android.test --es test_string &quot;this is test string&quot; --ei test_int 100 --ez test_boolean true
 
 
adb 读写 setting
adb 读取 Global 设置中的值 adb shell settings get global charging_sounds 其中&quot;charging_sounds&quot;为键
adb 写入 System 设置中的值 adb shell settings put system screen_brightness
 
user版本，不能root。adb root 无效
 &lt;/URI&gt;&lt;/FLAGS&gt;&lt;/COMPONENT&gt;&lt;/EXTRA_INT_VALUE&gt;&lt;/EXTRA_KEY&gt;&lt;/EXTRA_BOOLEAN_VALUE&gt;&lt;/EXTRA_KEY&gt;&lt;/EXTRA_STRING_VALUE&gt;&lt;/EXTRA_KEY&gt;&lt;/CATEGORY&gt;&lt;/CATEGORY&gt;&lt;/MIME_TYPE&gt;&lt;/DATA_URI&gt;&lt;/ACTION&gt;&lt;/p&gt;
&lt;h3 id=&quot;查看进程&quot;&gt;查看进程&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ps | grep ^u0&lt;/code&gt;
 
 &lt;/p&gt;
&lt;h3 id=&quot;查看当前app&quot;&gt;查看当前App&lt;/h3&gt;
&lt;p&gt;adb shell dumpsys window windows | grep -E ‘mCurrentFocus|mFocusedApp’
 
 &lt;/p&gt;
&lt;h3 id=&quot;app的安装&quot;&gt;APP的安装&lt;/h3&gt;
&lt;p&gt;android 安装非系统apk
第一步，把apk放到手机上
adb push D:\yangyk3\StudioProjects\HelloAndroid\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.yangyk3.helloandroid
第二步，安装手机上的apk
adb shell pm install -r “/data/local/tmp/com.example.yangyk3.helloandroid
 &lt;/p&gt;
&lt;h3 id=&quot;android安装系统apk&quot;&gt;android安装系统apk&lt;/h3&gt;
&lt;p&gt;把路径换为 /system/app 即可
 &lt;/p&gt;
&lt;h3 id=&quot;卸载apk&quot;&gt;卸载apk&lt;/h3&gt;
&lt;p&gt;adb uninstall  “/data/local/tmp/com.example.yangyk3.helloandroid.apk”
adb uninstall com.example
 &lt;/p&gt;
&lt;h3 id=&quot;systemui&quot;&gt;SystemUI&lt;/h3&gt;
&lt;p&gt;替换SystemUI， 原生的名字SystemUI.apk ， Zuk的名字为XuiSystemUI.apk.把原生的重命名为XuiSystemUI.apk。push到/system/priv-ap/XuiSystemUI/目录下
 &lt;/p&gt;
&lt;h3 id=&quot;adb-命令&quot;&gt;ADB 命令&lt;/h3&gt;
&lt;p&gt;进入adb shell
adb shell
退出
exit
重启命令 
adb reroot
http://www.cnblogs.com/playing/archive/2010/09/19/1830799.html
http://blog.csdn.net/janronehoo/article/details/6863772/
 &lt;/p&gt;
&lt;h3 id=&quot;abd在手机里面找东西先root&quot;&gt;abd在手机里面找东西先root&lt;/h3&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h3 id=&quot;sqlite&quot;&gt;sqlite&lt;/h3&gt;
&lt;p&gt;进入sqlite
adb shell(进入shell)
sqlite3 （进入sqlite）
退出sqlite
.quit （退出sqlite，返回shell）
查看数据库：
sqlite3 demo.db  [Android   .open demo.dp]
查看表
.tables
Atable Btable
查看数据库
select * from Btable&lt;/p&gt;

&lt;h3 id=&quot;查看日志&quot;&gt;查看日志&lt;/h3&gt;
&lt;p&gt;adb logcat -s 标签名
 &lt;/p&gt;
&lt;h3 id=&quot;删除系统app&quot;&gt;删除系统App&lt;/h3&gt;
&lt;p&gt;adb remount （重新挂载系统分区，使系统分区重新可写）。
      adb shell
      cd system/app
      rm *.apk
 
 
 &lt;/p&gt;
&lt;h3 id=&quot;拷贝&quot;&gt;拷贝&lt;/h3&gt;
&lt;p&gt;cp  file  file_2
 &lt;/p&gt;
&lt;h3 id=&quot;卸载-datadata-下的某个包名对应的apk&quot;&gt;卸载 data/data 下的某个包名对应的apk&lt;/h3&gt;
&lt;p&gt;adb uninstall com.example.hello  //不需要到某个apk
 &lt;/p&gt;
&lt;h3 id=&quot;替换jar包&quot;&gt;替换Jar包&lt;/h3&gt;
&lt;p&gt;adb push D:\ZUI\z2x\services.jar  system/framework/services.jar
 &lt;/p&gt;
&lt;h3 id=&quot;重命名-rename&quot;&gt;重命名 rename&lt;/h3&gt;
&lt;p&gt;例如: rename 1.txt 2.bat
文件1.txt 变为2.bat
 &lt;/p&gt;
&lt;h3 id=&quot;关机&quot;&gt;关机&lt;/h3&gt;
&lt;p&gt;adb shell shutdown
 &lt;/p&gt;
&lt;h3 id=&quot;查看手机版本信息&quot;&gt;查看手机版本信息&lt;/h3&gt;
&lt;p&gt;adb shell getprop
可查看手机系统的具体命令如下：
getprop 查看机器的全部信息参数
getprop ro.serialno 查看机器的SN号
getprop ro.carrier 查看机器的CID号
getprop ro.hardware 查看机器板子代号
 
adb shell getprop | grep build
[ro.build.args]: []
[ro.build.characteristics]: [phone]
[ro.build.cta]: [noncta]
[ro.build.date.utc]: [1495871049]
[ro.build.date]: [2017年 05月 27日 星期六 15:44:09 CST]
[ro.build.description]: [meizu_PRO5-user 5.1 LMY47D 1495870962 release-keys]
[ro.build.display.id]: [Flyme 6.1.0.0A]
[ro.build.fingerprint]: [Meizu/meizu_PRO5/PRO5:5.1/LMY47D/1495870962:user/release-keys]
[ro.build.flavor]: [meizu_m86-user]
[ro.build.host]: [Mz-Builder-l3]
[ro.build.id]: [LMY47D]
[ro.build.inside.id]: [5.1-20170527152857]
[ro.build.mask.id]: [5.1-1495870137_stable]
[ro.build.product]: [PRO5]
[ro.build.tags]: [release-keys]
[ro.build.type]: [user]
[ro.build.user]: [flyme]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [1495870962]
[ro.build.version.release]: [5.1]
[ro.build.version.sdk]: [22]
[ro.build.version.security_patch]: [2017-04-05]
[ro.meizu.build.spt]: [0] 
 &lt;/p&gt;
&lt;h3 id=&quot;连接-usb-时不充电&quot;&gt;连接 USB 时不充电&lt;/h3&gt;
&lt;p&gt;adb shell dumpsys battery unplug
 &lt;/p&gt;
&lt;h3 id=&quot;重置为充电状态&quot;&gt;重置为充电状态&lt;/h3&gt;
&lt;p&gt;adb shell dumpsys battery reset
 &lt;/p&gt;
&lt;h3 id=&quot;进入-idle&quot;&gt;进入 IDLE&lt;/h3&gt;
&lt;p&gt;adb shell dumpsys deviceidle step
 
 &lt;/p&gt;
&lt;h3 id=&quot;adb-命令链接wifi&quot;&gt;adb 命令链接wifi&lt;/h3&gt;
&lt;p&gt;adb push D:/ZUIsys/wpa_supplicant.conf  /data/misc/wifi/   // 第一次手动连接wifi，之后把这个文件pull出来，刷机之后再把文件push进去
然后重启一下wifi
打开WIFI指令  
     svc wifi enable
关闭WIFI指令
    svc wifi disable
 
 &lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/06/18/4-adb_command</link>
                <guid>http://yangyankai.github.io/post/2017/06/18/4-adb_command</guid>
                <pubDate>Sun, 18 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>3 Git_command</title>
                <description>
&lt;h2 id=&quot;git&quot;&gt;Git&lt;/h2&gt;

&lt;h3 id=&quot;查看历史&quot;&gt;查看历史&lt;/h3&gt;
&lt;p&gt;git blame 文件1
git show 426eb1b84// 打开某次记录&lt;/p&gt;

&lt;h3 id=&quot;gitnon-fast-forward&quot;&gt;Git：（Non-fast-forward）&lt;/h3&gt;
&lt;p&gt;出现原因在于：git仓库中已经有一部分代码，所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式：
1，强推，即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f
2，先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于
$ git pull&lt;/p&gt;

&lt;h3 id=&quot;git撤销修改&quot;&gt;Git撤销修改&lt;/h3&gt;
&lt;p&gt;(1) git checkout
恢复某个已修改的文件（撤销未提交的修改）：
$ git checkout file-name
例如：git checkout src/com/android/…/xxx.java
比如修改的都是java文件，不必一个个撤销，可以使用
$ git checkout *.java
撤销所有修改
$ git checkout .&lt;/p&gt;

&lt;p&gt;(2) git revert
撤销某次操作，此次操作之前和之后的commit和history都会保留，并且把这次撤销
作为一次最新的提交
    * git revert HEAD                  撤销前一次 commit
    * git revert HEAD^               撤销前前一次 commit
    * git revert commit-id （比如：fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff）撤销指定的版本，撤销也会作为一次提交进行保存。
git revert是提交一个新的版本，将需要revert的版本的内容再反向修改回去，版本会递增，不影响之前提交的内容&lt;/p&gt;

&lt;h3 id=&quot;git-返回以前某个状态代码&quot;&gt;Git 返回以前某个状态代码&lt;/h3&gt;
&lt;p&gt;第一种返回方法
$git log
commit 5ff8ee………..75044
Author:yangyk3 &lt;a href=&quot;mailto:yangyk3@zuk.com&quot;&gt;yangyk3@zuk.com&lt;/a&gt;
Date:        Wed Aug…..
         commit 信息
         Change-Id: I6758345234…..e65501
commit 5328ee………..75044
Author:yangyk3 &lt;a href=&quot;mailto:yangyk3@zuk.com&quot;&gt;yangyk3@zuk.com&lt;/a&gt;
Date:        Wed Aug…..
         commit 信息
         Change-Id: I6758345234…..e65501
$git reset 5328ee………..75044&lt;/p&gt;
&lt;h3 id=&quot;第二种返回方法&quot;&gt;第二种返回方法&lt;/h3&gt;
&lt;p&gt;$git reflog
5428ee5 HEAD@{0}:commit
842ffe5 HEAD@{1}:commit
$git reset 842ffe5   //{0}:commit 的但没有 push 的，不会丢掉。&lt;/p&gt;

&lt;h3 id=&quot;git查看某个文件的修改历史&quot;&gt;git查看某个文件的修改历史&lt;/h3&gt;
&lt;p&gt;git log -p filename
如：某次提交
commit 432dfasd786a5s86fs6d8a5fas6asf5
Author：xxxx@xxxxx
Date： Thu May
使用git log -p a.java
会显示某次的哈希值
git show 哈希值 文件名
git show 432dfasd786a5s86fs6d8a5fas6asf5  a.java&lt;/p&gt;

&lt;h3 id=&quot;git-撤销add&quot;&gt;git 撤销add&lt;/h3&gt;
&lt;p&gt;git reset .
撤销 add 某个 fileA
git reset fileA&lt;/p&gt;

&lt;h3 id=&quot;git-撤销-comment&quot;&gt;git 撤销 Comment&lt;/h3&gt;
&lt;p&gt;git reset  commit_id  ( commit id 需要通过 git log  查看)&lt;/p&gt;

&lt;h3 id=&quot;git-回退&quot;&gt;git 回退&lt;/h3&gt;
&lt;p&gt;http://blog.csdn.net/yaoming168/article/details/38777763&lt;/p&gt;

&lt;h3 id=&quot;patch&quot;&gt;Patch&lt;/h3&gt;
&lt;p&gt;1 生成Patch
git diff &amp;gt; diff.patch
2 合入Patch
git apply diff.patch&lt;/p&gt;

&lt;h3 id=&quot;回滚某个文件&quot;&gt;回滚某个文件&lt;/h3&gt;
&lt;p&gt;首先查看该文件的历史版本信息：git log Default@2x.png
记录下需要恢复的commit版本号：如 9aa51d89799716aa68cff3f30c26f8815408e926
恢复该文件：git reset 9aa51d89799716aa68cff3f30c26f8815408e926 Default@2x.png
提交git:git commit -m “revert old file”&lt;/p&gt;

&lt;h3 id=&quot;git冲突commit-your-changes-or-stash-them-before-you-can-merge&quot;&gt;Git冲突：commit your changes or stash them before you can merge.&lt;/h3&gt;
&lt;p&gt;1.stash
通常遇到这个问题，你可以直接commit你的修改；但我这次不想这样。
看看git stash是如何做的。
git stash
git pull
git stash pop
接下来diff一下此文件看看自动合并的情况，并作出相应修改。
git stash: 备份当前的工作区的内容，从最近的一次提交中读取相关内容，让工作区保证和上次提交的内容一致。同时，将当前的工作区内容保存到Git栈中。
git stash pop: 从Git栈中读取最近一次保存的内容，恢复工作区的相关内容。由于可能存在多个Stash的内容，所以用栈来管理，pop会从最近的一个stash中读取内容并恢复。
git stash list: 显示Git栈内的所有备份，可以利用这个列表来决定从那个地方恢复。
git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现，原来stash的哪些节点都消失了。&lt;/p&gt;

&lt;p&gt;2.放弃本地修改，直接覆盖之
git reset –hard
git pull&lt;/p&gt;

&lt;p&gt;git revert 和 git reset的区别&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;git revert是用一次新的commit来回滚之前的commit，git reset是直接删除指定的commit。&lt;/li&gt;
  &lt;li&gt;在回滚这一操作上看，效果差不多。但是在日后继续merge以前的老版本时有区别。因为git revert是用一次逆向的commit“中和”之前的提交，因此日后合并老的branch时，导致这部分改变不会再次出现，但是git reset是之间把某些commit在某个branch上删除，因而和老的branch再次merge时，这些被回滚的commit应该还会被引入。&lt;/li&gt;
  &lt;li&gt;git reset 是把HEAD向后移动了一下，而git revert是HEAD继续前进，只是新的commit的内容和要revert的内容正好相反，能够抵消要被revert的内容。
git reset
git reset –hard e377f60e28c8b84158
-f 强制推送，否则出错
git push -f origin master&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;repo&quot;&gt;Repo&lt;/h2&gt;

&lt;h3 id=&quot;同步代码出现错误&quot;&gt;同步代码出现错误&lt;/h3&gt;
&lt;p&gt;提示需要checkout，但是checkout 后又不管用，那就删掉这个目录后，在用repo sync同步代码&lt;/p&gt;

&lt;h3 id=&quot;error-prior-sync-frameworkbase-failed-rebase-still-in-progress&quot;&gt;error: prior sync framework/base failed; rebase still in progress&lt;/h3&gt;
&lt;p&gt;framework/base 目录下 .git/ 目录删除后重新 sync&lt;/p&gt;

&lt;h3 id=&quot;repo-sync-某个目录&quot;&gt;repo sync 某个目录&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;打开.repo/manifiest.xml文件（这是隐藏文件夹，可用Ctrl+h显示），找到所要下载的project，使用path或者name字段的值都可以，直接跟在repo sync后作为参数即可。&lt;/li&gt;
  &lt;li&gt;在要修改的文件的目录，找到最早祖先目录， repo sync 这个祖先目录&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;git与repo&quot;&gt;Git与Repo&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://www.cnblogs.com/angeldevil/archive/2013/11/26/3238470.html&quot;&gt;http://www.cnblogs.com/angeldevil/archive/2013/11/26/3238470.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.csdn.net/gjswxhb/article/details/23221197&quot;&gt;http://blog.csdn.net/gjswxhb/article/details/23221197&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://blog.csdn.net/huwei2003/article/details/40707139&quot;&gt;http://blog.csdn.net/huwei2003/article/details/40707139&lt;/a&gt;&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/post/2017/06/17/3-git_command</link>
                <guid>http://yangyankai.github.io/post/2017/06/17/3-git_command</guid>
                <pubDate>Sat, 17 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Linux practical command</title>
                <description>
&lt;p&gt;bash 只是众多linux shell的一种。
bash shell是sh shell的增强版本。目前linux大部分使用的都是bash shell.&lt;/p&gt;

&lt;h3 id=&quot;查看隐藏文件&quot;&gt;查看隐藏文件&lt;/h3&gt;
&lt;p&gt;ls -a&lt;/p&gt;

&lt;h3 id=&quot;重命名&quot;&gt;重命名&lt;/h3&gt;
&lt;p&gt;①将一个名为abc.txt的文件重命名为1234.txt
mv abc.txt 1234.txt
②将目录A重命名为B
mv A B
③将a.txt移动到/b下，并重命名为c.txt
mv a.txt /b/c.txt&lt;/p&gt;

&lt;p&gt;例子：将/a目录移动到/b下，并重命名为c&lt;/p&gt;

&lt;p&gt;mv /a /b/c&lt;/p&gt;

&lt;p&gt;其实在文本模式中要重命名文件或目录的话也是很简单的，我们只需要使用mv命令就可以了，比如说我们要将一个名为abc的文件重命名为1234就可以这样来写：mv abc 1234，但是要注意的是，如果当前目录下也有个1234的文件的话，我们的这个文件是会将它覆盖的&lt;/p&gt;

&lt;h3 id=&quot;查看一个文件-filea-大小&quot;&gt;查看一个文件 fileA 大小&lt;/h3&gt;
&lt;p&gt;ls -l fileA    // 字节为单位 
或者  ls -lh fileA  //M为单位,K&lt;/p&gt;

&lt;h3 id=&quot;linux-文件操作&quot;&gt;linux 文件操作&lt;/h3&gt;
&lt;p&gt;http://www.cnblogs.com/zf2011/archive/2011/05/17/2049155.html&lt;/p&gt;

&lt;h3 id=&quot;linux下复制粘贴快捷键&quot;&gt;Linux下复制粘贴快捷键&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;在终端下：&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  复制命令：Ctrl + Shift + C  组合键.

  粘贴命令：Ctrl + Shift + V  组合键.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;在控制台下：&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  复制命令：Ctrl + Insert  组合键　　或　　用鼠标选中即是复制。

  粘贴命令：Shift + Insert  组合键　　或　　单击鼠标滚轮即为粘贴。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;补充 — Ubuntu终端 快捷键&lt;/p&gt;

&lt;p&gt;快捷键 功能
Tab 自动补全
Ctrl+a 光标移动到开始位置
Ctrl+e 光标移动到最末尾
Ctrl+k 删除此处至末尾的所有内容
Ctrl+u 删除此处至开始的所有内容
Ctrl+d 删除当前字符
Ctrl+h 删除当前字符前一个字符
Ctrl+w 删除此处到左边的单词
Ctrl+y 粘贴由 Ctrl+u ， Ctrl+d ， Ctrl+w 删除的单词
Ctrl+l 相当于clear，即清屏
Ctrl+r 查找历史命令
Ctrl+b 向回移动光标
Ctrl+f 向前移动光标
Ctrl+t 将光标位置的字符和前一个字符进行位置交换
Ctrl+&amp;amp; 恢复 ctrl+h 或者 ctrl+d 或者 ctrl+w 删除的内容
Ctrl+S 暂停屏幕输出
Ctrl+Q 继续屏幕输出
Ctrl+Left-Arrow 光标移动到上一个单词的词首
Ctrl+Right-Arrow 光标移动到下一个单词的词尾
Ctrl+p 向上显示缓存命令
Ctrl+n 向下显示缓存命令
Ctrl+d 关闭终端
Ctrl+xx 在EOL和当前光标位置移动
Ctrl+x@ 显示可能hostname补全
Ctrl+c 终止进程/命令
Shift +上或下 终端上下滚动
Shift+PgUp/PgDn 终端上下翻页滚动
Ctrl+Shift+n 新终端
alt+F2 输入gnome-terminal打开终端
Shift+Ctrl+T 打开新的标签页
Shift+Ctrl+W 关闭标签页
Shift+Ctrl+C 复制
Shift+Ctrl+V 粘贴
Alt+数字 切换至对应的标签页
Shift+Ctrl+N 打开新的终端窗口
Shift+Ctrl+Q 管壁终端窗口
Shift+Ctrl+PgUp/PgDn 左移右移标签页
Ctrl+PgUp/PgDn 切换标签页
F1 打开帮助指南
F10 激活菜单栏
F11 全屏切换
Alt+F 打开 “文件” 菜单（file）
Alt+E 打开 “编辑” 菜单（edit）
Alt+V 打开 “查看” 菜单（view）
Alt+S 打开 “搜索” 菜单（search）
Alt+T 打开 “终端” 菜单（terminal）
Alt+H 打开 “帮助” 菜单（help）&lt;/p&gt;

&lt;h3 id=&quot;linux-查看文件&quot;&gt;Linux 查看文件&lt;/h3&gt;
&lt;p&gt;android 环境中linux内核查看文件 cat 文件1
创建一个文件（节点）  touch nodeA
往节点写数据   echo “Raspberry” &amp;gt; nodeA&lt;/p&gt;

&lt;h3 id=&quot;查看cpu个数核数逻辑cpu个数&quot;&gt;查看CPU个数、核数、逻辑CPU个数&lt;/h3&gt;
&lt;p&gt;总核数 = 物理CPU个数 X 每颗物理CPU的核数
 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数&lt;/p&gt;

&lt;h3 id=&quot;查看物理cpu个数&quot;&gt;查看物理CPU个数&lt;/h3&gt;
&lt;p&gt;cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l&lt;/p&gt;

&lt;h3 id=&quot;查看每个物理cpu中core的个数即核数&quot;&gt;查看每个物理CPU中core的个数(即核数)&lt;/h3&gt;
&lt;p&gt;cat /proc/cpuinfo| grep “cpu cores”| uniq&lt;/p&gt;

&lt;h3 id=&quot;查看逻辑cpu的个数&quot;&gt;查看逻辑CPU的个数&lt;/h3&gt;
&lt;p&gt;cat /proc/cpuinfo| grep “processor”| wc -l&lt;/p&gt;

&lt;h3 id=&quot;查看cpu信息型号&quot;&gt;查看CPU信息（型号）&lt;/h3&gt;
&lt;p&gt;cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c&lt;/p&gt;

&lt;h3 id=&quot;top-命令&quot;&gt;Top 命令&lt;/h3&gt;
&lt;p&gt;Linux
top -n 10&lt;/p&gt;

&lt;p&gt;Desktop 终端切到桌面目录
cd  /home/username1/Desktop&lt;/p&gt;

&lt;h3 id=&quot;linux下文件的复制移动与删除命令为cpmvrm&quot;&gt;linux下文件的复制、移动与删除命令为：cp，mv，rm&lt;/h3&gt;
&lt;p&gt;一、文件复制命令cp
    命令格式：cp [-adfilprsu] 源文件(source) 目标文件(destination)
              cp [option] source1 source2 source3 …  directory
    参数说明：
    -a:是指archive的意思，也说是指复制所有的目录
    -d:若源文件为连接文件(link file)，则复制连接文件属性而非文件本身
    -f:强制(force)，若有重复或其它疑问时，不会询问用户，而强制复制
    -i:若目标文件(destination)已存在，在覆盖时会先询问是否真的操作
    -l:建立硬连接(hard link)的连接文件，而非复制文件本身
    -p:与文件的属性一起复制，而非使用默认属性
    -r:递归复制，用于目录的复制操作
    -s:复制成符号连接文件(symbolic link)，即“快捷方式”文件
    -u:若目标文件比源文件旧，更新目标文件
    如将/test1目录下的file1复制到/test3目录，并将文件名改为file2,可输入以下命令：
    cp /test1/file1 /test3/file2
二、文件移动命令mv
    命令格式：mv [-fiv] source destination
    参数说明：
    -f:force，强制直接移动而不询问
    -i:若目标文件(destination)已经存在，就会询问是否覆盖
    -u:若目标文件已经存在，且源文件比较新，才会更新
    如将/test1目录下的file1复制到/test3 目录，并将文件名改为file2,可输入以下命令：
    mv /test1/file1 /test3/file2
三、文件删除命令rm
    命令格式：rm [fir] 文件或目录
    参数说明：
    -f:强制删除
    -i:交互模式，在删除前询问用户是否操作
    -r:递归删除，常用在目录的删除
    如删除/test目录下的file1文件，可以输入以下命令：
    rm -i /test/file1&lt;/p&gt;

&lt;p&gt;在Linux下拷贝的时候有时候会出现cp:omitting directory的错误 ，例如 cp:omitting directory “bbs” 说明bbs目录下面还有目录，不能直接拷贝
解决办法：递归拷贝  命令：cp -r bbs ../backup/bbs    解释:-r 这个options是递归的意思
————————————————————&lt;/p&gt;

&lt;h3 id=&quot;打开编辑器&quot;&gt;打开编辑器&lt;/h3&gt;
&lt;p&gt;gedit&lt;/p&gt;

&lt;h3 id=&quot;默认新建一个空白&quot;&gt;默认新建一个空白&lt;/h3&gt;
&lt;p&gt;gedit file1&lt;/p&gt;

&lt;h3 id=&quot;使用编辑器gedit打开file1&quot;&gt;使用编辑器gedit打开file1.&lt;/h3&gt;
&lt;p&gt;要想不停止这个软件继续使用命令行的话，就要方向键“下”&lt;/p&gt;

&lt;h3 id=&quot;以窗口形式打开某个文件夹&quot;&gt;以窗口形式打开某个文件夹&lt;/h3&gt;
&lt;p&gt;nautilus /media/&lt;/p&gt;

&lt;h3 id=&quot;对linux不怎么熟悉以前在linux中敲命令的时候要移动光标傻傻的一个一个的移动感觉特不爽有几个常用的快捷键&quot;&gt;对linux不怎么熟悉,以前在linux中敲命令的时候，要移动光标，傻傻的一个一个的移动，感觉特不爽。有几个常用的快捷键。&lt;/h3&gt;
&lt;p&gt;ctrl+左右键:在单词之间跳转
ctrl+a:跳到本行的行首
ctrl+e:跳到页尾
Ctrl+u：删除当前光标前面的文字
ctrl+k：删除当前光标后面的文字
Ctrl+L：进行清屏操作
Ctrl+y:进行恢复删除做
Ctrl+w:删除光标前面的单词的字符
Alt – d ：由光标位置开始，往右删除单词。往行尾删&lt;/p&gt;

&lt;h3 id=&quot;解压&quot;&gt;解压&lt;/h3&gt;
&lt;p&gt;解压tar.xz文件：先 xz -d xxx.tar.xz 将 xxx.tar.xz解压成 xxx.tar 然后，再用 tar xvf xxx.tar来解包。&lt;/p&gt;

&lt;h3 id=&quot;查找文件&quot;&gt;查找文件&lt;/h3&gt;
&lt;p&gt;jgrep
sgrep
find ./ -name “*.xml” | xargs grep “item” ————————————————————color&lt;/p&gt;

&lt;h3 id=&quot;当前所有目录下查找&quot;&gt;当前所有目录下查找&lt;/h3&gt;
&lt;p&gt;find ./  | xargs grep “item” ————————————————————color
【查找的不能以空格隔开，如需要隔开则必须加双引号括起来】&lt;/p&gt;

&lt;h3 id=&quot;查找目录&quot;&gt;查找目录&lt;/h3&gt;
&lt;p&gt;比如想查找/etc/ 下的目录为AAA的
find /etc -name AAA -type d&lt;/p&gt;

&lt;h3 id=&quot;查看目录结构&quot;&gt;查看目录结构&lt;/h3&gt;
&lt;p&gt;tree . |  tee tmp.log&lt;/p&gt;

&lt;h3 id=&quot;参考博客1&quot;&gt;参考博客1：&lt;/h3&gt;
&lt;p&gt;http://blog.csdn.net/ljianhui/article/details/11100625&lt;/p&gt;
&lt;h3 id=&quot;参考博客2&quot;&gt;参考博客2：&lt;/h3&gt;
&lt;p&gt;http://www.cnblogs.com/laov/p/3541414.html#chmod&lt;/p&gt;

&lt;h3 id=&quot;创建--new_file_name--文件夹&quot;&gt;创建  NEW_FILE_NAME  文件夹&lt;/h3&gt;
&lt;p&gt;mkdir NEW_FILE_NAME&lt;/p&gt;

&lt;h3 id=&quot;切换到a_file目录&quot;&gt;切换到A_FILE目录&lt;/h3&gt;
&lt;p&gt;cd A_FILE&lt;/p&gt;

&lt;h3 id=&quot;查看当前子目录子文件&quot;&gt;查看当前子目录、子文件&lt;/h3&gt;
&lt;p&gt;ls&lt;/p&gt;

&lt;h3 id=&quot;删除目录&quot;&gt;删除目录&lt;/h3&gt;
&lt;p&gt;rm  file #删除文件file
rm -rf  a_directory   #删除文件a_directory目录&lt;/p&gt;

&lt;h3 id=&quot;删除当前目录下所有文件及文件夹&quot;&gt;删除当前目录下所有文件及文件夹&lt;/h3&gt;
&lt;p&gt;rm -r *&lt;/p&gt;

&lt;h3 id=&quot;清屏相关&quot;&gt;清屏相关&lt;/h3&gt;
&lt;p&gt;（1）clear
这个命令将会刷新屏幕，本质上只是让终端显示页向后翻了一页，如果向上滚动屏幕还可以看到之前的操作信息。一般都会用这个命令。
（2）reset
这个命令将完全刷新终端屏幕，之前的终端输入操作信息将都会被清空，这样虽然比较清爽，但整个命令过程速度有点慢，使用较少。
（3）另外介绍一个用别名来使用清屏命令的方法，如下：
[root@localhost ~]$ alias cls=‘clear’
[root@localhost ~]$ cls&lt;/p&gt;

&lt;h3 id=&quot;返回上一级&quot;&gt;返回上一级&lt;/h3&gt;
&lt;p&gt;cd ..
返回三级
cd ../../../&lt;/p&gt;

&lt;h3 id=&quot;返回根目录&quot;&gt;返回根目录&lt;/h3&gt;
&lt;p&gt;最上面一栏菜单栏有 “go”  菜单。点击选择 open parent，一直返回，知道根目录。&lt;/p&gt;

&lt;h3 id=&quot;查看硬盘空间&quot;&gt;查看硬盘空间&lt;/h3&gt;
&lt;p&gt;df -hl&lt;/p&gt;

&lt;h3 id=&quot;linux-命令行窗口添加多个tab页面&quot;&gt;Linux 命令行窗口添加多个Tab页面&lt;/h3&gt;
&lt;p&gt;Ctrl + Shift + T
Linux 命令行窗口中复制/粘贴
Ctrl+Shift+C / Ctrl+Shift+V&lt;/p&gt;

&lt;h3 id=&quot;移动-atxt&quot;&gt;移动 a.txt&lt;/h3&gt;
&lt;p&gt;mv a.txt temp/a.txt   //把当前目录的a.txt文件移动到 temp目录下&lt;/p&gt;

&lt;h3 id=&quot;linux杀死某个用户所用进程&quot;&gt;Linux杀死某个用户所用进程&lt;/h3&gt;
&lt;p&gt;在一台100多人使用的 SUN 服务器上经常发现有人滥用资源，平时用用就算了，到了交作业的时候100多号人同时登录使用，服务器明显迟缓，特别是实验室用的是瘦客户机，没硬盘，SUN 客户端需要从服务器装载系统镜像，而且编译、运行程序都要在服务器上完成。如果发现某个用户运行很多进程，并且进程还有子进程，怎么能方便的找出全部进程并 kill 掉呢？
ps -ef | grep ^username | cut -c 10-15 | xargs kill -9
把全部进程打印出来根据用户名过滤后找出全部进程号，然后逐行 kill 掉。xargs 就是用来把 cut 后的输出逐个以空白符分割后输给 kill。注意上面的 grep ^username 不能缺 ^，^username 表示从一行开始匹配 username，比如就可以避免匹配到 sshd: username@pts/0。不过尽管加了 ^，上面的代码仍然有个小 bug，如果恰好有个进程名和用户名完全一样怎么办？可以用 ps -u 找出所有与 username 相关的进程，然后 grep -v 过滤掉 PID 只剩下进程信息，然后逐行 kill 掉，如下：
ps -u username | grep -v PID | cut -c 0-5 | xargs kill -9
不过上面的命令还有个小问题就是如果 cut 的时候不小心 cut 多了或者 cut 少了怎么办？可以用 awk 过滤一列信息出来：&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ps -u username&lt;/td&gt;
      &lt;td&gt;grep -v PID&lt;/td&gt;
      &lt;td&gt;awk ‘{print$1}’&lt;/td&gt;
      &lt;td&gt;xargs kill -9&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;上面的命令也可以在 Linux 上运行，不过在 Linux 下可以用更简单的 killall，Solaris 上没有 killall：&lt;/p&gt;

&lt;p&gt;killall -u username&lt;/p&gt;

&lt;h3 id=&quot;只显示文件前几行&quot;&gt;只显示文件前几行：&lt;/h3&gt;
&lt;p&gt;sed -n 4,8p file #打印file中的4-8行
sed -n 4p file #打印file中的第4行
当git branch -a 太多的时候，这时候用 git branch -a sed -n 1,8p 就可以显示1-8行的结果&lt;/p&gt;

&lt;h3 id=&quot;查找杀进程&quot;&gt;查找杀进程&lt;/h3&gt;

&lt;p&gt;常规篇：&lt;/p&gt;

&lt;p&gt;　首先，用ps查看进程，方法如下：&lt;/p&gt;

&lt;p&gt;$ ps -ef&lt;/p&gt;

&lt;p&gt;……
smx       1822     1  0 11:38 ?        00:00:49 gnome-terminal
smx       1823  1822  0 11:38 ?        00:00:00 gnome-pty-helper
smx       1824  1822  0 11:38 pts/0    00:00:02 bash
smx       1827     1  4 11:38 ?        00:26:28 /usr/lib/firefox-3.6.18/firefox-bin
smx       1857  1822  0 11:38 pts/1    00:00:00 bash
smx       1880  1619  0 11:38 ?        00:00:00 update-notifier
……
smx      11946  1824  0 21:41 pts/0    00:00:00 ps -ef&lt;/p&gt;

&lt;p&gt;或者：&lt;/p&gt;

&lt;p&gt;$ ps -aux&lt;/p&gt;

&lt;p&gt;……&lt;/p&gt;

&lt;p&gt;smx       1822  0.1  0.8  58484 18152 ?        Sl   11:38   0:49 gnome-terminal
smx       1823  0.0  0.0   1988   712 ?        S    11:38   0:00 gnome-pty-helper
smx       1824  0.0  0.1   6820  3776 pts/0    Ss   11:38   0:02 bash
smx       1827  4.3  5.8 398196 119568 ?       Sl   11:38  26:13 /usr/lib/firefox-3.6.18/firefox-bin
smx       1857  0.0  0.1   6688  3644 pts/1    Ss   11:38   0:00 bash
smx       1880  0.0  0.6  41536 12620 ?        S    11:38   0:00 update-notifier
……
smx      11953  0.0  0.0   2716  1064 pts/0    R+   21:42   0:00 ps -aux&lt;/p&gt;

&lt;p&gt;此时如果我想杀了火狐的进程就在终端输入：&lt;/p&gt;

&lt;p&gt;$ kill -s 9 1827&lt;/p&gt;

&lt;p&gt;其中-s 9 制定了传递给进程的信号是９，即强制、尽快终止进程。各个终止信号及其作用见附录。&lt;/p&gt;

&lt;p&gt;1827则是上面ps查到的火狐的PID。&lt;/p&gt;

&lt;p&gt;简单吧，但有个问题，进程少了则无所谓，进程多了，就会觉得痛苦了，无论是ps -ef 还是ps -aux，每次都要在一大串进程信息里面查找到要杀的进程，看的眼都花了。&lt;/p&gt;

&lt;p&gt;进阶篇：&lt;/p&gt;

&lt;p&gt;改进１：&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;把ps的查询结果通过管道给grep查找包含特定字符串的进程。管道符“&lt;/td&gt;
      &lt;td&gt;”用来隔开两个命令，管道符左边命令的输出会作为管道符右边命令的输入。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;$ ps -ef | grep firefox
smx       1827     1  4 11:38 ?        00:27:33 /usr/lib/firefox-3.6.18/firefox-bin
smx      12029  1824  0 21:54 pts/0    00:00:00 grep ————————————————————color=auto firefox&lt;/p&gt;

&lt;p&gt;这次就清爽了。然后就是&lt;/p&gt;

&lt;p&gt;$kill -s 9 1827&lt;/p&gt;

&lt;p&gt;还是嫌打字多？&lt;/p&gt;

&lt;p&gt;改进２——使用pgrep：&lt;/p&gt;

&lt;p&gt;一看到pgrep首先会想到什么？没错，grep！pgrep的p表明了这个命令是专门用于进程查询的grep。&lt;/p&gt;

&lt;p&gt;$ pgrep firefox
1827&lt;/p&gt;

&lt;p&gt;看到了什么？没错火狐的PID，接下来又要打字了：&lt;/p&gt;

&lt;p&gt;$kill -s 9 1827&lt;/p&gt;

&lt;p&gt;改进３——使用pidof：&lt;/p&gt;

&lt;p&gt;看到pidof想到啥？没错pid of xx，字面翻译过来就是 xx的PID。&lt;/p&gt;

&lt;p&gt;$ pidof firefox-bin
1827
和pgrep相比稍显不足的是，pidof必须给出进程的全名。然后就是老生常谈：&lt;/p&gt;

&lt;p&gt;$kill -s 9 1827&lt;/p&gt;

&lt;p&gt;无论使用ps 然后慢慢查找进程PID 还是用grep查找包含相应字符串的进程，亦或者用pgrep直接查找包含相应字符串的进程ＰＩＤ，然后手动输入给ｋｉｌｌ杀掉，都稍显麻烦。有没有更方便的方法？有！&lt;/p&gt;

&lt;p&gt;改进４：&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;$ps -ef&lt;/td&gt;
      &lt;td&gt;grep firefox&lt;/td&gt;
      &lt;td&gt;grep -v grep&lt;/td&gt;
      &lt;td&gt;cut -c 9-15&lt;/td&gt;
      &lt;td&gt;xargs kill -s 9&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;说明：&lt;/p&gt;

&lt;p&gt;“grep firefox”的输出结果是，所有含有关键字“firefox”的进程。&lt;/p&gt;

&lt;p&gt;“grep -v grep”是在列出的进程中去除含有关键字“grep”的进程。&lt;/p&gt;

&lt;p&gt;“cut -c 9-15”是截取输入行的第9个字符到第15个字符，而这正好是进程号PID。&lt;/p&gt;

&lt;p&gt;“xargs kill -s 9”中的xargs命令是用来把前面命令的输出结果（PID）作为“kill -s 9”命令的参数，并执行该命令。“kill -s 9”会强行杀掉指定进程。&lt;/p&gt;

&lt;p&gt;难道你不想抱怨点什么？没错太长了&lt;/p&gt;

&lt;p&gt;改进５：&lt;/p&gt;

&lt;p&gt;知道pgrep和pidof两个命令，干嘛还要打那么长一串！&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;$ pgrep firefox&lt;/td&gt;
      &lt;td&gt;xargs kill -s 9&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;改进６：&lt;/p&gt;

&lt;p&gt;$ ps -ef | grep firefox | awk ‘{print $2}’ | xargs kill -9
kill: No such process&lt;/p&gt;

&lt;p&gt;有一个比较郁闷的地方，进程已经正确找到并且终止了，但是执行完却提示找不到进程。&lt;/p&gt;

&lt;p&gt;其中awk ‘{print $2}’ 的作用就是打印（print）出第二列的内容。根据常规篇，可以知道ps输出的第二列正好是PID。就把进程相应的PID通过xargs传递给kill作参数，杀掉对应的进程。&lt;/p&gt;

&lt;p&gt;改进７：&lt;/p&gt;

&lt;p&gt;难道每次都要调用xargs把PID传递给kill？答案是否定的：&lt;/p&gt;

&lt;p&gt;$kill -s 9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ps -aux | grep firefox | awk ‘{print $2}’&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;改进８：&lt;/p&gt;

&lt;p&gt;没错，命令依然有点长，换成pgrep。&lt;/p&gt;

&lt;p&gt;$kill -s 9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pgrep firefox&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;改进9——pkill：&lt;/p&gt;

&lt;p&gt;看到pkill想到了什么？没错pgrep和kill！pkill＝pgrep+kill。&lt;/p&gt;

&lt;p&gt;$pkill -９ firefox&lt;/p&gt;

&lt;p&gt;说明：”-9” 即发送的信号是9，pkill与kill在这点的差别是：pkill无须 “ｓ”，终止信号等级直接跟在 “-“ 后面。之前我一直以为是 “-s 9”，结果每次运行都无法终止进程。&lt;/p&gt;

&lt;p&gt;改进10——killall：&lt;/p&gt;

&lt;p&gt;killall和pkill是相似的,不过如果给出的进程名不完整，killall会报错。pkill或者pgrep只要给出进程名的一部分就可以终止进程。&lt;/p&gt;

&lt;p&gt;$killall -9 firefox&lt;/p&gt;

</description>
                <link>http://yangyankai.github.io/2017/06/17/2-linux_bash</link>
                <guid>http://yangyankai.github.io/2017/06/17/2-linux_bash</guid>
                <pubDate>Sat, 17 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>A Method to Secure Cloud Storage</title>
                <description>&lt;h2&gt;A Method to Secure Cloud Storage&lt;/h2&gt;

&lt;p&gt;A Data Partitioning and Scrambling Method to Secure Cloud Storage with Healthcare Applications &lt;/p&gt;

&lt;a href=&quot;https://yangyankai.github.io/assets/images/icc2015_article.pdf&quot;&gt;原文链接,更新&lt;/a&gt;

&lt;script type=&quot;text/javascript&quot;&gt;document.write(unescape(&quot;%3Cspan id='cnzz_stat_icon_1280762813'%3E%3C/span%3E%3Cscript src='https://s4.cnzz.com/z_stat.php%3Fid%3D1280762813%26online%3D1' type='text/javascript'%3E%3C/script%3E&quot;));&lt;/script&gt;

&lt;p&gt;04 Jun 2017&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/2017/06/04/1-secure_cloud_storage</link>
                <guid>http://yangyankai.github.io/2017/06/04/1-secure_cloud_storage</guid>
                <pubDate>Sun, 04 Jun 2017 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Jekyll Introduction</title>
                <description>
&lt;p&gt;This Jekyll introduction will outline specifically  what Jekyll is and why you would want to use it.
Directly following the intro we’ll learn exactly &lt;em&gt;how&lt;/em&gt; Jekyll does what it does.&lt;/p&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;h3 id=&quot;what-is-jekyll&quot;&gt;What is Jekyll?&lt;/h3&gt;

&lt;p&gt;Jekyll is a parsing engine bundled as a ruby gem used to build static websites from
dynamic components such as templates, partials, liquid code, markdown, etc. Jekyll is known as “a simple, blog aware, static site generator”.&lt;/p&gt;

&lt;h3 id=&quot;examples&quot;&gt;Examples&lt;/h3&gt;

&lt;p&gt;This website is created with Jekyll. &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Sites&quot;&gt;Other Jekyll websites&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;what-does-jekyll-do&quot;&gt;What does Jekyll Do?&lt;/h3&gt;

&lt;p&gt;Jekyll is a ruby gem you install on your local system.
Once there you can call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jekyll --server&lt;/code&gt; on a directory and provided that directory
is setup in a way jekyll expects, it will do magic stuff like parse markdown/textile files,
compute categories, tags, permalinks, and construct your pages from layout templates and partials.&lt;/p&gt;

&lt;p&gt;Once parsed, Jekyll stores the result in a self-contained static &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_site&lt;/code&gt; folder.
The intention here is that you can serve all contents in this folder statically from a plain static web-server.&lt;/p&gt;

&lt;p&gt;You can think of Jekyll as a normalish dynamic blog but rather than parsing content, templates, and tags
on each request, Jekyll does this once &lt;em&gt;beforehand&lt;/em&gt; and caches the &lt;em&gt;entire website&lt;/em&gt; in a folder for serving statically.&lt;/p&gt;

&lt;h3 id=&quot;jekyll-is-not-blogging-software&quot;&gt;Jekyll is Not Blogging Software&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Jekyll is a parsing engine.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Jekyll does not come with any content nor does it have any templates or design elements.
This is a common source of confusion when getting started.
Jekyll does not come with anything you actually use or see on your website - you have to make it.&lt;/p&gt;

&lt;h3 id=&quot;why-should-i-care&quot;&gt;Why Should I Care?&lt;/h3&gt;

&lt;p&gt;Jekyll is very minimalistic and very efficient.
The most important thing to realize about Jekyll is that it creates a static representation of your website requiring only a static web-server.
Traditional dynamic blogs like Wordpress require a database and server-side code.
Heavily trafficked dynamic blogs must employ a caching layer that ultimately performs the same job Jekyll sets out to do; serve static content.&lt;/p&gt;

&lt;p&gt;Therefore if you like to keep things simple and you prefer the command-line over an admin panel UI then give Jekyll a try.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developers like Jekyll because we can write content like we write code:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ability to write content in markdown or textile in your favorite text-editor.&lt;/li&gt;
  &lt;li&gt;Ability to write and preview your content via localhost.&lt;/li&gt;
  &lt;li&gt;No internet connection required.&lt;/li&gt;
  &lt;li&gt;Ability to publish via git.&lt;/li&gt;
  &lt;li&gt;Ability to host your blog on a static web-server.&lt;/li&gt;
  &lt;li&gt;Ability to host freely on GitHub Pages.&lt;/li&gt;
  &lt;li&gt;No database required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;how-jekyll-works&quot;&gt;How Jekyll Works&lt;/h1&gt;

&lt;p&gt;The following is a complete but concise outline of exactly how Jekyll works.&lt;/p&gt;

&lt;p&gt;Be aware that core concepts are introduced in rapid succession without code examples.
This information is not intended to specifically teach you how to do anything, rather it
is intended to give you the &lt;em&gt;full picture&lt;/em&gt; relative to what is going on in Jekyll-world.&lt;/p&gt;

&lt;p&gt;Learning these core concepts should help you avoid common frustrations and ultimately
help you better understand the code examples contained throughout Jekyll-Bootstrap.&lt;/p&gt;

&lt;h2 id=&quot;initial-setup&quot;&gt;Initial Setup&lt;/h2&gt;

&lt;p&gt;After &lt;a href=&quot;/index.html#start-now&quot;&gt;installing jekyll&lt;/a&gt; you’ll need to format your website directory in a way jekyll expects.
Jekyll-bootstrap conveniently provides the base directory format.&lt;/p&gt;

&lt;h3 id=&quot;the-jekyll-application-base-format&quot;&gt;The Jekyll Application Base Format&lt;/h3&gt;

&lt;p&gt;Jekyll expects your website directory to be laid out like so:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.
|-- _config.yml
|-- _includes
|-- _layouts
|   |-- default.html
|   |-- post.html
|-- _posts
|   |-- 2011-10-25-open-source-is-good.markdown
|   |-- 2011-04-26-hello-world.markdown
|-- _site
|-- index.html
|-- assets
    |-- css
        |-- style.css
    |-- javascripts
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;_config.yml&lt;/strong&gt;
  Stores configuration data.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;_includes&lt;/strong&gt;
  This folder is for partial views.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;_layouts&lt;/strong&gt;
  This folder is for the main templates your content will be inserted into.
  You can have different layouts for different pages or page sections.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;_posts&lt;/strong&gt;
  This folder contains your dynamic content/posts.
  the naming format is required to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@YEAR-MONTH-DATE-title.MARKUP@&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;_site&lt;/strong&gt;
  This is where the generated site will be placed once Jekyll is done transforming it.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;assets&lt;/strong&gt;
  This folder is not part of the standard jekyll structure.
  The assets folder represents &lt;em&gt;any generic&lt;/em&gt; folder you happen to create in your root directory.
  Directories and files not properly formatted for jekyll will be left untouched for you to serve normally.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(read more: &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Usage&quot;&gt;https://github.com/mojombo/jekyll/wiki/Usage&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&quot;jekyll-configuration&quot;&gt;Jekyll Configuration&lt;/h3&gt;

&lt;p&gt;Jekyll supports various configuration options that are fully outlined here:
(&lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Configuration&quot;&gt;https://github.com/mojombo/jekyll/wiki/Configuration&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;content-in-jekyll&quot;&gt;Content in Jekyll&lt;/h2&gt;

&lt;p&gt;Content in Jekyll is either a post or a page.
These content “objects” get inserted into one or more templates to build the final output for its respective static-page.&lt;/p&gt;

&lt;h3 id=&quot;posts-and-pages&quot;&gt;Posts and Pages&lt;/h3&gt;

&lt;p&gt;Both posts and pages should be written in markdown, textile, or HTML and may also contain Liquid templating syntax.
Both posts and pages can have meta-data assigned on a per-page basis such as title, url path, as well as arbitrary custom meta-data.&lt;/p&gt;

&lt;h3 id=&quot;working-with-posts&quot;&gt;Working With Posts&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Creating a Post&lt;/strong&gt;
Posts are created by properly formatting a file and placing it the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formatting&lt;/strong&gt;
A post must have a valid filename in the form &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YEAR-MONTH-DATE-title.MARKUP&lt;/code&gt; and be placed in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_posts&lt;/code&gt; directory.
If the data format is invalid Jekyll will not recognize the file as a post. The date and title are automatically parsed from the filename of the post file.
Additionally, each file must have &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter&quot;&gt;YAML Front-Matter&lt;/a&gt; prepended to its content.
YAML Front-Matter is a valid YAML syntax specifying meta-data for the given file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt;
Ordering is an important part of Jekyll but it is hard to specify a custom ordering strategy.
Only reverse chronological and chronological ordering is supported in Jekyll.&lt;/p&gt;

&lt;p&gt;Since the date is hard-coded into the filename format, to change the order, you must change the dates in the filenames.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tags&lt;/strong&gt;
Posts can have tags associated with them as part of their meta-data.
Tags may be placed on posts by providing them in the post’s YAML front matter.
You have access to the post-specific tags in the templates. These tags also get added to the sitewide collection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Categories&lt;/strong&gt;
Posts may be categorized by providing one or more categories in the YAML front matter.
Categories offer more significance over tags in that they can be reflected in the URL path to the given post.
Note categories in Jekyll work in a specific way.
If you define more than one category you are defining a category hierarchy “set”.
Example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;---
title :  Hello World
categories : [lessons, beginner]
---
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This defines the category hierarchy “lessons/beginner”. Note this is &lt;em&gt;one category&lt;/em&gt; node in Jekyll.
You won’t find “lessons” and “beginner” as two separate categories unless you define them elsewhere as singular categories.&lt;/p&gt;

&lt;h3 id=&quot;working-with-pages&quot;&gt;Working With Pages&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Creating a Page&lt;/strong&gt;
Pages are created by properly formatting a file and placing it anywhere in the root directory or subdirectories that do &lt;em&gt;not&lt;/em&gt; start with an underscore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formatting&lt;/strong&gt;
In order to register as a Jekyll page the file must contain &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter&quot;&gt;YAML Front-Matter&lt;/a&gt;.
Registering a page means 1) that Jekyll will process the page and 2) that the page object will be available in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site.pages&lt;/code&gt; array for inclusion into your templates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Categories and Tags&lt;/strong&gt;
Pages do not compute categories nor tags so defining them will have no effect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sub-Directories&lt;/strong&gt;
If pages are defined in sub-directories, the path to the page will be reflected in the url.
Example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.
|-- people
    |-- bob
        |-- essay.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This page will be available at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://yourdomain.com/people/bob/essay.html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommended Pages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;index.html&lt;/strong&gt;
You will always want to define the root index.html page as this will display on your root URL.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;404.html&lt;/strong&gt;
Create a root 404.html page and GitHub Pages will serve it as your 404 response.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;sitemap.html&lt;/strong&gt;
Generating a sitemap is good practice for SEO.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;about.html&lt;/strong&gt;
A nice about page is easy to do and gives the human perspective to your website.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;templates-in-jekyll&quot;&gt;Templates in Jekyll&lt;/h2&gt;

&lt;p&gt;Templates are used to contain a page’s or post’s content.
All templates have access to a global site object variable: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site&lt;/code&gt; as well as a page object variable: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;page&lt;/code&gt;.
The site variable holds all accessible content and metadata relative to the site.
The page variable holds accessible data for the given page or post being rendered at that point.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Template&lt;/strong&gt;
Templates are created by properly formatting a file and placing it in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_layouts&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Formatting&lt;/strong&gt;
Templates should be coded in HTML and contain YAML Front Matter.
All templates can contain Liquid code to work with your site’s data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rending Page/Post Content in a Template&lt;/strong&gt;
There is a special variable in all templates named : &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content&lt;/code&gt;.
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content&lt;/code&gt; variable holds the page/post content including any sub-template content previously defined.
Render the content variable wherever you want your main content to be injected into your template:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;...
&amp;lt;body&amp;gt;
  &amp;lt;div id=&quot;sidebar&quot;&amp;gt; ... &amp;lt;/div&amp;gt;
  &amp;lt;div id=&quot;main&quot;&amp;gt;
    &amp;#123;{content}&amp;#125;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
...&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;sub-templates&quot;&gt;Sub-Templates&lt;/h3&gt;

&lt;p&gt;Sub-templates are exactly templates with the only difference being they
define another “root” layout/template within their YAML Front Matter.
This essentially means a template will render inside of another template.&lt;/p&gt;

&lt;h3 id=&quot;includes&quot;&gt;Includes&lt;/h3&gt;
&lt;p&gt;In Jekyll you can define include files by placing them in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_includes&lt;/code&gt; folder.
Includes are NOT templates, rather they are just code snippets that get included into templates.
In this way, you can treat the code inside includes as if it was native to the parent template.&lt;/p&gt;

&lt;p&gt;Any valid template code may be used in includes.&lt;/p&gt;

&lt;h2 id=&quot;using-liquid-for-templating&quot;&gt;Using Liquid for Templating&lt;/h2&gt;

&lt;p&gt;Templating is perhaps the most confusing and frustrating part of Jekyll.
This is mainly due to the fact that Jekyll templates must use the Liquid Templating Language.&lt;/p&gt;

&lt;h3 id=&quot;what-is-liquid&quot;&gt;What is Liquid?&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/Shopify/liquid&quot;&gt;Liquid&lt;/a&gt; is a secure templating language developed by &lt;a href=&quot;http://shopify.com&quot;&gt;Shopify&lt;/a&gt;.
Liquid is designed for end-users to be able to execute logic within template files
without imposing any security risk on the hosting server.&lt;/p&gt;

&lt;p&gt;Jekyll uses Liquid to generate the post content within the final page layout structure and as the primary interface for working with
your site and post/page data.&lt;/p&gt;

&lt;h3 id=&quot;why-do-we-have-to-use-liquid&quot;&gt;Why Do We Have to Use Liquid?&lt;/h3&gt;

&lt;p&gt;GitHub uses Jekyll to power &lt;a href=&quot;http://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt;.
GitHub cannot afford to run arbitrary code on their servers so they lock developers down via Liquid.&lt;/p&gt;

&lt;h3 id=&quot;liquid-is-not-programmer-friendly&quot;&gt;Liquid is Not Programmer-Friendly.&lt;/h3&gt;

&lt;p&gt;The short story is liquid is not real code and its not intended to execute real code.
The point being you can’t do jackshit in liquid that hasn’t been allowed explicitly by the implementation.
What’s more you can only access data-structures that have been explicitly passed to the template.&lt;/p&gt;

&lt;p&gt;In Jekyll’s case it is not possible to alter what is passed to Liquid without hacking the gem or running custom plugins.
Both of which cannot be supported by GitHub Pages.&lt;/p&gt;

&lt;p&gt;As a programmer - this is very frustrating.&lt;/p&gt;

&lt;p&gt;But rather than look a gift horse in the mouth we are going to
suck it up and view it as an opportunity to work around limitations and adopt client-side solutions when possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Aside&lt;/strong&gt;
My personal stance is to not invest time trying to hack liquid. It’s really unnecessary
&lt;em&gt;from a programmer’s&lt;/em&gt; perspective. That is to say if you have the ability to run custom plugins (i.e. run arbitrary ruby code)
you are better off sticking with ruby. Toward that end I’ve built &lt;a href=&quot;http://github.com/plusjade/mustache-with-jekyll&quot;&gt;Mustache-with-Jekyll&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;static-assets&quot;&gt;Static Assets&lt;/h2&gt;

&lt;p&gt;Static assets are any file in the root or non-underscored subfolders that are not pages.
That is they have no valid YAML Front Matter and are thus not treated as Jekyll Pages.&lt;/p&gt;

&lt;p&gt;Static assets should be used for images, css, and javascript files.&lt;/p&gt;

&lt;h2 id=&quot;how-jekyll-parses-files&quot;&gt;How Jekyll Parses Files&lt;/h2&gt;

&lt;p&gt;Remember Jekyll is a processing engine. There are two main types of parsing in Jekyll.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Content parsing.&lt;/strong&gt;
  This is done with textile or markdown.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Template parsing.&lt;/strong&gt;
This is done with the liquid templating language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And thus there are two main types of file formats needed for this parsing.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Post and Page files.&lt;/strong&gt;
All content in Jekyll is either a post or a page so valid posts and pages are parsed with markdown or textile.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Template files.&lt;/strong&gt;
  These files go in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_layouts&lt;/code&gt; folder and contain your blogs &lt;strong&gt;templates&lt;/strong&gt;. They should be made in HTML with the help of Liquid syntax.
  Since include files are simply injected into templates they are essentially parsed as if they were native to the template.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Arbitrary files and folders.&lt;/strong&gt;
Files that &lt;em&gt;are not&lt;/em&gt; valid pages are treated as static content and pass through
Jekyll untouched and reside on your blog in the exact structure and format they originally existed in.&lt;/p&gt;

&lt;h3 id=&quot;formatting-files-for-parsing&quot;&gt;Formatting Files for Parsing.&lt;/h3&gt;

&lt;p&gt;We’ve outlined the need for valid formatting using &lt;strong&gt;YAML Front Matter&lt;/strong&gt;.
Templates, posts, and pages all need to provide valid YAML Front Matter even if the Matter is empty.
This is the only way Jekyll knows you want the file processed.&lt;/p&gt;

&lt;p&gt;YAML Front Matter must be prepended to the top of template/post/page files:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;---
layout: post
category : pages
tags : [how-to, jekyll]
---

... contents ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Three hyphens on a new line start the Front-Matter block and three hyphens on a new line end the block.
The data inside the block must be valid YAML.&lt;/p&gt;

&lt;p&gt;Configuration parameters for YAML Front-Matter is outlined here:
&lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter&quot;&gt;A comprehensive explanation of YAML Front Matter&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;defining-layouts-for-posts-and-templates-parsing&quot;&gt;Defining Layouts for Posts and Templates Parsing.&lt;/h4&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;layout&lt;/code&gt; parameter in the YAML Front Matter defines the template file for which the given post or template should be injected into.
If a template file specifies its own layout, it is effectively being used as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sub-template.&lt;/code&gt;
That is to say loading a post file into a template file that refers to another template file with work in the way you’d expect; as a nested sub-template.&lt;/p&gt;

&lt;h2 id=&quot;how-jekyll-generates-the-final-static-files&quot;&gt;How Jekyll Generates the Final Static Files.&lt;/h2&gt;

&lt;p&gt;Ultimately, Jekyll’s job is to generate a static representation of your website.
The following is an outline of how that’s done:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Jekyll collects data.&lt;/strong&gt;
  Jekyll scans the posts directory and collects all posts files as post objects. It then scans the layout assets and collects those and finally scans other directories in search of pages.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Jekyll computes data.&lt;/strong&gt;
  Jekyll takes these objects, computes metadata (permalinks, tags, categories, titles, dates) from them and constructs one
  big &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site&lt;/code&gt; object that holds all the posts, pages, layouts, and respective metadata.
  At this stage your site is one big computed ruby object.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Jekyll liquifies posts and templates.&lt;/strong&gt;
  Next jekyll loops through each post file and converts (through markdown or textile) and &lt;strong&gt;liquifies&lt;/strong&gt; the post inside of its respective layout(s).
  Once the post is parsed and liquified inside the the proper layout structure, the layout itself is “liquified”.
 &lt;strong&gt;Liquification&lt;/strong&gt; is defined as follows: Jekyll initiates a Liquid template, and passes a simpler hash representation of the ruby site object as well as a simpler
  hash representation of the ruby post object. These simplified data structures are what you have access to in the templates.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Jekyll generates output.&lt;/strong&gt;
 Finally the liquid templates are “rendered”, thereby processing any liquid syntax provided in the templates
 and saving the final, static representation of the file.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Notes.&lt;/strong&gt;
Because Jekyll computes the entire site in one fell swoop, each template is given access to
a global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;site&lt;/code&gt; hash that contains useful data. It is this data that you’ll iterate through and format
using the Liquid tags and filters in order to render it onto a given page.&lt;/p&gt;

&lt;p&gt;Remember, in Jekyll you are an end-user. Your API has only two components:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The manner in which you setup your directory.&lt;/li&gt;
  &lt;li&gt;The liquid syntax and variables passed into the liquid templates.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the data objects available to you in the templates via Liquid are outlined in the &lt;strong&gt;API Section&lt;/strong&gt; of Jekyll-Bootstrap.
You can also read the original documentation here: &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Template-Data&quot;&gt;https://github.com/mojombo/jekyll/wiki/Template-Data&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I hope this paints a clearer picture of what Jekyll is doing and why it works the way it does.
As noted, our main programming constraint is the fact that our API is limited to what is accessible via Liquid and Liquid only.&lt;/p&gt;

&lt;p&gt;Jekyll-bootstrap is intended to provide helper methods and strategies aimed at making it more intuitive and easier to work with Jekyll =)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank you&lt;/strong&gt; for reading this far.&lt;/p&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;

&lt;p&gt;Please take a look at &lt;a href=&quot;&quot;&gt;&lt;/a&gt;
or jump right into &lt;a href=&quot;&quot;&gt;Usage&lt;/a&gt; if you’d like.&lt;/p&gt;
</description>
                <link>http://yangyankai.github.io/lessons/2011/12/29/jekyll-introduction</link>
                <guid>http://yangyankai.github.io/lessons/2011/12/29/jekyll-introduction</guid>
                <pubDate>Thu, 29 Dec 2011 00:00:00 +0000</pubDate>
        </item>


</channel>
</rss>
