linux shell 和 基本指令

linux shell 和 基本指令

1.1.1 bash 与 Python
(1)which bash : 查看使用哪个bash脚本
(2)which python : 查看使用的Python

1.1.2 使用哪个脚本语言
编写shell脚本时,需根据需要进行设置:
(1)bourne shell : #!/bin/sh
(2)bash : #!/bin/bash , 使用bash的一般后缀为xx.sh
(3)python : #!/usr/bin/python, 后缀xx.py

1.1.3 实例

 1 #!/bin/bash
  2 #变量的用法,输出DATA,date,date
  3 DATE='date' 
  4 printf "%s\n" DATA
  5 printf "%s\n" $DATE #注意$
  6 printf "%s\n" "$DATE"
  7 
  8 date;echo hello #';'的用法
  9 
 10 date && echo "data" #第一条指令执行成功,才会执行第二条。date执行成功才会执行echo
 11 rm || echo "rm" #rm执行失败才会执行echo
 12 
 13 sleep 2 #睡眠2秒
 14
 15 echo "hello" > hello.txt #创建有信息的文件
 16 DATA=`date` #变量复制命令
 17 echo DATA  #打印时间

1.1.4 浏览文本文件
(1)less : 显示文件,利用vim实现
(2)more :显示文件,超过一屏,则用vim
(3)cat :显示文件

1.1.5 file 显示文件类型

1.2.1 其他操作
cp,mv,rm,mkdir,rmdir

1.3.1 IO重定向 >(覆盖) , >> (不覆盖)
(1) ls > ls.txt #把ls命令打印的内容输出到ls.txt
(2) cat hello.txt > ls.txt #hello.txt中的内容输出(覆盖形式)到ls.txt
(3) cat hello.txt >> ls.txt #不覆盖

1.4.1 | 管道
(1)grep h hello.txt #在文件hello.txt中查找h字符
(2)ls hello.txt | grep h #在ls输出的信息中查找h字符
(3)cat hello.txt | fmt | sort | less
sort : 对信息排序 sort < hello.txt
fmt :对信息格式化 fmt < hello.txt

1.5.1 chown,chgrp,chattr +i/-i,lsattr
(1) chown root:root hello.txt #修改所有者以及组
(2) chgrp ljl hello.txt #修改所有者
(3)chattr +i/-i hello.txt #修改文件属性,+i添加,-i删除。添加文件后root也无法删除

1.5.2 kill,jobs,ps
(1) jobs,ps 显示任务
(2) kill -l;显示发送信号的类型,共64种

1.5.3
who : 显示当前用户
id :显示用用户ID,组ID,所属组名。
lid :显示用户所属组
w :显示所有用户
tty : 显示当前用户终端

1.6.1 stat
(1) stat : 显示文件相关信息
(2) netstat : 显示网络信息

猜你喜欢

转载自blog.csdn.net/a185531353/article/details/78618465