Linux常用命令的操作

来源:互联网 发布:阿里巴巴农村淘宝加盟 编辑:程序博客网 时间:2024/06/07 05:53

今天总结一下Linux中常用命令(Ubuntu环境),包括查看文件类型,安装程序,解压缩,more\less,grep,head,tail等等。

1file name.c 查看name.c的文件类型

2dpkg -s 安装包名称     查看安装状态

   dpkg -l 安装包名称     查看安装包清单(倚赖)

3apt -update   刷新软件源列表

   apt -upgrade  升级所有软件包

4tar命令

tar -czf  hello.tar.gz   hello.c  hello1.c  hello.c hello1.c两个文件合并到hello.tar.gz文件中,并采用压缩方式

tar -tzf   hello.tar.gz  列出归档文件hello.tar所有文件列表

tar -xzvf  hello.tar.gz 将归档文件解压到源文件的路径中

tar -czvf hello.tar.gz hello.c hello.h 将hello.c hello.h压缩为hello.tar.gz

zf这两个选项是必须的,分别代表采取压缩方式和指定档案文件的名称

c创建

x分解

v显示过程信息

t查看档案文件的内容

5more命令   Crtl+F向下滚动一页   q退出    只能往后看文件

more  +3  file                 从第三行开始显示

more  +/day  file        file中找到第一个day,并从该行的前两行开始输出

more  -5        file             每页显示5

ls -l  | more -5                  和管道命令结合

6less命令  Crtl+f向下翻页    Crtl+b向上翻页  也可上下键,Pagedown  Pageup

less  file

ps -ef | less   查看进程,并通过less分页

history | less  查看history并通过less分页

less  flie1  flie2

less  -5  file1                每页显示5

7grep命令    查找字符串

grep  字符串文件名 /路径

例: grep "egbert" /home/file1.c

找到返回     0

没找到返回   1

产生错误返回 2

8head  -nk  file 显示file文件的前K

9tail  -nk  file   显示file文件的后K

10sort命令    (不改变源文件)

sort  -c  file找到第一个没有排序的单词,并输出

sort  file1 -o file2   file1排序好之后输出到file2

sort  -u  file  删除所有相同行,排序并显示

sort  -r  file  file逆序排序并显示

11uniq去掉文件中相邻重复的行

12diff命令

13whereis file查找文件的位置

14wc命令  

  -c, --bytes

              print the byte counts

 

  -m, --chars

              print the character counts

 

  -l, --lines

              print the newline counts

 

  -L, --max-line-length

              print the length of the longest line

 

   -w, --words

              print the word counts



15、在一个目录中查找一个文件是否存在

ls  |  grep  -c  filename

返回的找到filename的个数

1、管道  ls |wc -w 将当前目录的文件的单词作为wc命令,wc命令为统计单词个

2cp -a比较常用,可以同时将文件的属性复制过去

3、历史命令的多少是有HISTSIZE(环境变量)决定的,可通过直接赋值来改变

4、操作环境变量需要添加  $  字符

5、定向输入输出  >file  <file   >>file输出追加到file文件中

6vim调到第n行,用:n命令

7C语言相关:全局变量只能用常量表达式赋值 const int a  = 10;虽然a的值不可改变,但是a仍然为变量

8NULL定义在stddef.h头文件中,#define NULL  ((void*)0)0强制类型转换为指针类型,任何对地址0的访问都是非法的,将会导致段错误

9Makefile命令中前加上“-”,如果这句话错误,也会继续执行接下来的命令

10、 命令置换:command1`command2`    command2的结果作为command1的参数

11、创建软连接  ln -s /home/fs/test  game



0 0
原创粉丝点击