您的位置:首页 > 运维架构 > Linux

linux常用命令mkdir,cd,pwd,rmdir,cp,mv,rm,

2015-11-02 18:46 1041 查看
mkdir

create the directory(ies) , if they don’t already exist;

可以创建多个目录,只要他们不存在。

-p,–parents

no error if existing,make parent directories as needed

例如我们的/tmp目录是空的,输入以下命令就会报错

mkdir /tmp/father/son




系统就会报错,因为/tmp目录下没有father目录,它就无法创建son目录

mkdir -p /tmp/father/son




增加了-p选项之后它就会递归的帮助我们把father目录页创建出来

cd

change the current directory to dir

就是改变当前目录到dir目录下

这个命令有几个常见的参数

cd -

返回上一次访问的目录

比如从/tmp进入到了/tmp/father/son目录,输入cd -之后就会回到上一次访问的目录/tmp



cd ..

返回的父目录,比如进入到了/tmp/father/son目录,输入cd ..会返回到/tmp/father/son的父目录,也就是/tmp/fahter



cd ~

返回到当前用户的home目录,如果是root用户则会返回到/root目录



pwd

print the name of the current/work direcotry

显示当前或工作目录



rmdir

remove the directory(ies) , if they are empty

删除空目录,如果不是空目录就不能删除

rmdir /tmp/father




会报错显示目录不是空目录

-p

remove the direcotry and its ancesotr eg: rmdir -p a/b/c is similar to rmdir a/b/c a/b a

会把祖先目录也全部删除,这个参数大家就不要使用,太危险!!!!



cp

copy the source to dest

把源文件复制到目的地

注意这里复制的是文件,不包括目录

把/etc/shadow文件复制到/tmp/fahter/son目录下



如果复制目录的话会报错



-r,–recursively

copy direcotries recursively

递归的复制目录

虽然翻译是递归的复制目录,但大家直接理解为复制目录就可以了。



-p same as –preserve=mode,ownership,timestamps

–preserve

preserve the specified attributes(default:mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all

保持特殊属性(默认情况下这些属性是模式,拥有者关系,修改时间),如果有必要的话可以保持所有属性

这是没有加-p选项的



可以看到这两个文件的最后修改时间是不一样的,当前目录下复制过来的shadow的最后修改时间就是刚刚复制的时间。

加上-p选项



还有一个小技巧,在复制的时候我们可以修改文件名



mv

rename source to dest ,or remove source to dest

把源文件重命名为目标文件,或者把源文件移动到目标文件

-f ,–force

do not prompt before overwriting

在覆盖之前不会提示是否真的要移动

同时在移动的时候也可以改名字

rm

-r,–recursive

递归的删除目录

-d

删除空目录

-f

强制删除
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux