bash学习

1. 空格

  1. 等号赋值两边不能有空格
  2. 命令与选项之间需要空格
  3. 管道两边空格可有可无

2. 方括号

  1. [a=1]等号为赋值语句, 两边没有空格
  2. if语句if [ "a" = "1" ];then echo a;fi有空格, 因为
    1. [为bash builtin test command的synonym, 是一个命令, 用]表示命令的结束, 返回中间语句的exit status. 中间为参数, 需要空格隔开.
    2. 中间的=比较运算符, 需要用空格隔开.

3. 引号

参考

  1. 单引号'full quoting
    两个单引号包围起来的字符串就是普通的字符串,它将保留原始的字面意思.
  2. 双引号"partial quoting
    两个双引号包围起来的字符串,部分特殊字符将起到它们的作用.
    这些特殊字符有: $, \, `, !.
  3. 反引号`
    两个反引号包围起来的字符串,将作为命令来运行,执行的输出结果作为该反引号的内容,称为命令替换,它有另一种更好的写法: $(command)

4. 转向符

  1. >
    > filename输出保存在filename中
  2. <
    < filename将filename作为输入
  3. |
    Useful for chaining commands, scripts, files, and programs together.
    cat *.txt | sort | uniq > result-file

ssh user@host "cat > remote_dst; command; cat remote_src" < local_src > local_dst

  1. Copies local_src to remote_dst,
  2. Executes command,
  3. Copies remote_src to local_dst.

5. find

find / -name "wa*"#查找所有目录文件名为wa*的文件
find / -iname '*ensembl*'

6. which

which指令会在环境变量$PATH设置的目录里查找符合条件的文件。

7. 打包文件

  1. .tar[.gz|.xz|.bz2|.lz]
    打包[压缩] tar -[z|J|j|--lzip]cvf archive.tar.gz originalfiles
    [解压]解包 tar -[z|J|j|--lzip]xvf archive.tar.gz -C dir
    -t 查看包
    -a根据后缀压缩/解压
    --strip=n忽略前n个目录
  2. .zip
    压缩: zip -rv zipfile.zip originalfiles
    解压: unzip zipfile.zip [-d dir]
    合并压缩文件 zip -s 0 split.zip -O unsplit.zip
    解压分卷压缩 zip -s 0 split.zip - | unzip - -d dir(未测试)
  3. .gz
    压缩:gzip originfile
    解压:gunzip zipfile.gz, gzip -d zipfile.gz
    -k 保留原文件
    gzip -c originfile > dir/zipfile.gz 压缩至指定位置

8. 查找命令

查找该命令的内容

  1. type -a python3
    • determines if command is alias, function, built-in command, cached executable (hashed), binary in $PATH, etc
    • shell builtin
  2. which python3
    • finds executable in your $PATH
    • lives in /usr/bin/which

9. 查看进程

  1. ps
    ps aux | less显示所有运行中的进程
    ps -u vivek查看用户vivek运行的进程
  2. top显示运行中系统的动态实时视图
    按q退出,按h进入帮助
  3. pstree以树状显示正在运行的进程
  4. pgrep查找进程
    pgrep -u root sshd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值