Lunix Day 1

创建软连接

  1. 相当于Windows下的快捷方式,方便操作
  2. 节约空间

ln:Link 链接,分软链接(常用)和硬链接(默认).
常见参数:不加参数即为硬链接,加上 –s 参数即为软链接,
软链接的作用类似快捷方式
常见用法:ln –s TARGET DIRECTORY
必须使用绝对路径,相对路径会报错。

image.png

$ ls /
bin  boot  data  dev  etc  home  initrd.img  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  teach  tmp  trainee1  trainee2  usr  var  vmlinuz
Last2 11:31:07 ~
$ cd
Last2 11:32:18 ~
$ ln -s /teach . #把根目录下的teach创建到当前目录
Last2 11:34:03 ~
$ ll
total 256
drwxr-xr-x   7 Last2 Last    4096 Jan 20 11:34 ./
drwxr-xr-x 135 root  root    4096 Jan 20 11:34 ../
-rw-------   1 Last2 Last2   2242 Jan 20 11:34 .bash_history
-rw-r--r--   1 Last2 root    3895 Jan 19 17:30 .bashrc
drwx------   2 Last2 Last2   4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2      0 Jan 19 21:00 catFile
drwxr-xr-x   2 Last2 Last2   4096 Jan  7 21:26 Data/
-rw-rw-r--   1 Last2 Last2 216746 Jan 18 20:49 Data.tar.gz
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr1
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr2
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr3
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr4
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr5
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:16 myDir/
-rw-r--r--   1 Last2 root     655 Jan 17 16:51 .profile
-rw-r--r--   1 Last2 root     206 Jan 17 16:51 readme.txt
lrwxrwxrwx   1 Last2 Last2      6 Jan 20 11:34 teach -> /teach/
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:38 test1/
drwxrwxr-x   3 Last2 Last2   4096 Jan 18 22:40 test2/
Last2 11:34:11 ~
$ ls teach
data  database  document  fuz_src  jmzeng  lost+found  project  reference  software  test_data

#创建一个更深的 体会方便
$ ln -s /teach/data/airway/cleandata25000/ .
Last2 11:38:04 ~
$ ls
catFile  cleandata25000  Data  Data.tar.gz  filr1  filr2  filr3  filr4  filr5  myDir  readme.txt  teach  test1  test2
Last2 11:38:07 ~
$ ll
total 256
drwxr-xr-x   7 Last2 Last    4096 Jan 20 11:38 ./
drwxr-xr-x 135 root  root    4096 Jan 20 11:38 ../
-rw-------   1 Last2 Last2   2348 Jan 20 11:38 .bash_history
-rw-r--r--   1 Last2 root    3895 Jan 19 17:30 .bashrc
drwx------   2 Last2 Last2   4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2      0 Jan 19 21:00 catFile
lrwxrwxrwx   1 Last2 Last2     34 Jan 20 11:38 cleandata25000 -> /teach/data/airway/cleandata25000//
drwxr-xr-x   2 Last2 Last2   4096 Jan  7 21:26 Data/
-rw-rw-r--   1 Last2 Last2 216746 Jan 18 20:49 Data.tar.gz
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr1
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr2
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr3
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr4
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr5
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:16 myDir/
-rw-r--r--   1 Last2 root     655 Jan 17 16:51 .profile
-rw-r--r--   1 Last2 root     206 Jan 17 16:51 readme.txt
lrwxrwxrwx   1 Last2 Last2      6 Jan 20 11:34 teach -> /teach/
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:38 test1/
drwxrwxr-x   3 Last2 Last2   4096 Jan 18 22:40 test2/
Last2 11:38:15 ~
$ ls cleandata25000
log  SRR1039510_1_val_1.100000.fq.gz  SRR1039510_2_val_2.100000.fq.gz  SRR1039511_1_val_1.100000.fq.gz  SRR1039511_2_val_2.100000.fq.gz  SRR1039512_1_val_1.100000.fq.gz  SRR1039512_2_val_2.100000.fq.gz  z.sh
Last2 11:39:31 ~

尝试使用相对路径,不动可以,改变层级出问题,找不到位置

