10.2-linux文件与目录管理
1.1-目录的相关操作
. rm
Remove (unlink) the FILE(s). -f, --force #强制删除
ignore nonexistent files, never prompt -i prompt before every removal -I prompt once before removing more than three files, or when
removing recursively. Less intrusive than -i, while still
giving protection against most mistakes
-r, -R, --recursive 连同目录和内容一块删除
remove directories and their contents recursively By default, rm does not remove directories. Use the --recursive (-r
or -R) option to remove each listed directory, too, along with all
of its contents.
#删除名字带有 -
To remove a file whose name starts with a ‘-’, for example ‘-foo’,
use one of these commands: rm -- -foo rm ./-foo Note that if you use rm to remove a file, it is usually possible to
recover the contents of that file. If you want more assurance that
the contents are truly unrecoverable, consider using shred.
------------
. pwd
Print the full filename of the current working directory. -L, --logical #显示出当前路径,包含连接(link)路径
use PWD from environment, even if it contains symlinks -P, --physical #显示出当前路径,而非使用连接(link)路径
avoid all symlinks
------------
. mkdir
SYNOPSIS
mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
-m, --mode=MODE #设置配置文件的权限
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed ------------
. rmdir
SYNOPSIS
rmdir [OPTION]... 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 --->rm -r test 将目录下的东西也删除
1.2.1查看文件目录
ls [选项]... [文件]...
列出 FILE 的信息(默认为当前目录)。
-a, --all 不隐藏任何以. 开始的项目
-d, --directory 当遇到目录时列出目录本身而非目录内的文件
-f 不进行排序,-aU 选项生效,-lst 选项失效
-F, --classify 加上文件类型的指示符号(*/=@| 其中一个)
--format=关键字 交错-x,逗号分隔-m,水平-x,长-l,
单栏-,详细-l,垂直-C
--full-time 即-l --time-style=full-iso
-h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小
(例如 1K 234M 2G)
--si 同上面类似,但是使用1000 为基底而非1024
-i, --inode 显示每个文件的inode 号
-l 使用较长格式列出信息
-n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号
-r, --reverse 排序时保留顺序
-R, --recursive 递归显示子目录
-S 根据文件大小排序
-t 根据修改时间排序
-----------
ll ----> ls -l 一样
1.2.2复制,删除,与移动:cp ,rm, mv
. cp
用法:cp [选项]... [-T] 源文件 目标文件
或:cp [选项]... 源文件... 目录
或:cp [选项]... -t 目录 源文件...
将源文件复制至目标文件,或将多个源文件复制至目标目录。 长选项必须使用的参数对于短选项时也是必需使用的。
* -a, --archive 相当于-pdr 等于-dR --preserve=all
--backup[=CONTROL 为每个已存在的目标文件创建备份
-d 复制连接文件属性而非文件本身,等于--no-dereference --preserve=links
-f, --force 如果目标文件无法打开则将其移除并重试(当 -n 选项
存在时则不需再选此项)
*-i, --interactive 覆盖前询问(使前面的 -n 选项失效)
-l, --link 进行硬连接,文件而不复制
*-p 连同文件的属性一起复制过去,等于--preserve=模式,所有权,时间戳
--preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如果
可能保持附加属性:环境、链接、xattr 等
-s, --symbolic-link 只创建符号链接而不复制文件
-u, --update 目标文件比源文件旧才更新目标文件
-------
使用范例一:
[root@wen tmp]# cp ~/.bashrc /tmp/bashrc
[root@wen tmp]# cp -i ~/.bashrc /tmp/bashrc
cp:是否覆盖"/tmp/bashrc"?
[root@wen tmp]# cd /tmp
[root@wen tmp]# cp /var/log/wtmp .
[root@wen tmp]# ls -l /var/log/wtmp wtmp
-rw-rw-r--. root utmp 10月 : /var/log/wtmp
-rw-r--r-- root root 10月 wtmp
[root@wen tmp]# cp -a /var/log/wtmp wtmp_2
[root@wen tmp]# ls -l /var/log/wtmp wtmp_2
-rw-rw-r--. root utmp 10月 : /var/log/wtmp
-rw-rw-r--. root utmp 10月 wtmp_2 范例二:
[root@wen tmp]# cp /etc/ /tmp
cp: 略过目录"/etc/"
[root@wen tmp]# cp -r /etc/ /tmp [root@wen tmp]# ll bashrc
-rw-r--r-- root root 10月 bashrc
[root@wen tmp]# cp -s bashrc bashrc_slink
[root@wen tmp]# cp -l bashrc bashrc_hlink
[root@wen tmp]# ll bashrc*
-rw-r--r-- root root 10月 bashrc
-rw-r--r-- root root 10月 bashrc_hlink #硬连接
lrwxrwxrwx root root 10月 : bashrc_slink -> bashrc [root@wen tmp]# cp -u ~/.bashrc /tmp/bashrc #常用于备份 [root@wen tmp]# cp bashrc_slink bashrc_slink_1
[root@wen tmp]# cp -d bashrc_slink bashrc_slink_2 #复制连接文件属性而非本身
[root@wen tmp]# ll bashrc bashrc_slink*
-rw-r--r-- root root 10月 bashrc
lrwxrwxrwx root root 10月 : bashrc_slink -> bashrc
-rw-r--r-- root root 10月 : bashrc_slink_1
lrwxrwxrwx root root 10月 : bashrc_slink_2 -> bashrc
cp
rm
[root@wen ~]# cd /tmp
[root@wen tmp]# ls
bashrc bashrc_slink bashrc_slink_2 oldboy wtmp_2
bashrc_hlink bashrc_slink_1 etc wtmp*
rm:是否删除普通文件 "bashrc"?y
已删除"bashrc"
rm:是否删除普通文件 "bashrc_hlink"?y
已删除"bashrc_hlink"
rm:是否删除符号链接 "bashrc_slink"?y
已删除"bashrc_slink"
rm:是否删除普通文件 "bashrc_slink_1"?y
已删除"bashrc_slink_1"
rm:是否删除符号链接 "bashrc_slink_2"?y
已删除"bashrc_slink_2"
[root@wen tmp]# ls
etc oldboy wtmp wtmp_2
[root@wen tmp]# rm -fr /tmp/etc
[root@wen tmp]# ls
oldboy wtmp wtmp_2
[root@wen tmp]# \rm -r /tmp/wtmp* #没有询问删除
[root@wen tmp]# ls
oldboy
[root@wen tmp]# touch ./-aaa-
[root@wen tmp]# ls
-aaa- oldboy
[root@wen tmp]# rm ./-aaa- #或者 rm -- -aaa-
rm:是否删除普通空文件 "./-aaa-"?y
[root@wen tmp]# ls
oldboy
rm
用法:mv [选项]... [-T] 源文件 目标文件
或:mv [选项]... 源文件... 目录
或:mv [选项]... -t 目录 源文件...
将源文件重命名为目标文件,或将源文件移动至指定目录。
-f, --force 覆盖前不询问
-i, --interactive 覆盖前询问
-u, --update 只在源文件文件比目标文件新,或目标文件
不存在时才进行移动
[root@wen tmp]# cp ~/.bashrc bashrc
[root@wen tmp]# mkdir mvtest
[root@wen tmp]# mv bashrc mvtest
[root@wen tmp]# mv mvtest mvtest2 #重命名
[root@wen tmp]# ls
mvtest2 oldboy
mv
1.3 文件内容查阅
10.2-linux文件与目录管理的更多相关文章
- Linux 文件与目录管理
Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...
- CentOS(九)--与Linux文件和目录管理相关的一些重要命令①
接上一篇文章,实际生产过程中的目录管理一定要注意用户是root 还是其他用户. 一.目录与路径 1.相对路径与绝对路径 因为我们在Linux系统中,常常要涉及到目录的切换,所以我们必须要了解 & ...
- linux文件与目录管理笔记
### Linux文件与目录管理 ---------- 绝对路径: / 相对路径:不以/开头的 当前目录 . 上一个工作目录 - 用户主目录 ~ root账户的主目录是/root 其他用户是/home ...
- 【转】第七章、Linux 文件与目录管理
原文网址:http://vbird.dic.ksu.edu.tw/linux_basic/0220filemanager.php 第七章.Linux 文件与目录管理 最近升级日期:2009/08/26 ...
- Linux 文件与目录管理,Linux系统用户组的管理
一.Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什 ...
- 七、Linux 文件与目录管理
Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...
- CentOS(十)--与Linux文件和目录管理相关的一些重要命令②
在结束了第二期的广交会实习之后,又迎来了几天休闲的日子,继续学习Linux.在上一篇随笔 Linux学习之CentOS(十七)--与Linux文件和目录管理相关的一些重要命令① 中,详细记录了与Lin ...
- Linux文件与目录管理(一)
一.Linux文件与目录管理 1.Linux的目录结构是树状结构,最顶级的目录是根目录/(用"/"表示) 2.Linux目录结构图: /bin:bin是Binary的缩写,这个目录 ...
- 第七章、Linux 文件与目录管理
第七章.Linux 文件与目录管理 1. 目录与路径 1.1 相对路径与绝对路径 1.2 目录的相关操作: cd, pwd, mkdir, rmdir 1.3 关於运行档路径的变量: $PATH ...
- 2. Linux文件与目录管理
一.目录与路径 1. 相对路径与绝对路径 绝对路径:路径写法[一定由根目录 / 写起],如:/usr/share/doc 相对路径:路径写法[不由 / 写起], /usr/share/doc 要到 / ...
随机推荐
- mysql_DML_select_union
使用union可以将多个select 语句的查询结果集组合成一个结果集.select 字段列表1 from table1union [all]select 字段列表2 from table2...说明 ...
- Cef 重写alert与confirm弹窗
在使用form内嵌cef浏览本地页面的时候,如果出现alert弹窗,会在标题栏显示页面所在目录.所以想起来重写alert的样式,通过MessageBox进行提示,或者自己写一个弹窗. 以下代码基于 3 ...
- 第 1 章 前端之html
一.html初始 1.web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM ...
- 【BASIS系列】SAP BASIS模块-后台配置的传输
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP BASIS模块-后台配 ...
- OAUTH2.0协议-菜鸟级
OAUTH2.0入门必看 一.摘要 OAUTH协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是OAUTH的授权不会使第三方触及到用户的帐号信息(如用户名与密码),即 ...
- 开源企业IM-免费企业即时通讯-ENTBOOST V2014.183 Linux版本号正式公布
版权声明:本文为博主原创文章,欢迎转载,转载请尽量保持原文章完整,谢谢! https://blog.csdn.net/yanghz/article/details/37807975 ENTBOOST, ...
- 缓存模块redis
1.安装 安装 下载 :wget http://download.redis.io/releases/redis-3.2.8.tar.gz 解压:tar xzf redis-3.2.8.tar.gz ...
- WEB应用安全解决方案测试验证
WEB应用安全解决方案测试报告 --- By jiang.jx at 2017-08-11 WEB应用安全解决方案.docx 链接:https://share.weiyun.com/068b05467 ...
- spring(四):spring中给bean的属性赋值
spring中给bean的属性赋值 xml文件properties标签设置 <bean id="student" class="com.enjoy.study.ca ...
- Java集合、IO流、线程知识
一.集合: 1. 集合框架: 1)Collection (1)List:有序的,有索引,元素可重复. (add(index, element).add(index, Collection).remov ...