- pwd 查看当前所在位置
[root@localhost Desktop]# pwd
/root/Desktop
[root@localhost Desktop]# cd test
[root@localhost test]# pwd
/root/Desktop/test
[root@localhost test]#
>
2.touch
A.创建文本文件(文件之前不存在)
[root@localhost test]# ls
[root@localhost test]# touch file1 file2 #每次创建一个
[root@localhost test]# ls
file1 file2一次创建多个文件
[root@localhost test]# touch file{1..5}
[root@localhost test]# ll
total 0
-rw-r–r–. 1 root root 0 Mar 29 17:20 file1
-rw-r–r–. 1 root root 0 Mar 29 17:20 file2
-rw-r–r–. 1 root root 0 Mar 29 17:20 file3
-rw-r–r–. 1 root root 0 Mar 29 17:20 file4
-rw-r–r–. 1 root root 0 Mar 29 17:20 file5
[root@localhost test]#>
B. touch可以同步时间戳(文件之前就存在)
[root@localhost test]# touch file2
[root@localhost test]# ll
total 0
-rw-r–r–. 1 root root 0 Mar 29 17:18 file1
-rw-r–r–. 1 root root 0 Mar 29 17:18 file2
[root@localhost test]# touch file2
[root@localhost test]# ll
total 0
-rw-r–r–. 1 root root 0 Mar 29 17:18 file1
-rw-r–r–. 1 root root 0 Mar 29 17:19 file2
[root@localhost test]# touch file{1..5}
3.rm 删除文件或目录
-f 强制删除文件
-r 删除目录
rmdir 删除空目录A.删除文本文件 rm - f 文件名
[root@localhost test]# ls
file1 file2 file3 file4 file5
[root@localhost test]#
[root@localhost test]# rm -f file5
[root@localhost test]# ls
file1 file2 file3 file4
[root@localhost test]#>
B.删除目录 rm -rf 目录名
[root@localhost test]# ls
file1 file2 file3 file4 student
[root@localhost test]# rm -rf student/
[root@localhost test]# ls
file1 file2 file3 file4>
C. rmdir 删除空目录 rmdir 目录名
[root@localhost test]# ls
file1 file2 file3 file4 test
[root@localhost test]# ll test
total 0
[root@localhost test]# rmdir test/
[root@localhost test]# ls
file1 file2 file3 file4
[root@localhost test]#
4.mv
A.更改文件或目录的名称 mv 文件(目录)(old) 文件(目录)(new)
[root@localhost test]# ls
file1 file2 file3 file4
[root@localhost test]# mv file4 file6
[root@localhost test]# ls
file1 file2 file3 file6
[root@localhost test]# mkdir test
[root@localhost test]# ls
file1 file2 file3 file6 test
[root@localhost test]# mv test test3
[root@localhost test]# ls
file1 file2 file3 file6 test3
[root@localhost test]#>
B. mv * * 将前面所有文件和目录全部拷贝到最后一个目录(最后一个必须为目录)[root@localhost test]# ls
file1 file2 file3 file6 test3
[root@localhost test]# ls test3
[root@localhost test]# mkdir boy
[root@localhost test]# ls
boy file1 file2 file3 file6 test3
[root@localhost test]# mv * *
mv: cannot move ‘test3’ to a subdirectory of itself, ‘test3/test3’
mv: cannot stat ‘boy’: No such file or directory
mv: cannot stat ‘file1’: No such file or directory
mv: cannot stat ‘file2’: No such file or directory
mv: cannot stat ‘file3’: No such file or directory
mv: cannot stat ‘file6’: No such file or directory
[root@localhost test]# ls
test3
[root@localhost test]# ls test3/
boy file1 file2 file3 file6
[root@localhost test]#>
C. mv 文件/目录 文件/目录 将一个文件或目录移动至目标文件或目录[root@localhost test3]# ls
boy file1 file2 file3 file6
[root@localhost test3]# mv file1 file2
mv: overwrite ‘file2’?
[root@localhost test3]# ls
boy file1 file2 file3 file6
[root@localhost test3]# mv file1 ./boy/
[root@localhost test3]# ls boy/
file1
[root@localhost test3]#
>
5. cp 拷贝命令
拷贝文件或目录 (拷贝目录时要加-r参数)
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# cp file* ./new/ ## *可以替代任意字符
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# ls new/
file1 file2 file3 file4
[root@localhost test]#覆盖之前的内容 \cp
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# ls new/
file1 file2 file3 file4
[root@localhost test]# cp file3 ./new/
cp: overwrite ‘./new/file3’?
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# ls new
file1 file2 file3 file4
[root@localhost test]# \cp file3 ./new/
[root@localhost test]# ls new
file1 file2 file3 file4
[root@localhost test]#
6.file 查看文件的类型
常见文件类型如下:
ELF :二进制文件
ASCII:ASCII码文件
[root@localhost test]# file file3
file3: empty
[root@localhost test]# vim file4
[root@localhost test]# file file4
file4: ASCII text
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# cd new/
[root@localhost new]# ls
file1 file2 file3 file4
[root@localhost new]# cd ..
[root@localhost test]# file new/
new/: directory
[root@localhost test]#
7 stat 查看文件/目录状态
[root@localhost test]# stat file2
File: ‘file2’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 412607364 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-03-29 18:08:58.443205300 +0800
Modify: 2016-03-29 18:07:13.169249124 +0800
Change: 2016-03-29 18:07:13.169249124 +0800
Birth: -
[root@localhost test]# stat new/
File: ‘new/’
Size: 54 Blocks: 0 IO Block: 4096 directory
Device: fd00h/64768d Inode: 137530536 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-03-29 18:09:07.170367398 +0800
Modify: 2016-03-29 18:08:58.443205300 +0800
Change: 2016-03-29 18:08:58.443205300 +0800
Birth: -
[root@localhost test]#
8.cat 查看文件内容
[root@localhost test]# cat file4
jdfnhkjnglkfdnkfdmd
9.wc 统计文件信息
wc -l 文件名 :统计文件的行数
wc -c 文件名 : 统计文件的字节数
wc -w 文件名 : 统计文件的单词数(以空格作为区分)
wc -m 文件名 :统计文件的字符数
10 mkdir 创建目录
mkdir 目录名
[root@localhost test]# ls
file1 file2 file3 file4 new
[root@localhost test]# mkdir old
[root@localhost test]# ls
file1 file2 file3 file4 new old
[root@localhost test]#mkdir -p 目录1/目录2 递归创建目录(目录1之前不存在,加-p参数后就可递归创建)
[root@localhost test]# mkdir boy/girl
mkdir: cannot create directory ‘boy/girl’: No such file or directory
[root@localhost test]# mkdir -p boy/girl
[root@localhost test]# ls boy/
girl
[root@localhost test]#
11 ls 显示目录下的所有文件和目录
[root@localhost test]# ls
boy file1 file2 file3 file4 new old
[root@localhost test]#
12 cd 进入到一个目录下
[root@localhost test]# cd boy
[root@localhost boy]# ls
girl
[root@localhost boy]#