25
Jan

linux中文件与目录管理(一)

   Posted by: 士心   in Linux基础

       Linux学习笔记之基础:文件、目录管理。

       在linux中,特别是在没有安装X-system的linux系统中,我们对文件和目录的管理不像在windows中使用"资源管理器"那么直观。在windows中,我们可以用Ctrl+c/x来复制、剪切文件和文件夹,用Ctrl+v来粘贴。在linux中用命令管理起来虽然不是很直观,但是并不麻烦,甚至有时候很有趣、很方便。

        Linux中常用的命令有cd、mkdir、rmdir、cp、rm、mv。一一介绍:

      1、 cd(change directory)改变路径

 
  • cd ..          
  • /..表示上一级目录,.表示当前目录。这个就表示回到上一级目录   
  • cd ~   
  • /回到自己的主目录,如果是root,则回到/root;如果是其他用户,则回到 "/home/用户名" 目录中   
  • cd -   
  • /回到上一个目录,注意不是上一层。比如你在/tmp下面,然后切换到/var,这个时候输入cd -,就直接切换回/tmp下面了。   
  • cd的主要用法就这么多  

     2、mkdir(make directory)创建目录

  •  
  • 用man mkdir可以看到   
  • ……   
  • SYNOPSIS   
  •        mkdir [OPTION] DIRECTORY…    
  • DESCRIPTION   
  •        Create the DIRECTORY(ies), if they do not already exist.    
  •        Mandatory arguments to long options are mandatory for short options too.    
  •        -Z, –context=CONTEXT (SELinux) set security context to CONTEXT    
  •        -m, –mode=MODE    set permission mode (as in chmod), not rwxrwxrwx - umask    
  •        -p, –parents      no error if existing, make parent directories as needed    
  •        -v, –verbose    print a message for each created directory   
  •        –help display this help and exit    
  •        –version    output version information and exit  
  • 英语好的直接就可以看懂。
  • 这里最重要的两个参数是-m 和 -p
  • mkdir -p
  • /可以建立多层目录,不管上层目录存在不存在。比如mkdir -p /1/2/3 不管有没有/1、/1/2这个目录,都可以建立/1/2/3。如果没有这个参数,是办不到的
  • mkdir -m
  • /建立的目录是有默认的权限的,如果想在建立的时候就改变权限,就要使用-m参数了。比如:mkdir -m 777 /tmp/test 这样建立的新目录属性就是drwxrwxrwx了

       3、 rmdir(remove empty directory)删除的目录

  •  
  • DESCRIPTION   
  •        Remove the DIRECTORY(ies), if they are empty.    
  •        –ignore-fail-on-non-empty    ignore each failure that is solely because a directory is non-empty   
  •        -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      output a diagnostic for every directory processed    
  •        –help display this help and exit   
  •        –version   
  •               output version information and exit  
  • 最重要的参数是-p,它的意思是连上层的空目录一起删除,比如上面建立的/1/2/3 ,输入rmdir -p 就删除了/1/2/3.注意只能删除空的目录。

 

cp 、mv、rm参考linux中文件与目录管理(二)

作者: 士心

原载:linux学习笔记-士心

版权所有,转载时请以链接形式注明作者和原始出处及本声明

This entry was posted on 星期五, 01月 25th, 2008 at 9:18 pm and is filed under Linux基础. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One comment

 1 

[...]        接着linux中文件与目录管理(一)继续写。上面说到了cd、mkdir、rmdir,其中mkdir、rmdir是管理目录的。下面介绍cp、rm、mv。 [...]

01月 26th, 2008 at 7:54 pm

我要评论

大名 (*)
邮箱 (will not be published) (*)
网址
评论