Linux systems commonly used commands (2)

1. U disk mount

(1) first U disk into your computer, and then command to view disk information with fdisk: sudo fdisk -l outputs the following information:

So that we can see the U disk device name for / dev / sdb1.

Note: sda disk 1, sdb is the disk 2, and so on ....... sda1 ~ 4 primary partitions, sda5 next logical partition.

(2) Use the mount command to mount U disk to / mnt directory: sudo mount into the / dev / sdb1 after the / mnt mount / mnt directory, you can see the contents of the U disk.

(3) with the umount command to uninstall U disk: after sudo umount / mnt unloading / mnt directory will be no U contents of the disk.

Note: To try to manually mount the device mounted under / mnt, if mount to other locations such as a directory under the home directory. So the original content during mount the directory out of sight, only to wait until after unloading equipment, to recover. So we want to mount U disk to / mnt directory.

2. zipping the file / directory compression

(1) using the gzip command: gzip + filename compressed into .gz file            

         Use gunzip command: gunzip + filename .gz file decompression

Note: gzip command does not compress the directory, does not retain the original file and compression.

(2) Use bzip2 command: bzip2 + filename compressed into .bz2 file

          Use bunzip2 command: bunzip2 + decompress .bz2 file filename

Note: bzip2 command can not be compressed directory. Plus parameters -k, it will retain the original file when compressed.

(3) using the tar command:

Example 1:

Example 2:

Example 1:

Example 2:

(4) use the rar command:

Example 1:

Example 2:

Example 3:

(5) using the zip command

Example 1:

Example 2:

Example 3: Compression parameters to add the directory -r

Example 4: Extract to add parameters to the specified directory -d

3. who command

4. ps command

(1) ps aux lists information about all processes.

(2) in conjunction with other command: ps aux | grep xxx

Example 1:

注:执行命令本身需要占用一个进程,此进程也在结果当中(最后一条),所以结果数大于等于2才说明查询结果存在。下面的例2就说明了这个问题。

例2:

5. kill命令

(1)kill -l     列出所有的信号

(2)kill -SIGKILL 5179   (或kill -9 5179)   杀死进程号PID为5179的进程。    

6. evn命令

查看当前进程的环境变量。  环境变量有很多,查找其中一个的话用:evn | grep PATH

Linux中的环境变量格式:key=value:value:value   (如上面所示)

7. top命令

列出各进程的信息,类似于windows的任务管理器。缺点是只能看,不能进行其他操作。

8. 网络相关命令

(1)ifconfig       获取网络接口信息

上面的eth0代表网卡,硬件地址就是MAC地址,是唯一的。

(2)ping + IP地址         测试与目标主机的连通性,显示如下信息说明可以通信。

         ping + IP地址 -c 4     只显示4行就结束。

(3)ping + www.baidu.com     测试能不能上百度。

(4)nslookup + www.baidu.com     查看百度的IP地址。

9. 用户管理

(1)adduser命令:添加新用户

(2)su命令:切换用户

(3)groupadd命令:创建用户组      

(4)useradd命令:可以创建用户名含大写字母的用户。(adduser不可以)

其中-s参数用来指定什么类型的shell,这里为/bin/bash;-g代表我们创建的用户它所属的组,这里为Robin;-d是指定创建的用户的目录;-m代表如果家目录下没有Robin目录,就创建一个。

(5)passwd命令:给用户设置密码。

(6)deluser命令:删除用户

注:删除用户之后,家目录/home/baozheng还在,需要我们手动删除。

(7)userdel命令:删除用户和其家目录。    sudo userdel -r lisi

(8)查看所有用户:vi /etc/passwd      进入可以看到某用户是否存在。

10. ftp服务器搭建:—— vsftpd   

需要先下载vsftpd软件,ftp服务器的作用是文件的上传和下载。

(1)服务器端:

         1)修改配置文件  ——  如何修改配置文件

         软件安装好之后,配置文件 vsftpd.conf 在 /etc 目录下。先 cd /etc,然后打开vsftpd.conf 配置文件。然后就可以修改配置文件了。

         2)重启服务  ——  什么命令能够重启服务

         在配置文件修改完之后,如果想让它生效,就需要重启服务器,执行以下命令来完成重启:

         

(2)客户端(实名用户):

         1)实名用户登陆:ftp + IP(server)       然后输入用户名(server)、密码(server)。

         

        这时看最后一行有个:ftp>  ,就是已经实名登陆进去了。接下来再进行 ls 、pwd之类的命令操作就是在服务器上进行了。

        

        2)文件的上传:put + file   这个file只能上传实名登陆服务器时,客户端所在位置的目录下的file。比如是在家目录下实名登陆的服务器,那么只能上传家目录下的file。

        3)文件的下载:get + file   这个file只能是当前在服务器端所cd到的位置的目录下的file。比如当前cd到服务器的家目录下,那么就只能下载服务器的家目录下的file。

    注:不允许上传和下载目录。

(3)客户端(匿名用户):

        1)匿名用户登陆:

              不允许匿名用户在任意目录直接切换,只能在一个指定的目录范围内工作,需要在ftp服务器上创建一个匿名用户的目录,作为匿名用户的根目录。

              在ftp服务器的家目录下新建一个文件夹MyFtp,然后打开配置文件 vsftpd.conf ,在其中找一个地方添加一行:anon_root=/home/Robin/MyFtp/    

              接下来重启ftp服务器使配置文件的修改生效。

              然后客户端匿名用户登陆:ftp + IP(server)       然后输入用户名anonymous(固定的)、密码(无,回车即可)。

              这时如果输入 pwd 命令,会显示目前在根目录”/“中,但其实是在/home/Robin/MyFtp/中,因为这个目录就作为匿名用户的根目录了。如果我们事先在/home/Robin/MyFtp/中添加了目录aa和目录bb,那么这时匿名用户在登录服务器后输入 ls命令,会显示在根目录下有 aa、bb目录。

        2)文件的上传:put + file   注意:这里在上传时,在服务器端所cd到的位置的目录必须要对”其他人“有写权限,否则不能上传。

        3)文件的下载:get + file   注意:这里在下载时,在服务器端所cd到的位置的目录必须要对”其他人“有读权限,否则不能下载。

    注:不允许上传和下载目录。

(4)lftp登录ftp服务器

例1:匿名登录

例2:上传多个文件

例3:上传整个目录及其子目录

例4:下载整个目录及其子目录

11. nfs服务器的使用

(1)服务器端:

         1)创建共享目录:mkdir NfsShare

         2)打开配置文件:/etc/exports     ,然后添加一行,如下所示:

       

         3)重启服务器:sudo service nfs-kernel-server restart

(2)客户端:

         挂载服务器共享目录:mount serverIP:sharedir /mnt

         例:

         

12. ssh服务器

例1:远程登录

登录之后接下来的操作就和在远程的服务器Robin上操作是一样的了。比如这时输入 ls 命令,那么输出的就是服务器Robin的家目录中的内容。

例2:退出登录

13. scp命令

例:(这个例子是本机保存到本机)

 

 

Guess you like

Origin blog.csdn.net/mengyujia1234/article/details/90440916