- 文件名称大小写敏感
- 名称最多可以有255个字符
- 除了正斜线'/'外,都是有效字符
一、目录相关命令
- 目录占用一个 Block ,一个 Block 大小为 4K。(即目录大小为 4K)
- Block 存储这个目录下的文件的元数据:权限、修改时间等。
pwd Print name of current Working Directory
-L --logical use PWD from evironment, even if it contains symlinks
-P --phusical avoid all symlinks
mkdir Make Directory
-p 完整地常见一个子目录结构
mv Move 可以在移动文件的同时进行重命名
$ mv src dest (src=source; dest= destination)
-f --force do not prompt before overwriting
-i --interactive prompt before overwrite
-b (backup) 移动文件时在文件名后加一个‘~’,从而避免文件被覆盖
rmdir Remove Directory(just empty directory can be removed)
rm Remove
-i
-f --force
-d --dir remove empty directories
-r -R --Recursive remove directories and their contents recursively
cp Copy
$ cp src dest
-i
-b
-r
-p --preserve preserve the specified attributes(default: mode,ownership,timestamps)
cd Change Directory
. 当前目录
.. 上一层目录
- 前一个工作目录
~ 当前用户家目录
二、文件相关命令
ls List directory contents
-a --all do not ignore entries starting with .
-d --directory list directories themselves, not their contents
-F --classify append indicator ot entries
```
目录 / 蓝色
普通文件 黑色
可执行文件 * 草绿色
链接文件 @ 淡蓝色
```
-h --human with -l or -s, print sizes like 1K 234M 2G etc.
-l use a long listing format to show more info
```
权限标志 链接个数 user group size 最后一次修改的日期和时间 文件名
drwxr-xr-x 2 alex alex 4096 2月 11 19:36 Downloads
当对象是目录时:如果不在目录后加'/',则查看目录本身的属性
如果加'/',则查看目录中包含的各文件的属性
```
-R --recursive list subdirectories recursively
-t sort by modification time, newest first
cat conCATenate files and print on the stantard output
-n --number number all output lines
head output the first part of file
-n --lines print the first NUM lines instead of the first 10
tail output the last part of file
-n
-f --follow output appended data as the file grows(一般用于查看日志,持续显示新添加的内容,没有则不输出。需要手动结束命令)
more 一页一页显示文件内容,阅读至文件末尾自动结束(只能向下翻页)
空格键:向下翻动一页;
Enter键:向下滚动一行;
Q键: 退出
less commands are based on both more and vi.
空格键: next page
B: previous page
/: find some contents matched RE
Q: Quit
file determine file type
echo display a line of text(output '\n' by default)
-n do not output the trailing newline
-e enable interpretation of backslash excapes
-E disable interpretation of backslash escapes(default)
touch change file timestamps, if specified FILE isn't exist ,then creat empty FILE
-a change only the access time
-d --date parse DATE and use it instead of current time
-m change only the modification time
-t use [[CC]YY]MMDDhhmm[.ss] instead of current time
三、文本处理
3.1 基于行处理文本
grep Globally search a Regular Expression and Print(搜索符合条件的字符串并打印)
grep RE FILE
-i --ignore-case Ignore case distinctions, so that characters that differ only in case match each other(忽略大小写)
-v --invert-match Invert the sense of matching, to select non-matching lines(排除包含指定字符串的行)
-n --line-number Prefix each line of output with the 1-based line number within its input file
-Ax 在输出的时候包含结果所在行之后的指定行数N
-Bx 在输出的时候包含结果所在行之前的指定行数N
```
通配符
? The preceding item is optional and matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
{n} The preceding item is matched exactly n times.
{n,} The preceding item is matched n or more times.
{,m} The preceding item is matched at most m times. This is a GNU extension.
{n,m} The preceding item is matched at least n times, but not more than m times.
echo D* 输出当前目录下以D开头的文件
```
3.2 基于列处理文本
cut
$cut -d: -f3 /etc/passwd
$cut 2-6 /etc/passwd
-d 指定分隔符(默认是 TAB)
-f 指定输出的列号
-c 基于字符进行切割
3.3 文本统计
wc
-i 只统计行数
-w 只统计单词
-c 只统计字节数
-m 只统计字符数
3.4 文本排序
sort
-r 进行倒序排序
-n 基于数字进行排序
-f 忽略大小写
-u 删除重复行
-t c 使用 c 作为分隔为列进行排序
-k x 当进行基于字符分割为列的排序时,指定基于哪个列排序
uniq report or omit repeated lines(删除重复的相邻行)
3.5 文本比较 diff
diff compare files line by line
$ diff -u FILE NewFILE > final.patch
-q --brief report only when files differ
-s --report-identical-files report when two files are the same
-i --interactive-case
-b 忽略空格数量的改变
-u 统一显示比较信息(一般用以生成 .patch 文件)
3.6 处理文本内容
tr -d"TMD" < FILE # 删除关键字 “TMD”
tr 'a-z''A-Z' < FILE # 转换大小写
sed 搜索替换文本
$ sed 's/linux/unix/g' FILE
$ sed '1,50s/linux/unix/g' FILE
$ sed -e 's/linux/unix/g' -e 's/nash/nash_su/g' FILE
$ sed -f sededit FILE