阮一峰的IT笔记:首页 -> 分类 -> Linux 查看所有文章:按分类 | 按月份

Linux的文件基本操作

一、新建和删除文件

1. 删除文件

rm /test1/file1

2. 新建目录

mkdir /linux

3. 删除目录

rmdir /linux

在执行此命令前,必须确定目录中没有任何文件,否则系统会提示出错。

4. 删除目录及目录下的所有文件。

rm -rf /linux

-r 为递归处理参数,也就是说它会使删除命令持续地执行下去,而-f 是指强制删除所有文件。

5. 创立链接文件

链接文件可以节省磁盘空间,修改链接文件,等于修改原文件。

ln -s /test/file test1/file.ln

-s表示创建的是符号链接。

二、复制和移动文件

1. 文件复制

cp /test1/file1 /test3/file2

如果要将dir1下的所有目录包括子目录都复制到dir2:

cp a dir1 dir2

参数a表示复制所有的目录。

2. 文件移动(重命名)

mv /test1/file1 /test2/file2

三、查看和创建文件

1. 查看文件内容

cat /test/file1.txt

创建文件:

cat > /test/file2.txt
文件内容+enter键
Ctrl+C结束

如果加上-b参数,就可以在每个非空行前加上编号。

多个文件合并显示:

cat /test/file1.txt /test/file2.txt

将多个文件合并为一个文件:

cat /test/file1.txt /test/file2.txt >/test/new.txt

2. 分页显示文件内容

more /etc/imrc

从第3行开始显示:

more +3 /etc/imrc

显示文件中第一个do字符串出现的页面及其以后的内容:

more +/do /etc/imrc

3. 交互式操作显示文件内容

less /etc/imrc

使用方向键控制上下左右,Q键离开浏览模式。


« Linux的文件类型 | 首页 | 压缩文件的生成及解压缩 »

About

This page contains a single entry from the blog posted on 2007年03月08日 01:21.

The previous post in this blog was Linux的文件类型.

The next post in this blog is 压缩文件的生成及解压缩.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33

Post a comment