Linux学习笔记(2)

来源:互联网 发布:centos 删除 rm 编辑:程序博客网 时间:2024/05/18 02:30

Linux 常用命令

touch:
作用:改变目录或文件的时间,或创建一个新的文件
用法:

[jerry@localhost test]$ touch newfile1 newfile2[jerry@localhost test]$ lltotal 0-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile1-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2
  • [-r –reference]把指定的目录或文件的时间设置成和参考目录或文件的时间相同,touch -r [参考…] [指定…]
[jerry@localhost test]$ touch newfile3[jerry@localhost test]$ lltotal 0-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile1-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile3[jerry@localhost test]$ touch -r newfile3 newfile1[jerry@localhost test]$ lltotal 0-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile1-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:53 newfile2-rw-rw-r--. 1 jerry jerry 0 Oct  1 21:57 newfile3

cat:
作用:

  • 一次显示整个文件,cat filename
  • 从键盘创建一个文件,cat > filename
  • 将多个文件合并成一个文件,cat file1 file2 > newfile

用法:

[jerry@localhost test]$ cat /etc/issue\SKernel \r on an \m[jerry@localhost test]$ cat > kbfileHello WorldLinux    Enjoy ^C[jerry@localhost test]$ lskbfile  newfile1  newfile2  newfile3[jerry@localhost test]$ cat kbfile Hello WorldLinuxEnjoy

tac:
作用:与cat类似,反向列示
用法:

[jerry@localhost test]$ tac kbfile EnjoyLinuxHello World

more:
作用:功能与cat类似,cat命令是将整个文件的内容从上到下显示在屏幕上,more会一页一页的显示,方便使用者逐页阅读

  • 按空格键[space]:显示下一页
  • 按字母键b:显示上一页

用法:

more filename
  • [-n –num]每页显示n行

less:
作用:与more类似,但更具弹性,less 在查看之前不会加载整个文件
用法:

less filename

浏览文件过程中

  • 按/内容,向下搜索“内容”,按字母键n翻页
  • 按?内容,向上搜索“内容”,按字母键n翻页

head:
作用:显示文件的开头,默认显示前10行
用法:

head filename
  • [-n –lines]:指定显示文件前n行

tail:
作用:与head类似,反向显示
用法:

tail filename
  • [-n –lines]:指定显示文件末尾n行
  • [-f –follow]:动态显示文件末尾内容,可以用来监视log文件
0 0