$ ln -s ../../teach/database/ .
Last2 12:39:24 ~
$ ll
total 260
drwxr-xr-x   7 Last2 Last    4096 Jan 20 12:39 ./
drwxr-xr-x 135 root  root    4096 Jan 20 12:39 ../
-rw-------   1 Last2 Last2   8055 Jan 20 12:39 .bash_history
-rw-r--r--   1 Last2 root    3895 Jan 19 17:30 .bashrc
drwx------   2 Last2 Last2   4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2      0 Jan 19 21:00 catFile
lrwxrwxrwx   1 Last2 Last2     34 Jan 20 11:38 cleandata25000 -> /teach/data/airway/cleandata25000//
drwxr-xr-x   2 Last2 Last2   4096 Jan  7 21:26 Data/
lrwxrwxrwx   1 Last2 Last2     21 Jan 20 12:39 database -> ../../teach/database//
-rw-rw-r--   1 Last2 Last2 216746 Jan 18 20:49 Data.tar.gz
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr1
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr2
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr3
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr4
-rw-rw-r--   1 Last2 Last2      0 Jan 18 22:41 filr5
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:16 myDir/
-rw-r--r--   1 Last2 root     655 Jan 17 16:51 .profile
-rw-r--r--   1 Last2 root     206 Jan 17 16:51 readme.txt
lrwxrwxrwx   1 Last2 Last2      6 Jan 20 11:34 teach -> /teach/
drwxrwxr-x   2 Last2 Last2   4096 Jan 18 22:38 test1/
drwxrwxr-x   3 Last2 Last2   4096 Jan 18 22:40 test2/
Last2 12:39:46 ~
$ ls database
GATK  genome  gtf  hg38_salmon  Homo_sapiens.GRCh38.cdna.all.fa.gz  index
Last2 12:40:07 ~
$ mv database test1
Last2 12:40:51 ~
$ cd test1
Last2 12:40:55 ~/test1
$ ll
total 8
drwxrwxr-x 2 Last2 Last2 4096 Jan 20 12:40 ./
drwxr-xr-x 7 Last2 Last  4096 Jan 20 12:40 ../
lrwxrwxrwx 1 Last2 Last2   21 Jan 20 12:39 database -> ../../teach/database/ #移动位置后,代码颜色变了,出问题
Last2 12:41:03 ~/test1
$ mv ../teach .
Last2 12:43:37 ~/test1
$ ll
total 8
drwxrwxr-x 2 Last2 Last2 4096 Jan 20 12:43 ./
drwxr-xr-x 7 Last2 Last  4096 Jan 20 12:43 ../
lrwxrwxrwx 1 Last2 Last2   21 Jan 20 12:39 database -> ../../teach/database/
lrwxrwxrwx 1 Last2 Last2    6 Jan 20 11:34 teach -> /teach/ #移动位置,使用绝对路径的teach仍然正常,颜色没变
Last2 12:43:39 ~/test1

https://www.linuxprobe.com/soft-hard-links-comments.html
软链接和硬链接详解

练习5:
3.运行命令 cp ~/.bashrc ~/Data/bashrc_bk 并理解结果

$ ls
catFile  cleandata25000  Data  filr1  filr2  filr3  filr4  filr5  myDir  readme.txt  test2
Last2 15:50:38 ~
$ ll #要加参数a打开所有文件,才能找到隐藏文件
total 52
drwxr-xr-x   6 Last2 Last   4096 Jan 20 15:12 ./
drwxr-xr-x 135 root  root   4096 Jan 20 15:50 ../
-rw-------   1 Last2 Last2 15686 Jan 20 15:50 .bash_history
-rw-r--r--   1 Last2 root   3895 Jan 19 17:30 .bashrc
drwx------   2 Last2 Last2  4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2     0 Jan 19 21:00 catFile
lrwxrwxrwx   1 Last2 Last2    34 Jan 20 11:38 cleandata25000 -> /teach/data/airway/cleandata25000//
drwxr-xr-x   2 Last2 Last2  4096 Jan 20 15:25 Data/
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr1
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr2
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr3
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr4
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr5
drwxrwxr-x   2 Last2 Last2  4096 Jan 18 22:16 myDir/
-rw-r--r--   1 Last2 root    655 Jan 17 16:51 .profile
-rw-r--r--   1 Last2 root    206 Jan 17 16:51 readme.txt
drwxrwxr-x   3 Last2 Last2  4096 Jan 18 22:40 test2/
Last2 15:50:41 ~
$ cp ~/.bashrc ~/Data/bashrc_bk
Last2 15:51:16 ~
$ ls Data
bashrc_bk  example.fa  example.fq  example.gtf  Homo_sapiens.GRCh38.102.chromosome.Y.gff3.gz  readme.txt
Last2 15:51:34 ~
$ ll #cp之后原文件还在
total 52
drwxr-xr-x   6 Last2 Last   4096 Jan 20 15:12 ./
drwxr-xr-x 135 root  root   4096 Jan 20 15:51 ../
-rw-------   1 Last2 Last2 15763 Jan 20 15:51 .bash_history
-rw-r--r--   1 Last2 root   3895 Jan 19 17:30 .bashrc
drwx------   2 Last2 Last2  4096 Jan 18 20:26 .cache/
-rw-rw-r--   1 Last2 Last2     0 Jan 19 21:00 catFile
lrwxrwxrwx   1 Last2 Last2    34 Jan 20 11:38 cleandata25000 -> /teach/data/airway/cleandata25000//
drwxr-xr-x   2 Last2 Last2  4096 Jan 20 15:25 Data/
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr1
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr2
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr3
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr4
-rw-rw-r--   1 Last2 Last2     0 Jan 18 22:41 filr5
drwxrwxr-x   2 Last2 Last2  4096 Jan 18 22:16 myDir/
-rw-r--r--   1 Last2 root    655 Jan 17 16:51 .profile
-rw-r--r--   1 Last2 root    206 Jan 17 16:51 readme.txt
drwxrwxr-x   3 Last2 Last2  4096 Jan 18 22:40 test2/
Last2 15:51:44 ~

