touch命令用于创建空白文件或设置文件的时间,语法格式为:“touch [参数] 文件名称
[root@localhost mnt]# ls
[root@localhost mnt]# touch bing
[root@localhost mnt]# ls
bing
# vim linux 使用vim编辑一个不存在的文件,修改保存后,该会自动建立
[root@localhost mnt]# vim linux
[root@localhost mnt]# ls
bing linux
--------------------------------------------------------------------------------------------------------------
mkdir命令用于创建空白的目录,英文全称为:“make directory”,语法格式为:“mkdir [参数] 目录名称”
[root@localhost mnt]# mkdir linux-b
[root@localhost mnt]# ls
bing linux linux-b
mkdir -p /mnt/linux-c/bing/geely/7dct 创建递增层次的文件
[root@localhost mnt]# mkdir -p /mnt/linux-c/bing/geely/7dct
[root@localhost mnt]# ls
bing linux linux-b linux-c
[root@localhost mnt]# cd /mnt/linux-c/bing/geely/7dct
[root@localhost 7dct]# pwd
/mnt/linux-c/bing/geely/7dct
--------------------------------------------------------------------------------
cp命令用于复制文件或目录,英文全称为:“copy”,语法格式为:“cp [参数] 源文件名称 目标文件名称”
语法: cp 源… 目的
复制目录时,多个-r 选项:
# cp -r newdir/ /tmp/ 目标目录存在,则将源目录放在该目录下
# cp -r newdir /tmp/olddir 目标目录不存在,类似复制过去后重命名
# cp -r /run/media/admin/RHEL-7.0Server.x86_64/. /mnt/redhat7/ 复制/run/media/admin/RHEL-7.0Server.x86_64/下所有文件到/mnt/redhat7/下
[root@localhost mnt]# ls
bing linux linux-b linux-c
[root@localhost mnt]# cp bing bing1
[root@localhost mnt]# ls
bing bing1 linux linux-b linux-c
[root@localhost mnt]# cp -r linux-b /mnt/linux-c
[root@localhost mnt]# cd linux-c
[root@localhost linux-c]# ls
bing linux-b
--------------------------------------------------------------------------------
mv命令用于剪切或重命名文件,英文全称为:“move”,语法格式为:“mv [参数] 源文件名称 目标文件名称”
[root@localhost mnt]# ls
bing bing1 linux linux-b linux-c
[root@localhost mnt]# mv bing1 bing2
[root@localhost mnt]# ls
bing bing2 linux linux-b linux-c
[root@localhost mnt]# mv bing2 /mnt/linux-b
[root@localhost mnt]# cd linux-b
[root@localhost linux-b]# ls
bing2
--------------------------------------------------------------------------------
rm命令用于删除文件或目录,英文全称为:“remove”,语法格式为:“rm [参数] 文件名称”
rm -f 强制删除文件
rm -rf 强制删除目录文件
[root@localhost mnt]# rm linux
rm: remove regular file 'linux'? y
[root@localhost mnt]# ls
bing linux-b linux-c
[root@localhost mnt]# rm -f bing
[root@localhost mnt]# ls
linux-b linux-c
[root@localhost mnt]# rm -rf linux-b
[root@localhost mnt]# ls
linux-c
--------------------------------------------------------------------------------
dd命令用于按照指定大小的数据块个数来复制文件或转换文件
if input file 输入文件
of output file 输出文件
bs 设置每个“块”的大小
count 设置要复制“块”的个数
语法格式为:“dd if=参数值 of=参数值 count=参数值 bs=参数值”
--------------------------------------------------------------------------------
file命令用于查看文件的类型,语法格式为:“file 文件名称”
[root@localhost mnt]# file linux-c/
linux-c/: directory
--------------------------------------------------------------------------------
(考试命令tar)
tar命令用于对文件进行打包压缩或解压,语法格式为:“tar 参数 文件名称
[root@localhost mnt]# tar czvf etc.tar.gz /etc
[root@localhost mnt]# ls
etc.tar.gz linux-c
z ---tar.gz
j ---tar.bz2
tar czvf 压缩包.tar.gz
tar xjvf 压缩包.tar.bz2
参数 作用
-c 创建压缩文件
-x 解开压缩文件
-t 查看压缩包内有哪些文件
-z 用Gzip压缩或解压
-j 用bzip2压缩或解压
-v 显示压缩或解压的过程
-f 目标文件名
-p 保留原始的权限与属性
-P 使用绝对路径来压缩
-C 指定解压到的目录
--------------------------------------------------------------------------------
grep命令用于在文本中执行关键词搜索,并显示匹配的结果,格式为“grep [选项] [文件]”
[root@localhost mnt]# grep /sbin/nologin /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
........
[root@localhost mnt]# grep -c /sbin/nologin /etc/passwd
48
参数 作用
-b 将可执行文件(binary)当作文本文件(text)来搜索
-c 仅显示找到的行数
-i 忽略大小写
-n 显示行号
-v 反向选择——仅列出没有“关键词”的行。
--------------------------------------------------------------------------------
find命令用于按照指定条件来查找文件,格式为“find [查找路径] 寻找条件 操作”
[root@localhost mnt]# find /etc -name "host*" -print
/etc/opa/hosts
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/avahi/hosts
/etc/hostname
---------------------------------------------------
重定向符(<、<<、>、>>) 命令与文件的关系
管道符 ( | ) 命令与命令的关系
输入重定向(文件到命令)
命令 < 文件 将文件作为命令的标准输入
命令 << 分界符 从标准输入中读入,直到遇见分界符才停止
-------------------------------
输出重定向(命令到文件)
符号 作用
命令 > 文件 将标准输出重定向到一个文件中(清空写入 )
命令 2> 文件 将错误输出重定向到一个文件中(追加写入)
命令 >> 文件 将标准输出重定向到一个文件中(清空写入 )
命令 2>> 文件 将错误输出重定向到一个文件中(追加写入)
命令 &> 文件 将标准输出与错误输出共同写入到文件中(清空写入 )
命令 &>> 文件 将标准输出与错误输出共同写入到文件中(追加写入 )
[root@localhost mnt]# ls -l > test
[root@localhost mnt]# cat test
total 6548
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 0 Apr 10 13:12 test
[root@localhost mnt]# ls -l bing > test
ls: cannot access 'bing': No such file or directory
[root@localhost mnt]# ls -l bing 2> test
[root@localhost mnt]# cat test
ls: cannot access 'bing': No such file or directory
[root@localhost mnt]# ls -l 2> test
total 6548
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 0 Apr 10 13:14 test
[root@localhost mnt]# cat test
[root@localhost mnt]#
[root@localhost mnt]# ls -l &>> test
[root@localhost mnt]# ls -l geely &>> test
[root@localhost mnt]# cat test
ls: cannot access 'geely': No such file or directory
total 6552
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 53 Apr 10 13:18 test
ls: cannot access 'geely': No such file or directory
------------------------------------------------------------
管道符
grep /sbin/nologin /etc/passwd | wc -l
grep搜索命令的输出值传递给wc统计命令,即把原本要输出到屏幕的用户信息列表再交给wc命令作进一步的加工
[root@localhost mnt]# grep -c /sbin/nologin /etc/passwd
48
[root@localhost mnt]# grep /sbin/nologin /etc/passwd | wc -l
48
把管道符和passwd命令的--stdin参数相结合,可以用一条命令来完成密码重置操作
echo "root" | passwd --stdin root
[root@localhost mnt]# echo "root" | passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
(责任编辑:范老师)