zoukankan      html  css  js  c++  java
  • linux基础命令篇一

    1.ls列出文件信息,默认为当前目录下 

    [root@andy ~]# ls
    anaconda-ks.cfg

    ls -a列出所有文件包括以“.”开头的隐藏文件

    [root@andy ~]# ls -a
    . .. anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc .cshrc .mysql_history .pki .tcshrc .viminfo

    ls -d列出目录本身并不包括目录中的文件

    [root@andy ~]# ls -d
    .

    ls -lh长输出文件大小人类易读

    [root@andy ~]# ls -lh
    总用量 4.0K
    -rw-------. 1 root root 1.3K 7月 3 08:02 anaconda-ks.cfg

    ls -ltr列出目前工作目录的文件,越新的排越后面 

    [root@andy ~]# ls -ltr
    总用量 4
    -rw-------. 1 root root 1261 7月 3 08:02 anaconda-ks.cfg
    drwxr-xr-x 2 root root 6 10月 25 15:12 haha

    ls -ltr s*列出目前工作目录下所有名称是 s 开头的文件,越新的排越后面 

    [root@andy bin]# ls -ltr s*
    -rwxr-xr-x. 1 root root 33368 6月 10 2014 soelim
    -rwxr-xr-x 1 root root 27224 6月 10 2014 soundstretch
    -rwxr-xr-x. 1 root root 76016 6月 10 2014 sed
    -rwxr-xr-x. 1 root root 49528 6月 10 2014 sdiff
    -rwxr-xr-x. 1 root root 37576 6月 10 2014 setfacl
    -rwxr-xr-x. 1 root root 56240 11月 20 2015 sqlite3
    -rwxr-xr-x. 1 root root 228496 11月 5 2016 strip
    -rwxr-xr-x. 1 root root 29064 11月 5 2016 strings
    -rwxr-xr-x. 1 root root 33104 11月 5 2016 size
    -rwxr-xr-x. 1 root root 4341 11月 5 2016 sotruss
    -rwxr-xr-x. 1 root root 23152 11月 5 2016 sprof
    -rwxr-xr-x. 1 root root 15608 11月 6 2016 showkey
    -rwxr-xr-x. 1 root root 15832 11月 6 2016 showconsolefont
    -rwxr-xr-x. 1 root root 11600 11月 6 2016 setvtrgb
    -rwxr-xr-x. 1 root root 11472 11月 6 2016 setmetamode
    -rwxr-xr-x. 1 root root 11432 11月 6 2016 setleds

    2.man命令帮助手册

    [root@andy ~]# man cd
    BASH_BUILTINS(1) General Commands Manual BASH_BUILTINS(1)

    NAME
    bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue,
    declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs,
    kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source,
    suspend, test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in commands, see
    bash(1)

    BASH BUILTIN COMMANDS
    Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts
    -- to signify the end of the options. The :, true, false, and test builtins do not accept options and do not
    treat -- specially. The exit, logout, break, continue, let, and shift builtins accept and process arguments
    beginning with - without requiring --. Other builtins that accept arguments but are not specified as accepting
    options interpret arguments beginning with - as invalid options and require -- to prevent this interpretation.
    : [arguments]

    3.pwd显示当前活动目录名称

    [root@andy bin]# pwd
    /bin

    4.cd切换目录

    输入cd回到当前用户家目录

    [root@andy bin]# cd
    [root@andy ~]#

    cd ~切换到家目录

    [root@andy /]# cd ~
    [root@andy ~]#

     cd -回到上次所处的目录

    [root@andy /]# cd ~
    [root@andy ~]# cd -
    /
    [root@andy /]#

    cd ..切换到上级目录

    [root@andy ~]# cd ..
    [root@andy /]#

    cd /tmp(切换到指定文件夹)

    [root@andy tmp]# cd /root
    [root@andy ~]#

    5.mkdir创建目录(不能默认创建级联目录,若要创建级联目录要加-p)

    mkdir创建目录

    [root@andy ~]# mkdir test1
    [root@andy ~]# ls
    anaconda-ks.cfg test test1
    [root@andy ~]#

    mkdir -p创建级联目录

    [root@andy ~]# mkdir -p test4/test5
    [root@andy ~]# ls -ltr test4
    总用量 0
    drwxr-xr-x 2 root root 6 10月 25 16:13 test5

    6.touch创建普通文件

    [root@andy ~]# touch test
    [root@andy ~]# ls -ltr
    总用量 4
    -rw-------. 1 root root 1261 7月 3 08:02 anaconda-ks.cfg
    -rw-r--r-- 1 root root 0 10月 25 16:17 test

    7.echo输入并显示一行文本( 换行)

    [root@andy ~]# echo "hello"
    hello
    [root@andy ~]#

    echo -e允许对下面列出的加反斜线转义的字符进行解释

    [root@andy ~]# echo -e "hello hello"
    hello
    hello
    [root@andy ~]# echo "hello hello"
    hello hello
    [root@andy ~]#

     8.cp复制文件和目录

    cp -p 保持属性不变

    [root@andy ~]# cp test test2
    [root@andy ~]# ls -ltr
    总用量 4
    -rw-------. 1 root root 1261 7月 3 08:02 anaconda-ks.cfg
    -rwxrwxrwx 1 root root 0 10月 29 13:33 test
    -rwxr-xr-x 1 root root 0 10月 29 13:33 test2(权限改变了)
    [root@andy ~]# cp -p test test3
    [root@andy ~]# ls -ltr
    总用量 4
    -rw-------. 1 root root 1261 7月 3 08:02 anaconda-ks.cfg
    -rwxrwxrwx 1 root root 0 10月 29 13:33 test3(权限相同)
    -rwxrwxrwx 1 root root 0 10月 29 13:33 test
    -rwxr-xr-x 1 root root 0 10月 29 13:33 test2

    cp -r递归复制目录

    [root@andy ~]# mkdir text
    [root@andy ~]# cd text
    [root@andy text]# mkdir text1
    [root@andy text]# cd
    [root@andy ~]# cp text text2
    cp: 略过目录"text"(cp无法直接复制递归目录)
    [root@andy ~]# cp -r text text3
    [root@andy ~]# ls -ltr
    总用量 4
    -rw-------. 1 root root 1261 7月 3 08:02 anaconda-ks.cfg
    -rwxrwxrwx 1 root root 0 10月 29 13:33 test3
    -rwxrwxrwx 1 root root 0 10月 29 13:33 test
    -rwxr-xr-x 1 root root 0 10月 29 13:33 test2
    drwxr-xr-x 3 root root 19 10月 29 13:38 text
    drwxr-xr-x 3 root root 19 10月 29 13:38 text3
    [root@andy ~]# cd text3
    [root@andy text3]# ls
    text1

    cp -a复制文件时尽可能保持文件的结构和属性等同于-dpR(一般使用cp命令复制目录加-a复制普通文件不需要加-a即上边的集合)

    9.mv移动(改名)文件

    [root@andy ~]# ls
    anaconda-ks.cfg test
    [root@andy ~]# mv test test1
    [root@andy ~]# ls
    anaconda-ks.cfg test1

    10.rm移除文件或目录

    rm -r移除目录需要加-r

    [root@andy ~]# mkdir test
    [root@andy ~]# rm -r test
    rm:是否删除目录 "test"?y
    [root@andy ~]# ls
    anaconda-ks.cfg

    rm -f强制移除加-f(一般rm -rf连在一起用)

    [root@andy ~]# ls
    anaconda-ks.cfg test1
    [root@andy ~]# rm test1
    rm:是否删除普通空文件 "test1"?y
    [root@andy ~]# ls
    anaconda-ks.cfg
    [root@andy ~]# touch test
    [root@andy ~]# rm -f test
    [root@andy ~]# ls
    anaconda-ks.cfg

    [root@andy ~]# ls
    anaconda-ks.cfg
    [root@andy ~]# mkdir test
    [root@andy ~]# rm -r test
    rm:是否删除目录 "test"?y
    [root@andy ~]# ls
    anaconda-ks.cfg
    [root@andy ~]# mkdir test
    [root@andy ~]# rm -rf test
    [root@andy ~]# ls
    anaconda-ks.cfg

  • 相关阅读:
    C#中的代理(Delegate)
    动态栈C语言
    AMS算法
    动态队列实现C语言
    带头结点的循环单链表C语言
    静态栈C语言
    不带头结点的单链表C语言实现
    带头结点的双向循环链表C语言
    带头节点的单链表C语言实现
    使用函数指针模拟C++多态
  • 原文地址:https://www.cnblogs.com/yzandy/p/11738430.html
Copyright © 2011-2022 走看看