生信星球培训第四十三期

Day2-生信笔记-smartyy

2020-03-10  本文已影响0人  SmartSwift_529d

思维导图

Day2-Linux的基本操作-jyy.png

Linux基本操作

1.显示当前路径

pwd:print working directory,就是显示当前路径的指令

bio17@VM-0-10-ubuntu:~$ pwd
/home/bio17

/home/bio17就是我的当前路径

2.创建空目录

mkdir:make directory,就是创建你的空目录
现在来尝试创建四个名为soft,project,tmp,scr的四个新的空目录:

bio17@VM-0-10-ubuntu:~$ mkdir project
bio17@VM-0-10-ubuntu:~$ mkdir soft
bio17@VM-0-10-ubuntu:~$ mkdir tmp
bio17@VM-0-10-ubuntu:~$ mkdir scr

3.显示列表

ls:list,可以显示目录或是文件的列表
刚刚创建了四个新的空目录,那么用ls指令来检查一下是否创建成功了

bio17@VM-0-10-ubuntu:~$ ls
project  scr  soft  tmp

嗯,看来是成功了0.0

4.进入指定的目录

1.cd后面接一个目录名,就可以进入该目录。试一试吧!
如果我想进入刚刚创建的project目录:

bio17@VM-0-10-ubuntu:~$ cd project
bio17@VM-0-10-ubuntu:~/project$

2.cd -:如果我想从我正处于的project目录中退出去,返回到刚才的目录,可以使用这个指令。(cd和-之间必须要有一个空格!)
试一试吧:

bio17@VM-0-10-ubuntu:~/project$ cd -
/home/bio17

3.cd:直接进入主目录

5.删除

1.删除文件:rm
2.删除空目录:rmdir
3.删除非空目录:rm -r
注:这三个命令后面都要跟上
你要删除的目录或者文件名

现在往空目录project里面新建一个文件吧!

bio17@VM-0-10-ubuntu:~$ cd project #首先进入project这个空目录中
bio17@VM-0-10-ubuntu:~/project$ touch smart.txt #touch是新建命令
bio17@VM-0-10-ubuntu:~/project$ ls
smart.txt

这样一来,project就不再是一个空目录了,其内存在一个smart.text文件
试着再往空目录tmp中新建一个文件吧!

bio17@VM-0-10-ubuntu:~$ cd #返回主目录
bio17@VM-0-10-ubuntu:~$ cd tmp #进入tmp这个空目录中
bio17@VM-0-10-ubuntu:~/tmp$ touch swift.txt #新建swift.txt文件
bio17@VM-0-10-ubuntu:~/tmp$ ls
swift.txt

现在我们拥有了两个非空目录,分别是project以及tmp

准备工作完成后,开始练习删除操作吧!
1.删除文件smart.txt

bio17@VM-0-10-ubuntu:~/tmp$ cd #先返回到主目录中
bio17@VM-0-10-ubuntu:~$ cd project #进入到project这个非空目录中
bio17@VM-0-10-ubuntu:~/project$ rm smart.txt #删除smart.txt文件
bio17@VM-0-10-ubuntu:~/project$ ls #检查smart.txt文件是否已删除

好的,成功删除了文件smart.txt,于是目录project又变成了空目录
2.删除空目录project

bio17@VM-0-10-ubuntu:~/project$ rmdir project
rmdir: failed to remove 'project': No such file or directory
bio17@VM-0-10-ubuntu:~/project$ cd #看来直接在project路径下无法删除其本身,要回 到主目录中才可
bio17@VM-0-10-ubuntu:~$ rmdir project #删除空目录project
bio17@VM-0-10-ubuntu:~$ ls #检查空目录project是否已删除
scr  soft  tmp

嗯,空目录project删除成功,现在剩下一个非空目录tmp,试着删除一下它吧!
3.删除非空目录tmp

bio17@VM-0-10-ubuntu:~$ rm-r tmp #删除非空目录tmp
rm-r: command not found
bio17@VM-0-10-ubuntu:~$ rm -r tmp #看来rm和-r之间的空格不可忽略
bio17@VM-0-10-ubuntu:~$ ls #检查一下非空目录tmp是否已被删除
scr  soft

