学习小组Day2笔记--ksprings

感谢生信星球提供的服务器练习账号

Day2-linux常用命令.png

一、服务器登录

  • putty
  • Finalshell
  • ssh

二、常用命令及参数

tips :善用Tab补全命令

1. pwd 显示当前工作目录/路径

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

2. mkdir 创建目录

3. ls 显示目录、文件

bio05@VM-0-10-ubuntu:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .gnupg  .profile
bio05@VM-0-10-ubuntu:~$ mkdir test
bio05@VM-0-10-ubuntu:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .gnupg  .profile  test
bio05@VM-0-10-ubuntu:~$ 

4. rm 删除

  • rmdir 删除目录
bio05@VM-0-10-ubuntu:~$ rmdir test
bio05@VM-0-10-ubuntu:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .gnupg  .profile
  • 删除文件
bio05@VM-0-10-ubuntu:~$ touch test.txt
bio05@VM-0-10-ubuntu:~$ ls
test.txt
bio05@VM-0-10-ubuntu:~$ rm test.txt 
bio05@VM-0-10-ubuntu:~$ ls
bio05@VM-0-10-ubuntu:~$ 

5. cd 切换目录

bio05@VM-0-10-ubuntu:~$ mkdir tmp
bio05@VM-0-10-ubuntu:~$ pwd
/home/bio05
bio05@VM-0-10-ubuntu:~$ cd tmp
bio05@VM-0-10-ubuntu:~/tmp$ pwd
/home/bio05/tmp
bio05@VM-0-10-ubuntu:~/tmp$ 

6. vi 新建文件/脚本

bio05@VM-0-10-ubuntu:~/tmp$ vi helloworld.txt
bio05@VM-0-10-ubuntu:~/tmp$ ls
helloworld.txt

7. cat/head/tail 显示全部 / 前面 / 后面文件内容

  • cat
bio05@VM-0-10-ubuntu:~/tmp$ cat helloworld.txt 
one
two
three
four
five
six
seven
eight
nine
ten
  • head
bio05@VM-0-10-ubuntu:~/tmp$ head -n4 helloworld.txt 
one
two
three
four
  • tail
bio05@VM-0-10-ubuntu:~/tmp$ tail -n5 helloworld.txt 
six
seven
eight
nine
ten

8. cp 复制

bio05@VM-0-10-ubuntu:~/tmp$ cp helloworld.txt new.txt
bio05@VM-0-10-ubuntu:~/tmp$ ls
helloworld.txt  new.txt
bio05@VM-0-10-ubuntu:~/tmp$ cat new.txt 
one
two
three
four
five
six
seven
eight
nine
ten

9. mv 移动或重命名

  • 移动
bio05@VM-0-10-ubuntu:~/tmp$ tree ~
/home/bio05
└── tmp
    ├── helloworld.txt
    └── new.txt

1 directory, 2 files
bio05@VM-0-10-ubuntu:~/tmp$ mv new.txt ~
bio05@VM-0-10-ubuntu:~/tmp$ tree ~
/home/bio05
├── new.txt
└── tmp
    └── helloworld.txt

1 directory, 2 files
  • 重命名
bio05@VM-0-10-ubuntu:~/tmp$ cd ..
bio05@VM-0-10-ubuntu:~$ ls
new.txt  tmp
bio05@VM-0-10-ubuntu:~$ mv new.txt old.txt
bio05@VM-0-10-ubuntu:~$ ls
old.txt  tmp

三、学习资源

四、思考题

  • ls输出的是横向的列表,怎样输出长格式列表?
bio05@VM-0-10-ubuntu:~$ ls -l
total 8
-rw-rw-r-- 1 bio05 bio05   49 Apr 18 16:21 old.txt
drwxrwxr-x 2 bio05 bio05 4096 Apr 18 16:26 tmp
  • 如何查看长格式列表中文件的大小?
bio05@VM-0-10-ubuntu:~$ ls -lh
total 8.0K
-rw-rw-r-- 1 bio05 bio05   49 Apr 18 16:21 old.txt
drwxrwxr-x 2 bio05 bio05 4.0K Apr 18 16:26 tmp
  • 查看Linux系统版本、内存与硬盘空间?
bio05@VM-0-10-ubuntu:~$ uname -a
Linux VM-0-10-ubuntu 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
bio05@VM-0-10-ubuntu:~$ free -lh
              total        used        free      shared  buff/cache   available
Mem:           1.8G        323M         94M        5.5M        1.4G        1.3G
Low:           1.8G        1.7G         94M
High:            0B          0B          0B
Swap:            0B          0B          0B
bio05@VM-0-10-ubuntu:~$ df -lh
Filesystem      Size  Used Avail Use% Mounted on
udev            885M  4.0K  885M   1% /dev
tmpfs           184M  5.5M  178M   3% /run
/dev/vda1        50G   25G   23G  53% /
tmpfs           917M   48K  917M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           917M     0  917M   0% /sys/fs/cgroup
tmpfs           184M     0  184M   0% /run/user/1157
tmpfs           184M     0  184M   0% /run/user/1158
tmpfs           184M     0  184M   0% /run/user/1159
tmpfs           184M     0  184M   0% /run/user/1161
  • 怎样建立类似/tmp/tmp1/tmp1.1 这样的层级目录?
bio05@VM-0-10-ubuntu:~$ tree
.
└── old.txt

0 directories, 1 file
bio05@VM-0-10-ubuntu:~$ mkdir -p tmp/tmp1/tmp1.1
bio05@VM-0-10-ubuntu:~$ tree
.
├── old.txt
└── tmp
    └── tmp1
        └── tmp1.1

3 directories, 1 file
  • 怎样删除这些层级目录?
bio05@VM-0-10-ubuntu:~$ rm -r tmp
bio05@VM-0-10-ubuntu:~$ tree
.
└── old.txt

0 directories, 1 file
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容