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

Linux文件管理基本命令

2016-08-01 21:23 585 查看
cp命令
cp是用来将文件进行单源或多源文件或目录复制到指定的文件或目录

语法

cp [OPTION]... [-T] SOURCE DEST 单源复制
cp [OPTION]... SOURCE... DIRECTORY  多源复制目标必须是目录
cp [OPTION]... -t DIRECTORY SOURCE...多源复制目标必须是目录

常用选项

-a,--archive   #备份的时候用 跟-dR 同义
same as -dR --preserve=all

-d  #如果文件为link#链接不加-d默认复制link指定文件。加-d只复制软链接文件
-f, --force   #强制复制,无论目的文件是否存在
-i, --interactive #覆盖之间询问用户
prompt  before  overwrite  (overrides  a
previous -n option)
-l, --link #创建硬链接
link files instead of copying
-p     same as --preserve=mode,ownership,
--preserve[=ATTR_LIST] #保留源文件的属主、权限、时间戳
preserve    the   specified   attributes
(default: mode,ownership,timestamps), if
possible additional attributes: context,
links, xattr, all
-R, -r, --recursive #递归,用来复制目录
copy directories recursively

-s, --symbolic-link 复制软链接
make symbolic links instead of copying
-v, --verbose #显示详细操作
explain what is being done
示例

[root@localhost /]# cp -a /etc /testdir/ #递归复制,onwership,timestamp,mode不变
[root@localhost /]# ll -d /etc /testdir/etc/
drwxr-xr-x. 102 root root 12288 Jul 26 11:40 /etc
drwxr-xr-x. 102 root root 12288 Jul 26 11:40 /testdir/etc/
[root@localhost /]# cp /etc/redhat-release /testdir/noaddd
[root@localhost /]# cp -d /etc/redhat-release /testdir/addd #复制软链接
[root@localhost /]# ll /testdir/
total 4
lrwxrwxrwx 1 root root 14 Jul 26 11:46 addd -> centos-release #只复制软链接一般链接错误
-rw-r--r-- 1 root root 27 Jul 26 11:46 noaddd
[root@localhost /]# cp -s /etc/redhat-release /testdir/#-s创建正确的路径的链接文件
[root@localhost /]# ll /testdir/
total 0
lrwxrwxrwx 1 root root 19 Jul 26 11:52 redhat-release -> /etc/redhat-release
[root@localhost /]# cp -r /boot/ /testdir/  #-r复制目录
[root@localhost /]# ll /testdir/
total 4
dr-xr-xr-x 5 root root 4096 Jul 26 11:55 boot
[root@localhost /]# cp -v /etc/issue /etc/fstab /testdir/
`/etc/issue' -> `/testdir/issue' #显示详细信息 多源复制目标必须是目录
`/etc/fstab' -> `/testdir/fstab'
[root@localhost /]# ll /testdir/
total 8
-rw-r--r-- 1 root root 921 Jul 26 11:57 fstab
-rw-r--r-- 1 root root 103 Jul 26 11:57 issue
......
mv命令

mv - move (rename) files #移动或从命名文件或目录


语法

mv [OPTION]... [-T] SOURCE DEST 单源移动
mv [OPTION]... SOURCE... DIRECTORY #多源移动 必须目录
mv [OPTION]... -t DIRECTORY SOURCE... #多源移动 必须目录
常用选项

-f, --force   #不提示覆盖。
-i, --interactive #覆盖前提醒用户
-v, --verbose #显示详细过程

示例
[root@localhost /]# touch /testdir/fiel file1 #创建空文件做实验
[root@localhost /]# mv /etc/issue /testdir/fiel  #把文件复制覆盖,默认是-i提醒
mv: overwrite `/testdir/fiel'? yes
[root@localhost /]# mv -f /etc/fstab /testdir/fiel1 #把文件覆盖, -f不提醒覆盖。
[root@localhost /]# mv -v /etc/inittab /testdir/
`/etc/inittab' -> `/testdir/inittab' #显示详细信息
[root@localhost testdir]# mv file fi #相同路径移动表示更改用户名
[root@localhost testdir]# ls
fi  file1


rm命令
rm - remove files or directories #删除文件或目录。Linux中文件删除是无法找回的,使用此命令请慎重


语法

rm [OPTION]... FILE...


常用选项
-f, --force #直接删除,不提醒
-i   #提醒用户是否删除,别名定义加有-i
-r, -R, --recursive  #递归,用来删除目录
-v, --verbose :显示详细过程


示例
[root@localhost roooa]# ls
dir3  dir4  file7  file8  inittab
[root@localhost roooa]# rm file7 #移除file7文件,默认交互是提醒
rm: remove regular empty file `file7'? yes
[root@localhost roooa]# rm -r dir3/ #递归移除目录
rm: descend into directory `dir3'? yes
rm: remove regular empty file `dir3/fill2'? yes
rm: remove regular empty file `dir3/fill3'? yes
rm: remove regular empty file `dir3/fill1'? yes
rm: remove directory `dir3'? yes
[root@localhost roooa]# rm -fr dir4/ #强制删除不提醒


本文出自 “10974793” 博客,请务必保留此出处http://nieqi.blog.51cto.com/10974793/1833211
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: