linux 常用命令

总结了一下android开发中常用的Linux命令

  • man

man的含义manual,手册,不清楚某个命令的作用和用法时,可以使用 man command 查询。比如: man ls

  • find

find 用于查找文件、文件夹,比如:

$ find . -name “*.java”

查找当前目录下扩展名为.java 的文件 ,.代表当前目录,*为通配符

  • grep

grep命令为正则表达式匹配命令,用于字符串匹配。比如想查找MainActivity.java文件中包含“Activity”的地方,可以使用如下命令

$ grep "Activity" MainActivity.java 
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

grep和find的区别在于,find用于查找目录或者文件,而grep用于查找指定的字符串,并且字符串可以由正则表达式描述。

  • xargs

xargs 并不是一个命令,是一个标示,代表上一个命令的执行结果,并作为下一个命令的参数。两个命令用|分开。比如想找到当前目录下文件名包含“Activity”的文件,可以使用以下命令:

$ls | grep "Activity"
MainActivity.java

再如,想查找当前目录下所有包含“Activity”字符串的java文件,命令如下

$find . -name "*.java" | xargs grep "Activity"
./MainActivity.java:import android.support.v7.app.AppCompatActivity;
./MainActivity.java:public class MainActivity extends AppCompatActivity {

再如,查找当前目录下,名为res的目录下的所有的xml文件中有字符串“layout_width”的地方,命令如下:

$find `find . -name res` -name "*.xml" | xargs grep layout_width
./main/res/layout/activity_main.xml:    android:layout_width="match_parent"
./main/res/layout/activity_main.xml:        android:layout_width="wrap_content"
./main/res/layout/activity_main.xml:        android:layout_width="wrap_content"

注:` 不是单引号。

  • cat
     The command:
          cat file1

           will print the contents of file1 to the standard output.
    The command:
      cat file1 file2 > file3

       will sequentially print the contents of file1 and file2 to the file file3, truncating file3 if it already exists.  See the manual page for your shell (i.e., sh(1)) for more
     information on redirection.
   The command:
           cat file1 - file2 - file3

     will print the contents of file1, print data it receives from the standard input until it receives an EOF (`^D') character, print the contents of file2, read and output contents
     of the standard input again, then finally output the contents of file3.  Note that if the standard input referred to a file, the second dash on the command-line would have no
     effect, since the entire contents of the file would have already been read and printed by cat when it encountered the first `-' operand.
  • chmod

Linux中,文件等访问者被分为三类,并针对这三类不同的用户指定了不同的访问权限,三类访问者分别是:

    • user 用户自身,即创建该文件的用户
    • group 用户所在的组
    • other 其他用户

chmod用于设置这三类访问者对某文件的的访问权限。访问权限分为读(r)、写(w)、执行(x)。

$chmod u+x test.sh

为test.sh添加user的执行权限。

但对于某些Linux系统,比如android的底层Linux,不识别r、w、x,这些参数,只能用8进制的数来表示。比如:

$chmod 777 test.sh

777为8进制的数,对应二进制数111 111 111,代表u、g、o三类用户的权限

  • ps , kill

ps用于列出当前所有进程,kill用于杀死某个进程

  • export

export用于将某个变量值的作用域设为全局范围。比如,可以将某个路径赋值给系统环境变量PATH,然后再export PATH,之后,其他程序都可以使用该路径。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值