使用命令sed、cp、tail、cat

1、拷贝一个任意文件(生产环境切勿操作)

cp /etc/profile /tmp

查看文件部分格式

cat /tmp/profile

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates. pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$
else
PATH=$:$PATH
fi
esac
} if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
.....
.....
.....

2、使用sed命令替换

sed 's/^ *//' /tmp/profile

root@CentOS7[::]:/tmp# sed 's/^ *//' profile
# /etc/profile # System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates. pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$
else
PATH=$:$PATH
fi
esac
} if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
.....
.....
.....

上述方法仅仅是输出到屏幕,如果想要应用到文件加上 -i参数即可

sed -i 's/^ *//' /tmp/profile

最新文章

  1. Tcp/ip 报文解析
  2. 在线倍增法求LCA专题
  3. android 音频焦点
  4. 那些不是秘密的微信earning方法
  5. 【BZOJ】2049: [Sdoi2008]Cave 洞穴勘测(lct/并查集)
  6. 键盘控制select选项上下
  7. Storm入门学习随记
  8. 对web日志文件实现按照人员、行为分类
  9. 开始使用Ambari吧
  10. 微信上传图文消息素材40007,invalid media_id hint
  11. maya绝招(1-20)
  12. cisco san交换机配置
  13. linux sort命令详解(转)
  14. 代码的鲁棒性:链表中倒数第k个结点
  15. 自定义Django的中间件
  16. 浏览器缓存机制<转>
  17. n人围成一圈报数
  18. C++_友元函数
  19. IP通信基础学习第六周(上)
  20. 模仿Semaphore自定义自己的 信号量

热门文章

  1. MybatisPlus自动填充公共字段的策略
  2. tomcat开启PID文件
  3. 常用开发类库支持--UUID及空值处理Optional
  4. go 语言结构控制
  5. java虚拟机规范(se8)——class文件格式(四)
  6. MVC通过重写OnActionExecuting获取控制器,方法和域
  7. jackson 问题定位
  8. bzoj 1176 cdq分治套树状数组
  9. JavaScript常用技巧之进制转换
  10. 77th ploty 制图神器