Linux文件管理命令

2018-08-22  本文已影响0人  sunnowyli

1、Linux上的文件管理命令有:

      mkdir - make directories

           mkdir [OPTION]... DIRECTORY...

                   -m, --mode=MODE,set file mode (as in chmod), not a=rwx - umask

                   -p, --parents,no error if existing, make parent directories as needed/按需创建父目录

                   -v, --verbose/显示详细信息

                   print a message for each created directory

                    例: >>mkdir -v -m 700 test2   ##也支持 mkdir -m u=rwx,g+w,o-x test2

                                  mkdir: created directory ‘test2’

                            >> ll -d test2

                                drwx------ 2 vn0eco6 vn0eco6 6 Aug 22 08:10 test2

                            >>mkdir -p /tmp/a/b/c/d/e

rmdir - remove empty directories // 删除空目录

             rmdir [OPTION]... DIRECTORY...

                    -p, --parents,remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to                         

                            'rmdir a/b/c a/b a'  /删除某空目录后,如果其父母为空,则一并删除

                    -v, --verbose

cp - copy files and directories

      单源复制: cp [OPTION]... [-T] SOURCE DEST 【如果DEST不存在则创建,存在则覆盖;】

     多源复制:  cp [OPTION]... SOURCE... DIRECTORY

                         cp [OPTION]... -t DIRECTORY SOURCE...

                        【如果DEST不存在或为文件则报错,存在且为目录则先创建与原文件相同的文件,然后在复制数据;】

    常用选项:-i :交互式

                    -f : force

                    -p:--preserve=mode,保留属性复制, preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context,links, xattr, all

                    -a, --archive, same as  --preserve=all

                    -R, -r, --recursive,copy directories recursively,递归复制

                     -d   same as --no-dereference --preserve=links,复制符号链接文件本身,而非其所指向的源文件

                    >> ll /etc/{passwd,fstab}

                            -rw-r--r--. 1 root root  543 Jun 11 05:24 /etc/fstab

                            -rw-r--r--  1 root root 2008 Aug 13 08:09 /etc/passwd

                    >>cp -pv /etc/{passwd,fstab}  /tmp

                                ‘/etc/passwd’ -> ‘/tmp/passwd’

                                ‘/etc/fstab’ -> ‘/tmp/fstab’

                    >> ll /tmp/{passwd,fstab}

                                -rw-r--r-- 1 vn0eco6 vn0eco6  543 Jun 11 05:24 /tmp/fstab

                                -rw-r--r-- 1 vn0eco6 vn0eco6 2008 Aug 13 08:09 /tmp/passwd

                     [-d 示例]

                    >> ll /tmp/wnpasswd

                            lrwxrwxrwx 1 vn0eco6 vn0eco6 6 Aug 22 09:15 /tmp/wnpasswd -> passwd

                    >> cp -v wnpasswd /tmp/r1

                    >>cp -dv wnpasswd /tmp/r2

                    >> ll r*

                            -rw-r--r-- 1 vn0eco6 vn0eco6 2008 Aug 22 09:16 r1

                            lrwxrwxrwx 1 vn0eco6 vn0eco6    6 Aug 22 09:16 r2 -> passwd

mv -  move (rename) files 移动文件或改名

          mv [OPTION]... [-T] SOURCE DEST

         mv [OPTION]... SOURCE... DIRECTORY

         mv [OPTION]... -t DIRECTORY SOURCE...

           常用选项:

                     -i :交互式

                     -f :force

        >>mv file /tmp/test

rm:  remove files or directories

        rm [OPTION]... FILE..

        常用选项:

            -i :交互式

            -f : force

            -r :recursive,递归删除

        >>rm -rf  /tmp/tst

上一篇下一篇

猜你喜欢

热点阅读