【shell学习|005】- 常用命令之其他基础命令

15 篇文章 0 订阅
13 篇文章 0 订阅

其他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]# 

下一节将介绍10个与文件管理有关的命令,敬请期待

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值