Lunix Day 5

Linux系统环境

• 查看CPU信息:lscpu
• 查看内存信息:free -h
• 查看硬盘信息:df -h
• 查看文件大小:du -h -d 1
• 查看文件大小:du -sh ~
• 查看系统进程:top 或者 ps -ef | grep "$LOGNAME"
htop

查看CPU信息:lscpu

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8 #8核
On-line CPU(s) list:   0-7
Thread(s) per core:    1 #8核8线程
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 94
Model name:            Intel(R) Xeon(R) Gold 61xx CPU #CPU型号
Stepping:              3
CPU MHz:               2494.130
BogoMIPS:              4988.26
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-7
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single kaiser fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap xsaveopt xsavec xgetbv1 arat
(base) Last2 10:14:39 ~

查看内存信息:free -h

$ free
              total        used        free      shared  buff/cache   available
Mem:       16300696     2142168      526548      165764    13631980    13597756
Swap:             0           0           0
(base) Last2 11:05:01 ~
$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        2.0G        516M        161M         13G         12G
Swap:            0B          0B          0B
(base) Last2 11:05:41 ~

查看硬盘信息:df -h

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  162M  1.4G  11% /run
/dev/vda1        50G   20G   28G  42% /
#/dev/vda1 相当于windowsC盘
tmpfs           7.8G   28K  7.8G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vdd1       493G  334G  134G  72% /trainee1
#相当于windowsD盘
/dev/vdc1       493G  364G  104G  78% /trainee2
#相当于windowsE盘
/dev/vde1       148G   91G   50G  65% /teach
#相当于windowsF盘
tmpfs           1.6G     0  1.6G   0% /run/user/1003
tmpfs           1.6G     0  1.6G   0% /run/user/1027
tmpfs           1.6G     0  1.6G   0% /run/user/1011
tmpfs           1.6G     0  1.6G   0% /run/user/1057
tmpfs           1.6G     0  1.6G   0% /run/user/1074
tmpfs           1.6G     0  1.6G   0% /run/user/1080
tmpfs           1.6G     0  1.6G   0% /run/user/1103
tmpfs           1.6G     0  1.6G   0% /run/user/1101
tmpfs           1.6G     0  1.6G   0% /run/user/1093
tmpfs           1.6G     0  1.6G   0% /run/user/1091
tmpfs           1.6G     0  1.6G   0% /run/user/1125
tmpfs           1.6G     0  1.6G   0% /run/user/1131
tmpfs           1.6G     0  1.6G   0% /run/user/1172
tmpfs           1.6G     0  1.6G   0% /run/user/1173
tmpfs           1.6G     0  1.6G   0% /run/user/1157
tmpfs           1.6G     0  1.6G   0% /run/user/1207
tmpfs           1.6G     0  1.6G   0% /run/user/1209
tmpfs           1.6G     0  1.6G   0% /run/user/1208
(base) Last2 11:12:31 ~

查看家目录下文件大小

$ du -sh ~
3.6G    /trainee1/Last2
(base) Last2 11:37:11 ~

查看家目录下Data文件,miniconda3文件大小

$ ls
biosoft  config  database  filr1  filr3  filr5                          miniconda3                         myDir    project         readme.txt             softlink  test   tmp
catFile  Data    file      filr2  filr4  hisat2-2.1.0-Linux_x86_64.zip  Miniconda3-latest-Linux-x86_64.sh  pipline  project_backup  samtools-1.10.tar.bz2  sysoft    test2  Trimmomatic-0.39.zip
(base) Last2 11:39:53 ~
$ du -sh Data
2.6M    Data
(base) Last2 11:40:06 ~
$ du -sh miniconda3/
3.4G    miniconda3/
(base) Last2 11:41:53 ~

显示出当前每个文件夹,当成固定用法即可

$ du -h -d 1
102M    ./biosoft
3.4G    ./miniconda3
36K ./project
8.0K    ./.ssh
2.6M    ./Data
20K ./database
4.0K    ./myDir
8.0K    ./.ncbi
4.0K    ./softlink
4.0K    ./sysoft
4.0K    ./pipline
8.0K    ./test2
4.0K    ./test
8.0K    ./project_backup
8.0K    ./.conda
4.0K    ./.cache
3.6G    .
(base) Last2 11:52:11 ~

