1. pwd - 打印当前工作目录

[root@VM_0_171_centos ~]# pwd
/root

2. cd - Change the shell working directory.

[root@VM_0_171_centos ~]# cd /usr/local

[root@VM_0_171_centos local]# cd .

[root@VM_0_171_centos local]# cd ..

[root@VM_0_171_centos usr]# cd -

/usr/local

[root@VM_0_171_centos local]# cd

[root@VM_0_171_centos ~]#

3. ls - list directory contents

SYNOPSIS

ls [OPTION]... [FILE]...

OPTIONS

-a, --all    do not ignore entries starting with .

-A, --almost-all    do not list implied . and ..

-d, --directory    list directories themselves, not their contents

-G, --no-group   in a long listing, don't print group names

-h, --human-readable     

with -l, print sizes in human readable format (e.g., 1K 234M 2G)

-i, --inode    print the index number of each file

--sort=WORD

sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v),extension (-X)

-l    use a long listing format

-m    fill width with a comma separated list of entries

-r, --reverse    reverse order while sorting

EXAMPLES

[root@VM_0_171_centos ~]# ls -l /etc/yum.repos.d/
总用量 8
-rw-r--r-- 1 root root 1410 3月 16 20:18 CentOS-Base.repo
-rw-r--r-- 1 root root 220 3月 16 20:18 CentOS-Epel.repo
[root@VM_0_171_centos ~]# ls -la /etc/yum.repos.d/
总用量 16
drwxr-xr-x. 2 root root 4096 3月 16 20:18 .
drwxr-xr-x. 90 root root 4096 4月 4 23:32 ..
-rw-r--r-- 1 root root 1410 3月 16 20:18 CentOS-Base.repo
-rw-r--r-- 1 root root 220 3月 16 20:18 CentOS-Epel.repo
[root@VM_0_171_centos ~]# ls -lr /etc/yum.repos.d/
总用量 8
-rw-r--r-- 1 root root 220 3月 16 20:18 CentOS-Epel.repo
-rw-r--r-- 1 root root 1410 3月 16 20:18 CentOS-Base.repo
[root@VM_0_171_centos ~]# ls -i /etc/yum.repos.d/
458776 CentOS-Base.repo 458777 CentOS-Epel.repo
[root@VM_0_171_centos ~]#

4. stat - display file or file system status

5. touch - change file timestamps

SYNOPSIS

touch [OPTION]... FILE...

特殊用法:不加选项时,则创建文件

OPTIONS

-a    change only the access time 

-c, --no-create    do not create any files(指定的文件路径不存在时不予创建)

-d, --date=STRING    parse STRING and use it instead of current time(如果加了时间字符串则不使用当前时间)

-h, --no-dereference    只作用于软链接而非链接文件

-m    change only the modification time

-r, --reference=FILE    use this file's times instead of current time

-t STAMP    use [[CC]YY]MMDDhhmm[.ss] instead of current time(如果加了时间戳则不使用当前时间)

EXAMPLES

6. mkdir - make directories

SYNOPSIS

mkdir [OPTION]... DIRECTORY...

OPTIONS

-m, --mode=MODE    set file mode (as in chmod), not a=rwx - umask

-p, --parents     no error if existing, make parent directories as needed

-v, --verbose    print a message for each created directory

-Z    set SELinux security context of each created directory to the default type

EXAMPLES

7. mv - move (rename) files

移动文件或者重命名文件(在同一目录下移动即重命名)

  • 1.mv 文件 文件|目录

  • 2.mv 多个文件 目录(移动到目标目录下)

  • 3.mv 目录 目录(移动到目标目录下)

SYNOPSIS

mv [OPTION]... [-T] SOURCE DEST

mv [OPTION]... SOURCE... DIRECTORY

mv [OPTION]... -t DIRECTORY SOURCE...

OPTIONS

-f, --force    do not prompt before overwriting

-i, --interactive    prompt before overwrite

-n, --no-clobber    do not overwrite an existing file

If you specify more than one of -i, -f, -n, only the final one takes effect.

--strip-trailing-slashes  remove any trailing slashes from each SOURCE argument

-S, --suffix=SUFFIX    override the usual backup suffix

-t, --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY

-T, --no-target-directory    treat DEST as a normal file

-v, --verbose  explain what is being done

-Z, --context  set SELinux security context of destination file to default type

EXAMPLES

当前目录下有2个字目录mydir1,mydir2,mydir1中有a,b,c三个文件,mydir2中有d,e,f三个文件:

1.将mydir1/a移动至mydir2,文件名改为aa

2.将mydir2/aa移动至mydir1

3.将mydir1下的所有文件移动至mydir2

4.将mydir2及其下的所有文件移动至mydir1

[root@VM_0_171_centos ~]# tree
.
├── anaconda-ks.cfg
├── mydir1
│ ├── a
│ ├── b
│ └── c
└── mydir2
├── d
├── e
└── f
2 directories, 7 files
[root@VM_0_171_centos ~]# mv mydir1/a mydir2/aa
[root@VM_0_171_centos ~]# tree
.
├── anaconda-ks.cfg
├── mydir1
│ ├── b
│ └── c
└── mydir2
├── aa
├── d
├── e
└── f
2 directories, 7 files
[root@VM_0_171_centos ~]# mv mydir2/aa mydir1
[root@VM_0_171_centos ~]# tree
.
├── anaconda-ks.cfg
├── mydir1
│ ├── aa
│ ├── b
│ └── c
└── mydir2
├── d
├── e
└── f
2 directories, 7 files
[root@VM_0_171_centos ~]# mv mydir1/* mydir2
[root@VM_0_171_centos ~]# tree
.
├── anaconda-ks.cfg
├── mydir1
└── mydir2
├── aa
├── b
├── c
├── d
├── e
└── f
2 directories, 7 files
[root@VM_0_171_centos ~]# mv mydir2 mydir1
[root@VM_0_171_centos ~]# tree
.
├── anaconda-ks.cfg
└── mydir1
└── mydir2
├── aa
├── b
├── c
├── d
├── e
└── f
2 directories, 7 files
[root@VM_0_171_centos ~]#

8. cp - copy files and directories

SYNOPSIS

cp [OPTION]... [-T] SOURCE DEST

cp [OPTION]... SOURCE... DIRECTORY

cp [OPTION]... -t DIRECTORY SOURCE...

OPTIONS

-a, --archive    same as -dR --preserve=all

--copy-contents    copy contents of special files when recursive

-d    same as --no-dereference --preserve=links

-f, --force    if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)

-i, --interactive    prompt before overwrite (overrides a previous -n option)

-H    follow command-line symbolic links in SOURCE

-l, --link    hard link files instead of copying

-L, --dereference    always follow symbolic links in SOURCE

-n, --no-clobber    do not overwrite an existing file (overrides a previous -i option)

-P, --no-dereference    never follow symbolic links in SOURCE

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

-c    deprecated, same as --preserve=context

--no-preserve=ATTR_LIST    don't preserve the specified attributes

--parents    use full source file name under DIRECTORY

-R, -r, --recursive    copy directories recursively

--sparse=WHEN     control creation of sparse files. See below

--strip-trailing-slashes    

remove any trailing slashes from each SOURCE argument

-s, --symbolic-link    make symbolic links instead of copying

-S, --suffix=SUFFIX    override the usual backup suffix

-t, --target-directory=DIRECTORY  

copy all SOURCE arguments into DIRECTORY

-T, --no-target-directory     treat DEST as a normal file

-u, --update

copy only when the SOURCE file is newer than the destination file or when the destination file is missing

-v, --verbose    explain what is being done

-x, --one-file-system    stay on this file system

-Z    set SELinux security context of destination file to default type

EXAMPLES

用法与mv类似

9. rm - remove files or directories

删除文件或目录

SYNOPSIS

rm [OPTION]... FILE...

OPTIONS

-f, --force    ignore nonexistent files and arguments, 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(递归)

EXAMPLES

rm -rf 文件或目录(习惯用法)

10. file - determine file type

识别文件类型,辨别文件编码格式。

它通过查看文件的头部信息获取文件类型,而不是像windows通过扩展名来确定文件类型,linux中文件名的后缀只是辅助识别文件类型(规范),并不能真正决定文件的类型。

EXAMPLES