6.新建脚本或者文本文档

vi命令可新建脚本或文本文档,它和前面提到的touch指令不同,touch是正经的新建命令,但是没有vi好使,vi是直接新建并打开编辑(敲i键就可以开始输入了)
vi是Linux中的文本编辑器

尝试着往空目录scr中新建一个有内容的文本文档吧

bio17@VM-0-10-ubuntu:~$ cd scr
bio17@VM-0-10-ubuntu:~/scr$ vi love_poem.txt
bio17@VM-0-10-ubuntu:~/scr$ ls
love_poem.txt

文本文档love_poem.txt新建成功,往里面输入一首英文诗吧!

7.将内容输出屏幕

1.cat指令可查看并直接将内容输出到屏幕
那么就用cat将刚刚输入的那首英文诗输出到屏幕看看吧!

bio17@VM-0-10-ubuntu:~/scr$ cat love_poem.txt
How do I love thee?
Let me count the ways.
I love thee to the depth and breadth and height
My soul can reach
when feeling out of sight for the ends of being
and ideal Grace
I love thee to the level of every day's most quiet need
by sun and candle light
I love thee freely
as men strive for right
I love thee purely
as they turn from praise
I love with a passion put to use in my old grief
and with mu childhood's faith

2.head:默认输出内容的前十行

bio17@VM-0-10-ubuntu:~/scr$ head love_poem.txt
How do I love thee?
Let me count the ways.
I love thee to the depth and breadth and height
My soul can reach
when feeling out of sight for the ends of being
and ideal Grace
I love thee to the level of every day's most quiet need
by sun and candle light
I love thee freely
as men strive for right

3.tail:默认输出内容的后10行

bio17@VM-0-10-ubuntu:~/scr$ tail love_poem.txt
and ideal Grace
I love thee to the level of every day's most quiet need
by sun and candle light
I love thee freely
as men strive for right
I love thee purely
as they turn from praise
I love with a passion put to use in my old grief
and with mu childhood's faith

4.head -n 3:自定义输出前几行(这里是前3行)
注:head 与 -n之间的空格不可省略,-n与3之间的空格可有可无

bio17@VM-0-10-ubuntu:~/scr$ head -n3 love_poem.txt
How do I love thee?
Let me count the ways.
I love thee to the depth and breadth and height

嗯,一切似乎都很顺利呢~ 。~

8.复制文件

cp:复制文件
使用方法:cp file1 file2

来试试将刚刚新建的文件love_poem.txt复制一个叫做new_file.txt吧!

bio17@VM-0-10-ubuntu:~/scr$ cp love_poem.txt new_file.txt
bio17@VM-0-10-ubuntu:~/scr$ ls #检查一下scr目录中会不会出现第二个复制文件
love_poem.txt  new_file.txt

刚刚的love_poem.txt文件复制成功了
要不要给它换个好听的名字然后移动到别的文件夹呢?

9.文件的移动和重命名

1.mv filenname1 filename2:重命名
试试看将复制文件new_file.txt,重命名为home.txt吧!

bio17@VM-0-10-ubuntu:~/scr$ mv new_file.txt home.txt #将复制文件new_file.txt重命名为home.txt
bio17@VM-0-10-ubuntu:~/scr$ ls #检查一下该文件的名称是否已变更
home.txt  love_poem.txt

文件重命名成功了嘛
2.mv file 路径:将文件移入到其他文件夹中(路径:~/该文件夹名称)
那么试试将scr目录下的文件home.txt移入到空目录soft中吧

bio17@VM-0-10-ubuntu:~/scr$ mv home.txt ~/soft #将文件home.txt移入目录soft中
bio17@VM-0-10-ubuntu:~/scr$ ls #检查文件home.txt是否从原目录中移除
love_poem.txt
bio17@VM-0-10-ubuntu:~/scr$ cd #返回主目录
bio17@VM-0-10-ubuntu:~$ cd soft #进入目录soft中查看文件home.txt是否已移入其中
bio17@VM-0-10-ubuntu:~/soft$ ls
home.txt

我的猪脑子啊,是时候让你休息一下了@.@

上一篇 下一篇

猜你喜欢

热点阅读