查看系统进程top,类似于windows的任务资源管理器


image.png

按q退出

查看具体某一个人的系统进程

$ top -u Last2  #u是user
image.png

查看系统进程htop

$ htop
image.png

查看具体某一个人的系统进程

$ htop -u Last2
image.png
$ ps -ef
image.png
$ ps -ef | grep 'Last2'
Last2     5453 29645  0 15:45 pts/17   00:00:00 ps -ef
Last2     5454 29645  0 15:45 pts/17   00:00:00 -bash
root     29580  1491  0 14:54 ?        00:00:00 sshd: Last2 [priv]
Last2    29587     1  0 14:54 ?        00:00:00 /lib/systemd/systemd --user
Last2    29592 29587  0 14:54 ?        00:00:00 (sd-pam)
Last2    29644 29580  0 14:54 ?        00:00:00 sshd: Last2@pts/17
Last2    29645 29644  0 14:54 pts/17   00:00:00 -bash
(base) Last2 15:45:03 ~

变量

自定义变量

$ a=gene
(base) Last2 15:53:15 ~
$ echo 'This is a $a'
This is a $a
(base) Last2 15:54:59 ~
$ echo "This is a $a"
This is a gene
(base) Last2 15:55:15 ~

单引号:变量不会被解释,不动脑子
双引号:变量被解释

环境变量

注意大小写

$ echo $HOME
/trainee1/Last2
(base) Last2 16:19:46 ~
$ echo $SHELL
/bin/bash
(base) Last2 16:19:57 ~
$ echo $LOGNAME
Last2
(base) Last2 16:20:12 ~

$PS1:修改命令行配色
~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取和执行。
Linux export 命令https://www.runoob.com/linux/linux-comm-export.html
Linux export 命令用于设置或显示环境变量。
在 shell 中执行程序时,shell 会提供一组环境变量。export 可新增,修改或删除环境变量,供后续执行的程序使用。export 的效力仅限于该次登陆操作。写入bashrc,被永久保存。
export仅设置环境变量,要echo来输出,才能写入bashrc

image.png

image.png

验证export 的效力仅限于该次登陆操作

$ export A=3
(base) Last2 16:46:57 ~
$ export -p
declare -x A="3"
declare -x CONDA_DEFAULT_ENV="base"
declare -x CONDA_EXE="/trainee1/Last2/miniconda3/bin/conda"
declare -x CONDA_PREFIX="/trainee1/Last2/miniconda3"
declare -x CONDA_PROMPT_MODIFIER="(base) "
declare -x CONDA_PYTHON_EXE="/trainee1/Last2/miniconda3/bin/python"
declare -x CONDA_SHLVL="1"
declare -x HISTSIZE="3000"
declare -x HISTTIMEFORMAT="%F %T "
declare -x HOME="/trainee1/Last2"
declare -x LANG="en_US.utf8"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LOGNAME="Last2"
......

重新登录一次,发现环境变量没有A

$ export -p
declare -x CONDA_DEFAULT_ENV="base"
declare -x CONDA_EXE="/trainee1/Last2/miniconda3/bin/conda"
declare -x CONDA_PREFIX="/trainee1/Last2/miniconda3"
declare -x CONDA_PROMPT_MODIFIER="(base) "
declare -x CONDA_PYTHON_EXE="/trainee1/Last2/miniconda3/bin/python"
declare -x CONDA_SHLVL="1"
declare -x HISTSIZE="3000"
declare -x HISTTIMEFORMAT="%F %T "
declare -x HOME="/trainee1/Last2"
declare -x LANG="en_US.utf8"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LOGNAME="Last2"

状态变量

$? 获取执行上一个指令的执行状态返回值,返回0表示上一个命令或者程序执行成功,返回的值为非0则表示上一个命令执行失败。只有0和非0的区别。

$ ls
biosoft  config  database  filr1  filr3  filr5                          miniconda3                         myDir    project         readme.txt             softlink  test   tmp
catFile  Data    file      filr2  filr4  hisat2-2.1.0-Linux_x86_64.zip  Miniconda3-latest-Linux-x86_64.sh  pipline  project_backup  samtools-1.10.tar.bz2  sysoft    test2  Trimmomatic-0.39.zip
(base) Last2 17:25:45 ~
$ echo $?
0
(base) Last2 17:25:56 ~
$ pppp
No command 'pppp' found, did you mean:
 Command 'pppd' from package 'ppp' (main)
 Command 'kppp' from package 'kppp' (universe)
 Command 'pptp' from package 'pptp-linux' (main)
 Command 'pspp' from package 'pspp' (universe)
