其他5个常用命令
接上一节 【shell学习|004】
linux上除了ls意外,还有几个其他的基础命令;这里做个简要介绍下
如果感兴趣,可以man 各个命令,然后试验下各个参数的返回结果;
下面进入介绍环节:
1、cat: Displays a Text File 显示文本文件
cat 实用程序显示文本文件的内容。命令的名称是派生的来自 单词catenate,意思是一个接一个地连接在一起。
在屏幕上显示文件内容的一种方便的方法是给出命令 cat,后跟一个空格和文件名。
下面的例子展示了ls和cat之间的区别:
ls 实用程序显示文件名,而 cat 显示文件内容。
(base) [root@theThree cattest]# echo "this is a test file" > test
(base) [root@theThree cattest]# ls
test
(base) [root@theThree cattest]# cat test
this is a test file
(base) [root@theThree cattest]#
2、rm: Deletes a File;删除一个文件
rm:删除一个文件,下面的例子展示了使用rm删除test文件
(base) [root@theThree cattest]# ls test
test
(base) [root@theThree cattest]# cat test
this is a test file
(base) [root@theThree cattest]# rm test
(base) [root@theThree cattest]# ls test
ls: cannot access test: No such file or directory
(base) [root@theThree cattest]# cat test
cat: test: No such file or directory
(base) [root@theThree cattest]#
rm 删除文件后, ls 和 cat 显示该目录中不再存在test文件
更安全的删除方式
rm有个更加安全的交互式删除参数 -i ;默认情况下为 root 用户设置了 –i 选项
不过我这个环境没有配置,检查是否配置了-i 参数可以用alias查看:
(base) [root@theThree cattest]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
(base) [root@theThree cattest]#
配置rm -i参数
可以使用alias进行配置并再次测试
(base) [root@theThree cattest]# alias rm='rm -i'
(base) [root@theThree cattest]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
(base) [root@theThree cattest]# echo "test rm -i to delete test file" >test
(base) [root@theThree cattest]# cat test
test rm -i to delete test file
(base) [root@theThree cattest]# rm test
rm: remove regular file ‘test’? y
(base) [root@theThree cattest]# ls
(base) [root@theThree cattest]#
3、less Is more: Display a Text File One Screen at a Time
一次一屏显示一个文本文件
当您想查看超过一个屏幕的文件时,您可以使用 less或者more命令。
这两个命令在显示一个文本屏幕的内容后后都会暂停;按空格键显示下一屏文本。
more和less的细微差别:
1、在文件末尾,less 会显示 END 消息并等待您按 q 再返回 shell。而more会直接返回shell;man命令的展示就用到了less:
4、hostname: Displays the System Name 显示主机名
(base) [root@theThree cattest]# hostname
theThree
(base) [root@theThree cattest]#