课后练习1

home不是家目录,/trainee1/Last2才是

$ ls /
bin  boot  data  dev  etc  home  initrd.img  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  teach  tmp  trainee1  trainee2  usr  var  vmlinuz
Last2 16:41:40 ~
$ ls /home
hcguo  jmzeng  teach_rna  ubuntu
Last2 16:41:51 ~
$ pwd
/trainee1/Last2
Last2 16:44:06 ~
$ cd /trainee1/Last2
Last2 16:44:19 ~

场景5 处理压缩文件

image.png

image.png

image.png

其他压缩和解压命令:
zip 和 unzip:用于压缩和解压 *zip 文件
gzip 和 gunzip:用于压缩和解压 *gz 文件
bzip2 和 bunzip2:用于压缩和解压 *bz2 文件
打包和压缩的区别?
打包是指将一大堆文件或目录变成一个总的文件
压缩是将一个大的文件通过一些压缩算法变成一个小文件。
Linux 中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩
一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后
再用压缩程序进行压缩(gzip bzip2命令)。
相当于把很多的衣服先塞进真空袋(打包),将真空袋抽真空减小体积(压缩)

打包并压缩
-z是调用gzip

$ tar -zcvf test1.tar.gz example.fq example.gtf
example.fq
example.gtf
Last2 15:09:30 ~/Data
$ ll -th
total 1.9M
-rw-rw-r--  1 Last2 Last2  70K Jan 23 15:09 test1.tar.gz #打包加压缩的文件
drwxr-xr-x  2 Last2 Last2 4.0K Jan 23 15:09 ./
drwxr-xr-x 10 Last2 Last  4.0K Jan 22 22:25 ../
-rw-rw-r--  1 Last2 Last2    0 Jan 21 10:07 file
-rw-rw-r--  1 Last2 Last2   20 Jan 21 09:53 test1
-rw-rw-r--  1 Last2 Last2   45 Jan 20 22:59 file3
-rw-rw-r--  1 Last2 Last2   35 Jan 20 22:51 file2
-rw-rw-r--  1 Last2 Last2   10 Jan 20 22:49 file1
-rw-rw-r--  1 Last2 Last2 137K Jan 20 20:52 Homo_sapiens.GRCh38.102.chromosome.Y.gff3.gz
-rw-r--r--  1 Last2 Last2 3.9K Jan 20 15:51 bashrc_bk
-rw-r--r--  1 Last2 Last2  15K Dec 29 16:07 example.fa
-rw-r--r--  1 Last2 Last2 1.4M Dec 21 15:17 Homo_sapiens.GRCh38.102.chromosome.Y.gff3
-rw-rw-r--  1 Last2 Last2  206 Nov 30 21:36 readme.txt
-rw-r--r--  1 Last2 Last2  76K Oct 27  2019 example.gtf
-rw-r--r--  1 Last2 Last2 194K Nov 14  2015 example.fq
Last2 15:09:52 ~/Data

仅打包,-cvf,不调用gzip

$ tar -cvf test1.tar example.fq example.gtf
example.fq
example.gtf
Last2 15:10:37 ~/Data
$ ll -th
total 2.2M
drwxr-xr-x  2 Last2 Last2 4.0K Jan 23 15:10 ./
-rw-rw-r--  1 Last2 Last2 280K Jan 23 15:10 test1.tar #仅打包的文件
-rw-rw-r--  1 Last2 Last2  70K Jan 23 15:09 test1.tar.gz
drwxr-xr-x 10 Last2 Last  4.0K Jan 22 22:25 ../
-rw-rw-r--  1 Last2 Last2    0 Jan 21 10:07 file
-rw-rw-r--  1 Last2 Last2   20 Jan 21 09:53 test1
-rw-rw-r--  1 Last2 Last2   45 Jan 20 22:59 file3
-rw-rw-r--  1 Last2 Last2   35 Jan 20 22:51 file2
-rw-rw-r--  1 Last2 Last2   10 Jan 20 22:49 file1
-rw-rw-r--  1 Last2 Last2 137K Jan 20 20:52 Homo_sapiens.GRCh38.102.chromosome.Y.gff3.gz
-rw-r--r--  1 Last2 Last2 3.9K Jan 20 15:51 bashrc_bk
-rw-r--r--  1 Last2 Last2  15K Dec 29 16:07 example.fa
-rw-r--r--  1 Last2 Last2 1.4M Dec 21 15:17 Homo_sapiens.GRCh38.102.chromosome.Y.gff3
-rw-rw-r--  1 Last2 Last2  206 Nov 30 21:36 readme.txt
-rw-r--r--  1 Last2 Last2  76K Oct 27  2019 example.gtf
-rw-r--r--  1 Last2 Last2 194K Nov 14  2015 example.fq
Last2 15:17:48 ~/Data

解压

$ tar -zxvf test1.tar.gz 
$ tar -xvf test1.tar
example.fq
example.gtf
Last2 15:40:29 ~/Data/test

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