Manipulating Files
http://linuxcommand.org/lc3_lts0050.php
This lesson will introduce you to the following commands:
These four commands are among the most frequently used Linux commands. They are the basic commands for manipulating both files and directories. Now, to be frank, some of the tasks performed by these commands are more easily done with a graphical file manager. With a file manager, you can drag and drop a file from one directory to another, cut and paste files, delete files, etc. So why use these old command line programs? The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file manager, complicated tasks can be easier with the command line programs. For example, how would you copy all the HTML files from one directory to another, but only copy files that did not exist in the destination directory or were newer than the versions in the destination directory? Pretty hard with with a file manager. Pretty easy with the command line: [me@linuxbox me]$ cp -u *.html destination WildcardsBefore I begin with our commands, I want to talk about a shell feature that makes these commands so powerful. Since the shell uses filenames so much, it provides special characters to help you rapidly specify groups of filenames. These special characters are called wildcards. Wildcards allow you to select filenames based on patterns of characters. The table below lists the wildcards and what they select:
Using wildcards, it is possible to construct very sophisticated selection criteria for filenames. Here are some examples of patterns and what they match:
You can use wildcards with any command that accepts filename arguments. cpThe cp program copies files and directories. In its simplest form, it copies a single file: [me@linuxbox me]$ cp file1 file2 It can also be used to copy multiple files (and/or directories) to a different directory: [me@linuxbox me]$ cp file... directory A note on notation: ... signifies that an item can be repeated one or more times. Other useful examples of cp and its options include:
mvThe mv command moves or renames files and directories depending on how it is used. It will either move one or more files to a different directory, or it will rename a file or directory. To rename a file, it is used like this: [me@linuxbox me]$ mv filename1 filename2 To move files (and/or directories) to a different directory: [me@linuxbox me]$ mv file... directory Examples of mv and its options include:
rmThe rm command removes (deletes) files and directories. [me@linuxbox me]$ rm file... It can also be used to delete directories: [me@linuxbox me]$ rm -r directory... Examples of rm and its options include:
Be careful with rm!Linux does not have an undelete command. Once you delete something with rm, it's gone. You can inflict terrific damage on your system with rm if you are not careful, particularly with wildcards. Before you use rm with wildcards, try this helpful trick: construct your command using ls instead. By doing this, you can see the effect of your wildcards before you delete files. After you have tested your command with ls, recall the command with the up-arrow key and then substitute rm for ls in the command. mkdirThe mkdir command is used to create directories. To use it, you simply type: [me@linuxbox me]$ mkdir directory... Using Commands With WildcardsSince the commands we have covered here accept multiple file and directories names as arguments, you can use wildcards to specify them. Here are a few examples:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
© 2000-2015, William E. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved. Linux® is a registered trademark of Linus Torvalds. |
Manipulating Files的更多相关文章
- Java NIO Files
Java NIO Files Files.exists() Files.createDirectory() Files.copy() Overwriting Existing Files Files. ...
- Vault 不同版本的API的异同
大家知道,Autodesk Vault 2014有几个版本,依次为( Basic, Workgroup, Professional),不同版本的功能不相同,关于Vault产品功能的不同之处可以在Vau ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Java fundamentals of basic IO
IO is a problem difficult to handle in various of systems because it always becomes a bottleneck in ...
- RFC-TCP
RFC: 793 TRANSMISSION CONTROL PROTOCOL DARPA INTERNET PROGRAM PROTOCOL SPECIFICATION September 1981 ...
- QtCore Module's Classes
Qt Core C++ Classes Provides core non-GUI functionality. More... Reference These are links to the AP ...
- SHFileOperation的用法
//删除文件或者文件夹bool DeleteFile(char * lpszPath){SHFILEOPSTRUCT FileOp={0};FileOp.fFlags = FOF_ALLOWUNDO ...
- SVN Client API的.net 接口 SharpSvn介紹 Checkout操作实例
Subversion是一個文件版本管理工具, 廣泛的被大家採用來作為源代碼版本管理. 已有的工具不管是其自帶的命令行工具還是Windows UI的tortoiseSVN等還是很方便實用的, 但是如果想 ...
- 深入代码详谈irqbalance【转】
转自:http://blog.csdn.net/whrszzc/article/details/50533866 版权声明:本文为博主原创文章,未经博主允许不得转载. 深入代码详谈irqbalance ...
随机推荐
- POJ 1015 Jury Compromise (动态规划)
dp[i][j]代表选了i个人,D(J)-P(J)的值为j的状态下,D(J)+P(J)的最大和. #include <cstdio> #include <cstring> #i ...
- JavaSE复习(四)File类与IO流
File类 构造方法 public File(String pathname) :通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例. public File(String parent ...
- lock关键字的使用
最近在代码中,发现别人使用了lock关键字,为了理解别人写的代码,所以自己对lock关键字的使用研究了下. 微软官方解释,请百度:lock 语句(C# 参考) 微软给了个官网实例代码: class A ...
- video on web
一.video容器 你可能经常看到.avi或.mp4的视频文件,实际上avi或者mp4只是一种视频容器.打个比方,ZIP的压缩文件可以包含各种各样的文件,同理,视频容器也定义用来怎么存放各种 ...
- poj1789 Truck History最小生成树
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- postman工具中如何提取接口的返回值
提取接口返回值 当返回值是返回JSON时 1.let json = JSON.parse(responseBody); // responseBody是包含整个返回内容的字符串 提取某字段的值: ...
- WCF 动态调用(动态创建实例接口)
很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...
- WebSocket简单介绍(1)
HTML5作为下一代WEB标准,拥有许多引人注目的新特性,如Canvas.本地存储.多媒体编程接口.WebSocket等等.今天我们就来看看具有“Web TCP”之称的WebSocket. WebSo ...
- P4016 负载平衡问题
题目描述 G 公司有 n 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 n个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. 输入输出格式 输入格式: 文 ...
- 【题解】CQOI2017老C的键盘
建议大家还是不要阅读此文了,因为我觉得这题我的解法实在是又不高效又不优美……只是想要记录一下,毕竟是除了中国象棋之外自己做出的组合dp第一题~ 首先如果做题做得多,比较熟练的话,应该能一眼看出这题所给 ...