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 要到 / ...
随机推荐
- leetcode 292. Nim游戏(python)
你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函数,来判断 ...
- 初步学习JS中的闭包
JS高级程序设计(3rd)中对闭包的定义就是一句话,首先闭包是一个函数,怎样的函数呢?有权访问另一个函数作用域中的变量 的函数.而创建闭包的常见方式就是在一个函数的内部创建另一个函数,就是嵌套函数. ...
- mysql处理百万数据遍历速度提升(遍历图片名字是否存在)
CREATE DEFINER=`root`@`localhost` FUNCTION `fun_wcmappendix02`(image_name VARCHAR(50)) RETURNS int(1 ...
- String中的CompareTo
在API源码中,String的compareTo其实就是一次比较两个字符串的ASCII码.如果两个字符串的ASCII相等则继续后续比较,否则直接返回两个ASCII的差值.如果两个字符串完全一样,则返回 ...
- 【ABAP系列】SAP ABAP模块-ABAP动态指针写法的精髓部分
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP模块-ABAP动 ...
- python time 和日期相关模块
时间日期相关的模块 calendar 日历模块 time 时间模块 datetime 日期时间模块 timeit 时间检测模块 日历模块 calendar() 功能:获取指定年份的日历字符串 格式:c ...
- 面向JVM的应用程序的项目结构
对于Maven所用的项目结构,称为Maven标准的目录结构,不包含git 一.一个典型的源代码结构: / [project-name] README.txt LICENSE.txt pom.xml / ...
- [Python3] 021 面向对象 第一弹
目录 1. 面向对象概述 1.1 OOP 思想 1.2 几个名词 1.3 类与对象 2. 类的基本实现 2.1 类的命名 2.2 如何声明一个类 2.3 如何实例化一个类 2.4 如何访问对象成员 2 ...
- 04 volatile关键字实现原理
volatile关键字实现原理 1.volatile关键字的语义分析 作用:让其他线程能够马上感知到某个线程多某个变量的修改 保证可见性 对共享变量的修改,其他线程能够马上感知到 保证有序性 在重排序 ...
- Android APP 登陆模块
首先我想强调一点.这个登陆的模块最好是放在另外一个线程里面来实现.否则有可能会爆出一系列的问题, 然后再与主UI 交互.这样就不会爆ANR异常 1.对于登陆模块的.首先大体的逻辑肯定是要清晰的. ...