pppp: command not found
(base) Last2 17:26:01 ~
$ echo $?
127
(base) Last2 17:26:04 ~

03.结构化语句

可以写成一段,也可以以;分隔写成一行

$ ls
biosoft  config  database  filr1  filr3  filr5                          miniconda3                         myDir    project         readme.txt             softlink  test   tmp
catFile  Data    file      filr2  filr4  hisat2-2.1.0-Linux_x86_64.zip  Miniconda3-latest-Linux-x86_64.sh  pipline  project_backup  samtools-1.10.tar.bz2  sysoft    test2  Trimmomatic-0.39.zip
(base) Last2 17:42:54 ~
$ if [ $? -eq 0 ]
> then
> echo 'Yes!'
> fi
Yes!
(base) Last2 17:44:51 ~
$ ls
biosoft  config  database  filr1  filr3  filr5                          miniconda3                         myDir    project         readme.txt             softlink  test   tmp
catFile  Data    file      filr2  filr4  hisat2-2.1.0-Linux_x86_64.zip  Miniconda3-latest-Linux-x86_64.sh  pipline  project_backup  samtools-1.10.tar.bz2  sysoft    test2  Trimmomatic-0.39.zip
(base) Last2 17:45:26 ~
$ if [ $? -eq 0 ];then echo 'Yes!';fi
Yes!
(base) Last2 17:47:58 ~

for循环语句

反引号里必须放一个可执行的命令,优先执行。不是可执行命令会报错。


image.png
$ for i in `file*`; do echo ${i} ; done
file1:
empty
file10:
empty
file2:
empty
file3:
empty
file4:
empty
file5:
empty
file6:
empty
file7:
empty
file8:
empty
file9:
empty
(base) Last2 20:26:11 ~
$ for i in `ls file*`; do echo ${i} ; done
file
file1
file10
file2
file3
file4
file5
file6
file7
file8
file9
(base) Last2 20:26:33 ~
$ for i in `ls ../file*`; do echo ${i} ; done
ls: cannot access '../file*': No such file or directory
(base) Last2 20:27:03 ~

04.Shell 脚本编程

vim很智能。写入.sh脚本,它可以识别哪句命令是对的,显示一个颜色。哪句命令是错的,显示一个颜色。写入.py脚本,print("Hi!")就显示对的颜色,echo就显示错的颜色。
如果是python脚本该如何指定?

$ which python
/usr/bin/python
Last2 18:40:20 ~
$ vim test.py

#!/usr/bin/python
print("Hi!")
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
~                                                                                                                                                                                                                                               
-- INSERT --            
$ python test.py
Hi!
Last2 18:46:10 ~

结构化语句练习:

在群文件,Linux结构化语句练习题

  1. 软件安装与环境变量:请安装一个二进制软件 bowtie2,包括下载、解压、调用 bowtie2 命令的帮助文档,修改环境变量 PATH

