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文件与目录管理的更多相关文章

  1. Linux 文件与目录管理

    Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...

  2. CentOS(九)--与Linux文件和目录管理相关的一些重要命令①

       接上一篇文章,实际生产过程中的目录管理一定要注意用户是root 还是其他用户. 一.目录与路径 1.相对路径与绝对路径 因为我们在Linux系统中,常常要涉及到目录的切换,所以我们必须要了解 & ...

  3. linux文件与目录管理笔记

    ### Linux文件与目录管理 ---------- 绝对路径: / 相对路径:不以/开头的 当前目录 . 上一个工作目录 - 用户主目录 ~ root账户的主目录是/root 其他用户是/home ...

  4. 【转】第七章、Linux 文件与目录管理

    原文网址:http://vbird.dic.ksu.edu.tw/linux_basic/0220filemanager.php 第七章.Linux 文件与目录管理 最近升级日期:2009/08/26 ...

  5. Linux 文件与目录管理,Linux系统用户组的管理

      一.Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什 ...

  6. 七、Linux 文件与目录管理

    Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...

  7. CentOS(十)--与Linux文件和目录管理相关的一些重要命令②

    在结束了第二期的广交会实习之后,又迎来了几天休闲的日子,继续学习Linux.在上一篇随笔 Linux学习之CentOS(十七)--与Linux文件和目录管理相关的一些重要命令① 中,详细记录了与Lin ...

  8. Linux文件与目录管理(一)

    一.Linux文件与目录管理 1.Linux的目录结构是树状结构,最顶级的目录是根目录/(用"/"表示) 2.Linux目录结构图: /bin:bin是Binary的缩写,这个目录 ...

  9. 第七章、Linux 文件与目录管理

    第七章.Linux 文件与目录管理   1. 目录与路径 1.1 相对路径与绝对路径 1.2 目录的相关操作: cd, pwd, mkdir, rmdir 1.3 关於运行档路径的变量: $PATH ...

  10. 2. Linux文件与目录管理

    一.目录与路径 1. 相对路径与绝对路径 绝对路径:路径写法[一定由根目录 / 写起],如:/usr/share/doc 相对路径:路径写法[不由 / 写起], /usr/share/doc 要到 / ...

随机推荐

  1. day28-Javascript定时器的应用案例

    转行学开发,代码100天——2018-04-13 上篇文章中记录了定时器的用法,本篇通过两个常用案例进一步巩固定时器的应用. 案例一:消息框延时,如QQ中鼠标移动到头像,弹出一个信息框:移出后,消息框 ...

  2. mysql-M-S-S模型 中继器 级联

    1.基础环境 三台虚机并且安装有mysql 并且同步好数据库 2.主服务器-创建账号并授权 mysql> create user 'mslave'@'X.X.X.X' identified by ...

  3. PHP继承及实现

    php学习已经有一段时间了,来对之前的知识积累做个记录. php实现单继承和多实现.单继承: 一个类只能有一个extends 抽象类 ,多实现 :一个类可以implements 多个接口 举个简单的栗 ...

  4. Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)

    传送门 Description Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In ...

  5. sourcetree for mac 使用

    1.sourceTree clone 仓库 打开sourceTree, 点击 新仓库(1) -> 从url克隆(2), 如下图 如下图所示, 粘贴源url路径, 自动补全或者手动选择目标路径和名 ...

  6. Web控件LinkButton

    <asp:LinkButton ID="" runat="server" ></asp:LinkButton> 编译后就变成了回发事件 ...

  7. 工作笔记:phpstrom、docker、phpunit进行单元测试

  8. python pip报错pip._ vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

    AttributeError: module 'pip' has no attribute 'main报错 找到安装目录下 helpers/packaging_tool.py文件,找到如下代码: de ...

  9. LOJ 2234/BZOJ 3629 聪明的燕姿(数论+DFS)

    题面 传送门 分析 看到约数之和,我们首先想到约数和公式 若$ x=\prod_{i=1}^{n}p_i^{k_i} \(,则x的约数和为\) \prod_{i=1}^{n} \sum_{j=0}^{ ...

  10. 浅谈随机数发生器(C语言)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/30971395 本文出自:点击打开链接 本来在做数据 ...