linux入门第2篇-linux基础命令

来源:互联网 发布:mac pkg文件解压 编辑:程序博客网 时间:2024/06/06 03:34

1.查看目录和文件

           (1)显示当前目录:pwd

[root@hostline /]# pwd/
            (2)改变目录:cd

[root@hostline /]# cd usr[root@hostline usr]# 
           在/usr/bin子目录时,可以用命令进入/usr子目录

[root@hostline bin]# cd ..[root@hostline usr]# ls
           在/usr/bin子目录中还可以使用命令进入根目录

[root@hostline usr]# cd /[root@hostline /]# 
2.列出目录内容: ls

[root@hostline /]# lsa.txt  boot  etc   lib    media  opt   root  sbin  sys   tmp  varbin    dev   home  lib64  mnt    proc  run   srv   test  usr
           不带ls的命令,列出的目录下所有文件和子目录
[root@hostline /]# ls -l总用量 44-rw-r--r--.   1 root root   88 5月  18 20:32 a.txtlrwxrwxrwx.   1 root root    7 5月  17 19:24 bin -> usr/bindr-xr-xr-x.   3 root root 4096 5月  17 19:48 bootdrwxr-xr-x.  20 root root 3260 5月  24 18:26 devdrwxr-xr-x. 137 root root 8192 5月  24 18:26 etcdrwxr-xr-x.   4 root root   43 5月  19 20:09 homelrwxrwxrwx.   1 root root    7 5月  17 19:24 lib -> usr/liblrwxrwxrwx.   1 root root    9 5月  17 19:24 lib64 -> usr/lib64drwxr-xr-x.   2 root root    6 5月  25 2015 mediadrwxr-xr-x.   2 root root    6 5月  25 2015 mntdrwxr-xr-x.   3 root root   15 5月  17 19:42 optdr-xr-xr-x. 499 root root    0 5月  24 18:26 procdr-xr-x---.  18 root root 4096 5月  24 18:30 rootdrwxr-xr-x.  38 root root 1160 5月  24 18:31 runlrwxrwxrwx.   1 root root    8 5月  17 19:24 sbin -> usr/sbindrwxr-xr-x.   2 root root    6 5月  25 2015 srvdr-xr-xr-x.  13 root root    0 5月  24 18:26 sysdrwxr-xr-x.   2 root root   21 5月  20 11:14 testdrwxrwxrwt.  73 root root 8192 5月  24 19:27 tmpdrwxr-xr-x.  14 root root 4096 5月  20 11:35 usrdrwxr-xr-x.  21 root root 4096 5月  24 18:26 var
          ls列出的是目录和文件的详细信息
          ls -f 在每个目录上加/,在可执行文件后加*,在连接文件后加@。
[root@hostline /]# ls -f.   boot  proc  sys  root  var  bin   lib    home   mnt  srv   a.txt..  dev   run   etc  tmp   usr  sbin  lib64  media  opt  test
         ls -a列出隐藏文件
[root@hostline /]# ls -a.   a.txt  boot  etc   lib    media  opt   root  sbin  sys   tmp  var..  bin    dev   home  lib64  mnt    proc  run   srv   test  usr

2.列出目录内容:dir和vdir

[root@hostline /]# dir usrbin  games    lib    libexec  mysoft  share  tmpetc  include  lib64  local    sbin    src
         vdir相当于ls命令上加-l
[root@hostline /]# vdir usr 总用量 256dr-xr-xr-x.   2 root root 45056 5月  17 19:43 bindrwxr-xr-x.   2 root root     6 5月  25 2015 etcdrwxr-xr-x.   2 root root     6 5月  25 2015 gamesdrwxr-xr-x.  36 root root  4096 5月  17 19:41 includedr-xr-xr-x.  43 root root  4096 5月  17 19:41 libdr-xr-xr-x. 139 root root 69632 5月  17 19:43 lib64drwxr-xr-x.  35 root root  8192 5月  17 19:41 libexecdrwxr-xr-x.  13 root root  4096 5月  21 21:30 localdrwxr-xr-x.   8 root root  4096 5月  21 21:31 mysoftdr-xr-xr-x.   2 root root 20480 5月  17 19:43 sbindrwxr-xr-x. 240 root root  8192 5月  17 19:42 sharedrwxr-xr-x.   4 root root    32 5月  17 19:24 srclrwxrwxrwx.   1 root root    10 5月  17 19:24 tmp -> ../var/tmp
3.查看文本文件:cat和more

            cat命令用于查看文件内容(通常是一个文本文件),后跟文件名作为参数

[root@hostline /]# cat a.txtddddddddddddddddddddddsfnasjvaadfasdfandfajfdaasdfasfafasdfasdfasfdanihapcongdidididi
            cat -n 在每行前面显示行号
[root@hostline /]# cat -n  a.txt      1ddddddddddddddddddddddsfnasjva     2adfasdfandfajfda     3asdfasfafasdfasdfasfdanihapcongdidididi
4.阅读文件的开头和结尾:head和tail
[root@hostline /]# head -n 2 a.txtddddddddddddddddddddddsfnasjvaadfasdfandfajfda
        说明:-n显示行号,2显示前面两行
[root@hostline /]# tail -n 2 a.txtadfasdfandfajfdaasdfasfafasdfasdfasfdanihapcongdidididi
        说明:同上,显示下面两行

5.查找文件内容:grep

[root@hostline /]# cat a.txtddddddddddddddddddddddsfnasjvaadfasdfandfajfdaasdfasfafasdfasdfasfdanihapcongdidididinihaoi[root@hostline /]# grep nihao a.txtnihaoi
           说明:nihao是查找的内容

6.我的东西在哪里   find命令

[root@hostline /]# find /usr/bin -name zip -print/usr/bin/zip
           说明:find在寻找过程中,需要指定路径 /usr/bin  说明在bin文件夹下面查找

                       -name zip 是要查找的名称未zip的文件

                       -print表示将结果标准输出

7.定位功能 locate命令

[root@hostline /]# locate *.doc/usr/lib/kbd/keymaps/legacy/i386/qwerty/no-latin1.doc/usr/lib64/python2.7/pdb.doc/usr/mysoft/openssl-1.0.1t/crypto/rc2/rrc2.doc/usr/mysoft/openssl-1.0.1t/crypto/rc4/rrc4.doc/usr/share/doc/doxygen-1.8.5/examples/page.doc
               说明:该命令可以更快的查找你想要的文件

原创粉丝点击