不需要下载这个软件,因为服务器上已经有了,拷贝一份即可 `/home/hcguo/tmp/biosoft/bowtie2-2.3.4.3-linux-x86_64.zip

# 提示,添加环境变量需要改一下安装路径
echo 'export PATH="安装路径:$PATH"' >> ~/.bashrc
echo 'export PATH="/home/hcguo/bowtie2-2.3.4.3-linux-x86_64:$PATH"' >> ~/.bashrc
echo 'export PATH="/trainee2/Sep14/bowtie2-2.3.4.3-linux-x86_64/:$PATH"' >> ~/.bashrc

我的解题

$ cd biosoft
Last2 21:28:41 ~/biosoft
$ cp /home/hcguo/tmp/biosoft/bowtie2-2.3.4.3-linux-x86_64.zip .
Last2 21:29:01 ~/biosoft
$ ls
bowtie2-2.3.4.3-linux-x86_64.zip  hisat2-2.1.0  hisat2-2.1.0-Linux_x86_64.zip
Last2 21:29:02 ~/biosoft
$ unzip bowtie2-2.3.4.3-linux-x86_64.zip 
Archive:  bowtie2-2.3.4.3-linux-x86_64.zip
   creating: bowtie2-2.3.4.3-linux-x86_64/
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-align-l  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-align-l-debug  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-inspect-l-debug  
  inflating: bowtie2-2.3.4.3-linux-x86_64/TUTORIAL  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-align-s-debug  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-inspect-s-debug  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-build-l  
  inflating: bowtie2-2.3.4.3-linux-x86_64/LICENSE  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2  
  inflating: bowtie2-2.3.4.3-linux-x86_64/AUTHORS  
  inflating: bowtie2-2.3.4.3-linux-x86_64/bowtie2-build-l-debug  
   creating: bowtie2-2.3.4.3-linux-x86_64/example/
   creating: bowtie2-2.3.4.3-linux-x86_64/example/reads/
......
$ ls
bowtie2-2.3.4.3-linux-x86_64  bowtie2-2.3.4.3-linux-x86_64.zip  hisat2-2.1.0  hisat2-2.1.0-Linux_x86_64.zip
Last2 21:35:20 ~/biosoft
$ ls bowtie2-2.3.4.3-linux-x86_64
AUTHORS  bowtie2-align-l        bowtie2-align-s        bowtie2-build    bowtie2-build-l-debug  bowtie2-build-s-debug  bowtie2-inspect-l        bowtie2-inspect-s        doc      LICENSE  MANUAL.markdown  scripts   VERSION
bowtie2  bowtie2-align-l-debug  bowtie2-align-s-debug  bowtie2-build-l  bowtie2-build-s        bowtie2-inspect        bowtie2-inspect-l-debug  bowtie2-inspect-s-debug  example  MANUAL   NEWS             TUTORIAL
Last2 21:37:34 ~/biosoft
$ cd bowtie2-2.3.4.3-linux-x86_64
Last2 21:44:01 ~/biosoft/bowtie2-2.3.4.3-linux-x86_64
$ ./bowtie2 --help
Bowtie 2 version 2.3.4.3 by Ben Langmead ([email protected], www.cs.jhu.edu/~langmea)
Usage: 
  bowtie2 [options]* -x  {-1  -2  | -U  | --interleaved } [-S ]

    Index filename prefix (minus trailing .X.bt2).
             NOTE: Bowtie 1 and Bowtie 2 indexes are not compatible.
         Files with #1 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
         Files with #2 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with unpaired reads.
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with interleaved paired-end FASTQ reads
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
        File for SAM output (default: stdout)

  , ,  can be comma-separated lists (no whitespace) and can be
  specified many times.  E.g. '-U file1.fq,file2.fq -U file3.fq'.
......

添加到PATH,这里出现了一些问题

$ $PATH
-bash: /trainee1/Last2/bin:/trainee1/Last2/.local/bin:/trainee1/Last2/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory

本想输出PATH看一看,发现有No such file or directory,原来是忘了写echo


image.png
$ PATH=
Last2 22:01:30 ~
#作死的我执行了这一步命令,然后PATH就空了
$ PATH=~/biosoft/bowtie2-2.3.4.3-linux-x86_64:$PATH
Last2 22:04:17 ~
$ echo $PATH
/trainee1/Last2/biosoft/bowtie2-2.3.4.3-linux-x86_64:
Last2 22:16:48 ~
后知后觉的我还在给PATH添加路径,到这里才发现

咨询了优秀的卖萌哥,新开了一个窗口,就好了。因为修改变量的值,不写入~/.bashrc,就只对这次登陆有效。不过,记得把bashrc给备份一下,cp ~/.bashrc ~/.bashrc_bak

image.png

备份了一下

$ cp ~/.bashrc ~/.bashrc_bak
(base) Last2 10:09:27 ~
$ ll
total 123408
drwxr-xr-x  19 Last2 Last      4096 Jan 30 10:09 ./
drwxr-xr-x 135 root  root      4096 Jan 30 10:09 ../
-rw-------   1 Last2 Last2    40819 Jan 30 10:09 .bash_history
-rw-r--r--   1 Last2 root      4390 Jan 22 20:42 .bashrc
-rw-r--r--   1 Last2 Last2     4390 Jan 30 10:09 .bashrc_bak
drwxrwxr-x   4 Last2 Last2     4096 Jan 29 21:30 biosoft/
drwx------   2 Last2 Last2     4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2        0 Jan 19 21:00 catFile
drwxrwxr-x   2 Last2 Last2     4096 Jan 22 20:41 .conda/
-rw-rw-r--   1 Last2 Last2      255 Jan 25 10:02 .condarc
-rw-rw-r--   1 Last2 Last2      150 Jan 23 21:20 config
drwx------   3 Last2 Last2     4096 Jan 29 15:08 .config/
drwxr-xr-x   3 Last2 Last2     4096 Jan 23 15:25 Data/
drwxrwxr-x   3 Last2 Last2     4096 Jan 25 22:08 database/
-rw-rw-r--   1 Last2 Last2 27104162 Jan 22 14:40 hisat2-2.1.0-Linux_x86_64.zip
drwxrwxr-x  18 Last2 Last2     4096 Jan 22 22:12 miniconda3/
-rw-rw-r--   1 Last2 Last2 94235922 Nov 24 03:21 Miniconda3-latest-Linux-x86_64.sh
drwxrwxr-x   2 Last2 Last2     4096 Jan 18 22:16 myDir/
drwx------   2 Last2 Last2     4096 Jan 25 10:56 .ncbi/
drwxrwxr-x   2 Last2 Last2     4096 Jan 25 22:16 pipline/
-rw-r--r--   1 Last2 root       655 Jan 17 16:51 .profile
drwxrwxr-x   6 Last2 Last2     4096 Jan 25 22:10 project/
drwxrwxr-x   3 Last2 Last2     4096 Jan 25 22:15 project_backup/
-rw-r--r--   1 Last2 root       206 Jan 17 16:51 readme.txt
-rw-rw-r--   1 Last2 Last2  4721173 Dec  7  2019 samtools-1.10.tar.bz2
drwxrwxr-x   2 Last2 Last2     4096 Jan 25 13:07 softlink/
drwx------   2 Last2 Last2     4096 Jan 22 14:54 .ssh/
drwxrwxr-x   2 Last2 Last2     4096 Jan 25 13:07 sysoft/
drwxrwxr-x   2 Last2 Last2     4096 Jan 22 10:22 test/
drwxrwxr-x   3 Last2 Last2     4096 Jan 18 22:40 test2/
-rw-rw-r--   1 Last2 Last2      209 Jan 22 14:03 tmp
-rw-rw-r--   1 Last2 Last2   133596 Apr  8  2019 Trimmomatic-0.39.zip
-rw-------   1 Last2 Last2     5001 Jan 25 10:03 .viminfo
(base) Last2 10:09:29 ~

添加到PATH

$ PATH=~/biosoft/bowtie2-2.3.4.3-linux-x86_64:$PATH
(base) Last2 10:12:11 ~/biosoft
$ echo $PATH
/trainee1/Last2/biosoft/bowtie2-2.3.4.3-linux-x86_64:/trainee1/Last2/bin:/trainee1/Last2/.local/bin:/trainee1/Last2/miniconda3/bin:/trainee1/Last2/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base) Last2 10:12:22 ~/biosoft

加入PATH之后就可以直接调用 bowtie2 命令的帮助文档了

$ bowtie2 -h
Bowtie 2 version 2.3.4.3 by Ben Langmead ([email protected], www.cs.jhu.edu/~langmea)
Usage: 
  bowtie2 [options]* -x  {-1  -2  | -U  | --interleaved } [-S ]

    Index filename prefix (minus trailing .X.bt2).
             NOTE: Bowtie 1 and Bowtie 2 indexes are not compatible.
         Files with #1 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
         Files with #2 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with unpaired reads.
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with interleaved paired-end FASTQ reads
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
        File for SAM output (default: stdout)

  , ,  can be comma-separated lists (no whitespace) and can be
  specified many times.  E.g. '-U file1.fq,file2.fq -U file3.fq'.
......
(base) Last2 10:17:14 ~/biosoft

写入~/.bashrc,永久保存

$ echo 'export PATH="/trainee1/Last2/biosoft/bowtie2-2.3.4.3-linux-x86_64:$PATH"'>> ~/.bashrc
(base) Last2 10:24:45 ~/biosoft
$ source ~/.bashrc
(base) Last2 10:53:16 ~/biosoft

2.if 语句与状态参数:在上一题修改好了环境变量之后,回到家目录,再次调用 bowtie2 命令的帮助文档,然后使用 if 语句判断是否调用成功(提示:状态参数变量),如果成功,输出:yes ,否则输出 no

if  [ $? -eq  0 ] ; then   echo  yes; else  echo no; fi 

我的答题
第一次尝试,错误,if 和command之间必须要加空格

$ if[ $? -eq 0 ]
if[ 0 -eq 0 ]: command not found
(base) Last2 11:26:37 ~
$ bowtie2 -h
Bowtie 2 version 2.3.4.3 by Ben Langmead ([email protected], www.cs.jhu.edu/~langmea)
Usage: 
  bowtie2 [options]* -x  {-1  -2  | -U  | --interleaved } [-S ]

    Index filename prefix (minus trailing .X.bt2).
             NOTE: Bowtie 1 and Bowtie 2 indexes are not compatible.
         Files with #1 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
         Files with #2 mates, paired with files in .
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with unpaired reads.
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
          Files with interleaved paired-end FASTQ reads
             Could be gzip'ed (extension: .gz) or bzip2'ed (extension: .bz2).
        File for SAM output (default: stdout)

  , ,  can be comma-separated lists (no whitespace) and can be
  specified many times.  E.g. '-U file1.fq,file2.fq -U file3.fq'.
......
$ if [ $? -eq 0 ]; then echo 'yes'; else echo 'no'; fi
yes
(base) Last2 11:29:30 ~

3.if 语句与自定义变量:

  • 创建文件 file1
  • 然后判断当前目录下是否有 file1 这个文件
  • 如果是,输出:yes ;否则什么都不做
touch  file1 
if  [ -f  file1  ]; then echo yes; fi

我的答案

$ touch file1
(base) Last2 11:38:22 ~
$ if [ -f file1 ]
> then 
> echo yes
> fi
yes
(base) Last2 11:41:40 ~

4.创建 10 个文件 test_file_1 ~ test_file_10 ,使用循环语句(建议用 while read id),将上面的 test_file_1 ~ test_file_10 进行重命名,如:test_file_1 改为 test_1
我的答案
使用参数拓展里的替换,将file_替换为空即可。因为要变的地方在中间,无法掐头去尾,无法索引切片。

$ touch  test_file_{1..10}
(base) Last2 12:14:38 ~
$ ls
biosoft  Data      hisat2-2.1.0-Linux_x86_64.zip      myDir    project_backup         softlink  test2         test_file_2  test_file_5  test_file_8  Trimmomatic-0.39.zip
catFile  database  miniconda3                         pipline  readme.txt             sysoft    test_file_1   test_file_3  test_file_6  test_file_9
config   file1     Miniconda3-latest-Linux-x86_64.sh  project  samtools-1.10.tar.bz2  test      test_file_10  test_file_4  test_file_7  tmp
(base) Last2 12:14:40 ~
$ ls test_file_*
test_file_1  test_file_10  test_file_2  test_file_3  test_file_4  test_file_5  test_file_6  test_file_7  test_file_8  test_file_9
(base) Last2 12:19:23 ~
$ ls test_file_* | while read id
> do
> mv ${id} ${id//file_/}
> done
(base) Last2 12:33:52 ~
$ ls
biosoft  config  database  hisat2-2.1.0-Linux_x86_64.zip  Miniconda3-latest-Linux-x86_64.sh  pipline  project_backup  samtools-1.10.tar.bz2  sysoft  test_1   test2   test_3  test_5  test_7  test_9  Trimmomatic-0.39.zip
catFile  Data    file1     miniconda3                     myDir                              project  readme.txt      softlink               test    test_10  test_2  test_4  test_6  test_8  tmp
(base) Last2 12:33:54 ~
$ ls test_*
test_1  test_10  test_2  test_3  test_4  test_5  test_6  test_7  test_8  test_9
(base) Last2 12:39:35 ~

科研利器

飞鸟flybird
文献推荐
A survey of best practices for RNA-seq data analysis
DOI号:10.1186/s13059-016-0881-8

你可能感兴趣的:(Lunix Day 5)