Wildcards
Wildcard Meaning
* Matches any characters
? Matches any single character
[characters] Matches any character that is a member of the set characters
[!characters] Matches any character that is not a member of the set characters
[[:class:]] Matches any character that is a member of the specified class
Commonly Used Character Classes
Character Class Meaning
[:alnum:] Matches any alphanumeric character
[:alpha:] Matches any alphabetic character
[:digit:] Matches any numeral
[:lower:] Matches any lowercase letter
[:upper:] Matches any uppercase letter
Wildcard Examples
Pattern Matches
* All files
g* All file beginning with "g"
b*.txt Any file beginning with "b" followed by any characters and ending with ".txt"
Data??? Any file beginning with "Data" followed by exactly three characters
[abc]* Any file beginning with either an "a", a "b", or a "c"
BACKUP.[0-9][0-9][0-9] Any file beginning with "BACKUP." followed by exactly three numerals
[[:upper:]]* Any file beginning with an uppercase letter
[![:digit:]]* Any file not beginning with a numeral
*[[:lower:]123] Any file ending with a lowercase letter or the numerals "1", "2", or "3"

cp-Copy files and directories

cp Options
Option Meaning
-a, --archive Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy
-i, --interactive Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, cp will silently overwrite files.
-r, --recursive Recursively copy directories and their contents. This option (or the -a option) is required when copying directories.
-u, --update When copying files from one directory to another, only copy files that either don't exist, or are newer than the existing corresponding files, in the destination directory.
-v, --verbose Display informative messages as the copy is performed.
cp Examples
Command Results
cp file1 file2 Copy file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created.
cp -i file1 file2 Same as above, except that if file2 exists, the user is prompted before it is overwritten.
cp file1 file2 dir1 Copy file1 and file2 into directory dir1. dir1 must already exist.
cp dir1/* dir2 Using a wildcard, all the files in dir1 are copied into dir2. dir2 must already exist.
cp -r dir1 dir2 Copy the contents of directory dir1 to directory dir2. If directory dir2 does not exist, it is created and, after the copy, will contain the same contents as directory dir1. If directory dir2 does exist, then directory dir1 (and its contents) will be copied into dir2.

mv-Move/rename files and directories

mv options
Option Meaning
-i --interactive Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv command will silently overwrite files
-u --update When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory.
-v --verbose Display informative messages as the move is performed.
mv Examples
mv file1 file2 Move file1 to file2. If file2 exists, it is overwritten with the contents of files. If file2 does not exist, it is created. In either case, file1 ceases to exist.
mv -i file1 file2 Same as above, except that if file2 exists, the user is prompted before it is overwritten.
mv file1 file2 dir1 Move file1 and file2 into dirctory dir1. dir1 must already exist.
mv dir1 dir2 if directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2 and delete directory dir1. if directory dir2 does exist, move directory dir1 (and its contents) into directory dir2.

mkdir-Create directories

rm Options
Option Meaning
-i, --interactive Before deleting an existing file, prompt the user for confirmation. If this option is not specified, rm will silently delete files.
-r, --recursive Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified.
-f, --force Ignore nonexistent files and do not prompt. This overrides the --interactive option.
-v, --verbose Display informative messages as the deletion is performed.
rm Examples
Command Results
rm file1 Delete file1 silently
rm -i file1 Same as above, except that the user is prompted for confirmation before the deletion is performed.
rm -r file1 dir1 Delete file1 and dir1 and its contents.
rm -rf file1 dir1 Same as above, except that if either file1 or dir1 do not exist, rm will continue silently.

rm-Remove files and directories

ln-Create hard and symbolic links

Chap5:操作文件和目录[The Linux Command Line]的更多相关文章

  1. (三)linux 学习 --操作文件和目录

    The Linux Command Line 读书笔记 - 部分内容来自 http://billie66.github.io/TLCL/book/chap05.html 文章目录 通配符 字符范围 ` ...

  2. 【Python】[IO编程]文件读写,StringIO和BytesIO,操作文件和目录,序列化

    IO在计算机中指Input/Output,也就是输入和输出. 1.文件读写,1,读文件[使用Python内置函数,open,传入文件名标示符] >>> f = open('/User ...

  3. Python之IO编程——文件读写、StringIO/BytesIO、操作文件和目录、序列化

    IO编程 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口.从 ...

  4. IO编程(2)-操作文件和目录

    操作文件和目录 如果我们要操作文件.目录,可以在命令行下面输入操作系统提供的各种命令来完成.比如dir.cp等命令. 如果要在Python程序中执行这些目录和文件的操作怎么办?其实操作系统提供的命令只 ...

  5. Python学习笔记(二十五)操作文件和目录

    摘抄:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014319253241 ...

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

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

  7. os,操作文件和目录

    如果我们要操作文件.目录,可以在命令行下面输入操作系统提供的各种命令来完成.比如dir.cp等命令. 如果要在Python程序中执行这些目录和文件的操作怎么办?其实操作系统提供的命令只是简单地调用了操 ...

  8. python学习笔记 操作文件和目录

    如果我们要操作文件.目录,可以在命令行下面输入操作系统提供的各种命令来完成.比如dir.cp等命令. 如果要在Python程序中执行这些目录和文件的操作怎么办?其实操作系统提供的命令只是简单地调用了操 ...

  9. IO编程、操作文件或目录、序列化、JSON

    IO中指Input/Output,即输入和输出:涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口 1.由于CPU和内存的速度远远高于外设的速度,所以,在IO编程中,存在速度严重不匹配问题.eg ...

随机推荐

  1. Basic SAP Data Types

    Basic SAP Data Types 6 out of 11 rated this helpful - Rate this topic The parameter types that the M ...

  2. pandas删除缺失数据(pd.dropna()方法)

    1.创建带有缺失值的数据库:   import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(5, 3), ind ...

  3. 【iCore1S 双核心板_ARM】例程十三:SDIO实验——读取SD卡信息

    实验现象: 核心代码: int main(void) { /* USER CODE BEGIN 1 */ HAL_SD_TransferStateTypedef State; /* USER CODE ...

  4. java.lang.String.regionMatches方法使用

    regionMatches(boolean ignoreCase,int toffset,String other,int ooffset,int len): regionMatches(int to ...

  5. SQL-----------------------之ON和WHERE的区别

    SQL中ON和WHERE的区别 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户.在使用left jion时,on和where条件的区别如下:1. on ...

  6. Make ProgressBar Vertical

    Create a drawable in your Drawable folder called vertical_progress_bar.xml: <?xml version="1 ...

  7. 一台PC双网卡,一个外网一个内网

    问题:一台PC双网卡,一个连外网一个连内网.用户主要访问外网,内网只访问有限的几个ip.因为外网很大,一般人公司内网常访问的ip是有限的几个. 现在如何做到在上外网的同时也能访问内网的系统?明明两个网 ...

  8. [PHP] 01 - Hypertext Preprocessor

    超级文本预处理语言:http://php.net/ 集成的服务器组件,它已经包含了 PHP.Apache.Mysql 等服务 PHP 7 https://www.tutorialspoint. com ...

  9. [JS] Topic - why "strict mode" here

    Ref: Javascript 严格模式详解 使得Javascript在更严格的条件下运行: - 消除Javascript语法的一些不合理.不严谨之处,减少一些怪异行为; - 消除代码运行的一些不安全 ...

  10. 《objective-c基础教程》学习笔记 (一)—— 开发环境配置和简单类型输出

    懒惰是富有最大的敌人,再不前进,我们就out了.最近工作比较轻松,不是很忙.于是想晚上下班回家学习点新东西.看着苹果大军的一天天壮大,心里也是痒痒的.于是就想先系统的学习下Objective-C,为之 ...