[root@VM_0_171_centos ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text

Linux-目录与文件的更多相关文章

  1. linux 目录下文件批量植入和删除,按日期打包

    linux目录下文件批量植入 [root@greymouster http2]# find /usr/local/http2/htdocs/ -type f|xargs sed -i "   ...

  2. Linux目录和文件——查询目录和文件的命令

    Linux目录和文件——查询目录和文件的命令 摘要:本文主要学习了在Linux系统中是如何查询目录和文件的. which命令 which命令是根据PATH环境变量设置的路径,去搜索执行文件. 基本语法 ...

  3. Linux目录和文件——管理目录和文件的命令

    Linux目录和文件——管理目录和文件的命令 摘要:本文主要学习了Linux系统中关于目录和文件的操作. cd命令 cd命令用来切换工作目录,是Change Directory的缩写. 基本语法 cd ...

  4. Linux目录和文件——目录格式

    Linux目录和文件——目录格式 摘要:本文主要了解了Linux系统的目录格式. 一切皆文件 Linux下“一切皆文件”是Unix/Linux的基本哲学之一. Linux中所有内容都是以文件的形式保存 ...

  5. Linux 目录与文件的基本操作

    1 目录与文件 1.1 文件 硬盘中的数据在操作系统中的体现为文件. 1.2 目录 目录的概念不是文件集合.目录和文件一样,目录也是文件.目录是找到文件的“踏板”.目录的本质是路径映射. 1.3 Li ...

  6. Linux目录与文件的权限

    零.Linux中的权限为什么重要? 权限直接关系数据安全! 一.用户基础概念: 所有者(owner):拥有这个文件的用户.一般拥有目录或文件的所有权限. 用户组(group):几个用户组成一个用户组, ...

  7. linux目录与文件权限的意义

    现在我们已经知道了Linux系统内文件的三种身份(所有者,用户者,与其他人),知道每种身份都有三种属性(r,w,x),已经能够使用chown,chgrp,chmod去修改这些权限和属性,那么这些文件权 ...

  8. linux 目录与文件命令

    目录与文件常用命令 1.cd命令 cd [相对路径或绝对路径或特殊符号] 功用:变换目录 ps: 不加参数时,默认切换到用户主目录,即环境变量HOME指定的目录,如root用户的HOME变量为/roo ...

  9. Linux 目录和文件操作

    Linux常用命令--目录和文件操作 [目录]删除.复制.移动 : 1.删除文件夹用:rmdir 文件夹名 但是rmdir不能删除非空的文件夹,那如何删除非空文件夹呢: 2.通常情况下,删除文件用:r ...

  10. Linux 目录和文件的操作

    整理常用的linux命令,关于目录和文件的操作,用于巩固记忆,以备不时之需. [root@localhost ~] root:当前用户 localhost:主机名 ~:当前所在位置 符号#:管理员 符 ...

随机推荐

  1. [RF] 安装好Robot Framework之后怎样让启动的界面后面不带命令行窗口,且图片以机器人显示

    安装好Robot Framework之后,通过 C:\Python27\Scripts\ride.py 启动时会带上一个命令行窗口: 怎样让启动的界面后面不带这个命令行窗口,且图片以机器人显示? 方法 ...

  2. 20155312 2016-2017-2 《Java程序设计》第九周学习总结

    20155312 2016-2017-2 <Java程序设计>第九周学习总结 课堂内容总结 两个类有公用的东西放在父类里. 面向对象的三要素 封装 继承 多态:用父类声明引用,子类生成对象 ...

  3. 821. Shortest Distance to a Character

    class Solution { public: vector<int> shortestToChar(string S, char C) { int len=S.length(); ve ...

  4. 2018.11.01 NOIP训练 递增数列(迭代加深)

    传送门 直接迭代加深搜索. 发现每次最多增加一倍,最少增加一,于是果断上下界剪枝. 代码

  5. mysql下载、安装

    一.下载 网上下载地址五花八门,为了防止出现不必要的麻烦,建议直接从官网下载.有几点好处: 1.没有任何其他捆绑的软件 2.版本分布清晰,一般建议选择较新版本    mysql官网下载地址:https ...

  6. dj 模型层orm-1

    ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发人员的 ...

  7. CentOS7 安装可视化脚本安装包Webmin

    一.简介 Webmin是一个基于Web的Linux系统管理界面.你就可以通过图形化的方式设置用户账号.Apache.DNS.文件共享等服务. 二.安装 1.下载安装包到本地Windows系统 http ...

  8. oracle如何快速导入导出文本格式数据

    导出工具:sqluldr2工具说明:sqluldr2再以安装oracle客户端的环境下下无需再安装其它软件,只需将对应的软件包拷贝至对应目录,即可运行导出数据导出示例:--linux环境导出示例:/d ...

  9. 分区表主键不包含分区键报错ERROR 1105 (HY000)

    ERROR 1105 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function MySQ ...

  10. AngularJS实战之cookie的读取

    <!DOCTYPE html> <html ng-controller="cookies_controller"> <head> <tit ...