【Linux学习】—Linux常用指令

简介: 【Linux学习】—Linux常用指令

一、初识Linux

二、Unix和Linux介绍

1.1、Unix与Linux发展史

1.1.1、Unix发展历史和发型版本

(1)1965年,麻省理工、通用电气、贝尔实验室联合开发了Multics工程计划,虽然此计划后来失败了,但直接推动了Unix的产生

(2)1969年,贝尔实验室的肯·汤普森开在DEC PDP-7机器上开发了Unix系统

(3)1971年,丹尼斯·里奇发明了C语言

(4)1973年,Unix系统的绝大部分源代码使用C语言重写,为提高Unix系统的可移植性打下基础

1.2 Linux

(1)Linux诞生于1991年,由芬兰的大学生Linux Torvalds和后来陆续加入的众多的爱好者共同开发完成

(2)Linux是开源软件,是源代码开放的Unix

(3)Linux的标志是企鹅,有很多说法,有种说法是企鹅是芬兰的吉祥物,还有种说法是Linux Torvalds曾经被企鹅咬过,当然还有另外一种说法,企鹅处在北极,不属于任何国家,用企鹅作为logo表示linux是开源,不属于任何国家或者企业,属于全人类,同开源思想相吻合

1.2.1 Linux与Unix的关系图

1.3 Linux 和Windows 区别

三、Linux的目录结构

Linux 系统中一切皆文件

四、VI/VIM 编辑器(重要)

VI 是 Unix 操作系统和类 Unix 操作系统中最通用的文本编辑器。

VIM 编辑器是从 VI 发展出来的一个性能更强大的文本编辑器。可以主动的以字体颜色辨别语法的正确性,方便程序设计。VIM 与 VI 编辑器完全兼容。

4.2 测试数据准备

1)拷贝/etc/profile 数据到/root 目录下

[root@hadoop100 桌面]# cp /etc/profile /root
 [root@hadoop100 桌面]# cd /root/

五、VI/VIM 的三种模式

5.1一般模式(正常模式这是默认的模式)

以 vi 打开一个档案就直接进入一般模式了(这是默认的模式)。在这个模式中, 你可以使用『上下左右』按键来移动光标,你可以使用『删除字符』或『删除整行』来处理档 案内容, 也可以使用『复制、粘贴』来处理你的文件数据。

语法
yy 复制光标当前一行
y 数字 y 复制一段(从第几行到第几行)
p 箭头移动到目的行粘贴
u 撤销上一步
dd 删除光标当前行
d 数字 d 删除光标(含)后多少行
x 剪切一个字母,相当于 del
X 剪切一个字母,相当于 Backspace
yw 复制一个词
dw 删除一个词
shift+6(^) 移动到行头
shift+4 ($) 移动到行尾
shift+g 移动到页尾
数字+shift+g 移动到目标行

vi/vim 键盘图,如 下所示:

5.2 编辑模式

  • 在一般模式中可以进行删除、复制、粘贴等的动作,但是却无法编辑文件内容的!
  • 要 等到你按下『i, I, o, O, a, A』等任何一个字母之后才会进入编辑模式。
  • 注意了!通常在Linux中,按下这些按键时,在画面的左下方会出现『INSERT或REPLACE』的字样,此时才可以进行编辑。而如果要回到一般模式时, 则必须要按下『Esc』这个按键即可退出编辑模式。推出所在的模式为一般模式

按键 功能
i 当前光标前
a 当前光标后
o 当前光标行的下一行
I 光标所在行最前
A 光标所在行最后
O 当前光标行的上一行

5.3指令模式

在一般模式当中,输入『 : / ?』3个中的任何一个按钮,就可以将光标移动到最底下那一行。

在这个模式当中, 可以提供你『搜寻资料』的动作,而读取、存盘、大量取代字符、

5.4三种模式的相互切换

六、Linux 关机重启命令

七、用户登录和注销

八、用户管理

Linux系统是一个多用户任务的操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统。

8.1 添加用户

8.2查询用户

8.3切换用户

8.4 查看当前用户(登录用户)

8.5 添加用户组

用户组:类似于角色,系统可以对有共性,权限的多个用户进行统一的管理。

[root@study ~]# groupadd demo
[root@study ~]# groupdel demo
[root@study ~]# groupadd demo
[root@study ~]# useradd -g demo zwj
[root@study ~]# id zwj
uid=1001(zwj) gid=1001(demo) 组=1001(demo)
[root@study ~]#  

8.6修改用户组

[root@study ~]#  groupadd mojiao
[root@study ~]# usermod -g mojiao zwj
[root@study ~]# id zwj
uid=1001(zwj) gid=1002(mojiao) 组=1002(mojiao)
[root@study ~]# 

8.7用户和组相关的文件

九、实用指令

9.1指定运行级别

9.2帮助指令

[user@study ~]$ ls
cpp         java  模板  图片  下载  桌面
hello.java  公共  视频  文档  音乐
[user@study ~]$ 

9.3 文件目录类

[root@study /]# mkdir /home/dog1
[root@study /]# cd home
[root@study home]# ls
animal  dog  dog1  tom  user  zwj
[root@study home]# mkdir -p /animal/tiger
[root@study home]# cd animal
[root@study animal]# ls
tiger
[root@study animal]# 

[root@study /]# rmdir /home/dog
[root@study /]# cd /home/
[root@study home]# ls
animal  dog1  tom  user  zwj
[root@study home]# rmdir /home/dog1
[root@study home]# ls
animal  tom  user  zwj
[root@study home]# rm -rf /home/animal
[root@study home]# ls
tom  user  zwj
[root@study home]# 

[root@study /]# cd /home
[root@study home]# touch hello.txt
[root@study home]# ls
hello.txt  tom  user  zwj
[root@study home]# 

[root@study /]# cd /home
[root@study home]# touch hello.txt
[root@study home]# ls
hello.txt  tom  user  zwj
[root@study home]# cp hello.txt bbb/
cp: 无法创建普通文件"bbb/": 不是目录
[root@study home]# mkdir bbb
[root@study home]# cp hello.txt bbb/
[root@study home]# cd bbb/
[root@study bbb]# ls
hello.txt
[root@study bbb]# touch hello2.txt
[root@study bbb]# ls
hello2.txt  hello.txt
[root@study bbb]# cp -r /home/bbb /opt/
[root@study bbb]# cd /opt
[root@study opt]# ls
bbb  rh
[root@study opt]# 
[root@study opt]# cp -r /home/bbb/ /opt/
cp:是否覆盖"/opt/bbb/hello.txt"? y
cp:是否覆盖"/opt/bbb/hello2.txt"? y
[root@study opt]# \cp -r /home/bbb/ /opt/
[root@study opt]# 

[root@study home]# touch cat.txt
[root@study home]# touch pig.txt
[root@study home]# ls
bbb  cat.txt  pig.txt  tom  user  zwj
[root@study home]# mv /home/cat.txt monkey.txt
[root@study home]# ls
bbb  monkey.txt  pig.txt  tom  user  zwj
[root@study home]# mv /home/monkey.txt /root
[root@study home]# ls
bbb  pig.txt  tom  user  zwj
[root@study home]# 

[root@study home]# cat -n /etc/profile
     1  # /etc/profile
     2  
     3  # System wide environment and startup programs, for login setup
     4  # Functions and aliases go in /etc/bashrc
     5  
     6  # It's NOT a good idea to change this file unless you know what you
     ……

[user@study ~]$ echo $HOSTNAME
study
[user@study ~]$ echo "hello world"
hello world
[user@study ~]$ head -n 5 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
[user@study ~]$ 

时间日期类指令

[user@study home]$ date
2023年 09月 18日 星期一 09:14:51 CST
[user@study home]$ date +%Y
2023
[user@study home]$ date +%m
09
[user@study home]$ date +%d
18
[user@study home]$ date "+%Y-%m-%d %H:%M:%S"
2023-09-18 09:16:14
[user@study home]$ 

[user@study home]$ cal
      九月 2023     
日 一 二 三 四 五 六
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
[user@study home]$ cal 2023
                               2023                               
        一月                   二月                   三月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 1  2  3  4  5  6  7             1  2  3  4             1  2  3  4
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    5  6  7  8  9 10 11
15 16 17 18 19 20 21   12 13 14 15 16 17 18   12 13 14 15 16 17 18
22 23 24 25 26 27 28   19 20 21 22 23 24 25   19 20 21 22 23 24 25
29 30 31               26 27 28               26 27 28 29 30 31
        四月                   五月                   六月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   1       1  2  3  4  5  6                1  2  3
 2  3  4  5  6  7  8    7  8  9 10 11 12 13    4  5  6  7  8  9 10
 9 10 11 12 13 14 15   14 15 16 17 18 19 20   11 12 13 14 15 16 17
16 17 18 19 20 21 22   21 22 23 24 25 26 27   18 19 20 21 22 23 24
23 24 25 26 27 28 29   28 29 30 31            25 26 27 28 29 30
30
        七月                   八月                   九月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
                   1          1  2  3  4  5                   1  2
 2  3  4  5  6  7  8    6  7  8  9 10 11 12    3  4  5  6  7  8  9
 9 10 11 12 13 14 15   13 14 15 16 17 18 19   10 11 12 13 14 15 16
16 17 18 19 20 21 22   20 21 22 23 24 25 26   17 18 19 20 21 22 23
23 24 25 26 27 28 29   27 28 29 30 31         24 25 26 27 28 29 30
30 31
        十月                  十一月                 十二月       
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 1  2  3  4  5  6  7             1  2  3  4                   1  2
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    3  4  5  6  7  8  9
15 16 17 18 19 20 21   12 13 14 15 16 17 18   10 11 12 13 14 15 16
22 23 24 25 26 27 28   19 20 21 22 23 24 25   17 18 19 20 21 22 23
29 30 31               26 27 28 29 30         24 25 26 27 28 29 30
                                              31
[user@study home]$ 

[root@study ~]# clear
[root@study ~]# find /home -name hello.txt
/home/bbb/hello.txt
[root@study ~]# ls -l
总用量 12
-rw-------. 1 root root 1587 4月  25 00:52 anaconda-ks.cfg
-rw-r--r--. 1 root root   60 9月  15 16:29 a.txt
-rw-r--r--. 1 root root 1615 4月  24 17:07 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 9月  15 17:09 monkey.txt
[root@study ~]# ls -lh
总用量 12K
-rw-------. 1 root root 1.6K 4月  25 00:52 anaconda-ks.cfg
-rw-r--r--. 1 root root   60 9月  15 16:29 a.txt
-rw-r--r--. 1 root root 1.6K 4月  24 17:07 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 9月  15 17:09 monkey.txt

[root@study ~]# locate hello.txt
/home/bbb/hello.txt
/opt/bbb/hello.txt
[root@study ~]# which ls
alias ls='ls --color=auto'
  /bin/ls
[root@study ~]# which reboot
/sbin/reboot
[root@study ~]# 

[root@study home]# gzip hello.txt
[root@study home]# ls
bbb  hello.txt.gz  pig.txt  tom  user  zwj
[root@study home]# gunzip hello.txt.gz
[root@study home]# ls
bbb  hello.txt  pig.txt  tom  user  zwj
[root@study home]# 

未完待续ing……


相关文章
|
9天前
|
Linux
【Linux系统编程】基础指令(二)(下)
【Linux系统编程】基础指令(二)
|
9天前
|
Linux C语言
【Linux系统编程】基础指令(二)(上)
【Linux系统编程】基础指令(二)
|
18小时前
|
人工智能 数据可视化 Unix
【Linux】Linux系统基础指令 ( 1 )
本文讲解的指令是基础的操作,下一篇文章我们将继续讲解不同指令。
6 0
|
1天前
|
存储 Unix Linux
【Linux修行路】基本指令(二)
【Linux修行路】基本指令(二)
|
1天前
|
存储 人工智能 安全
【Linux修行路】基本指令(一)
【Linux修行路】基本指令(一)
|
2天前
|
Linux 网络安全 开发工具
Linux常见指令
Linux指令涵盖9大类:文件管理(如ls, cp, mv, rm)、文本处理(cat, grep, sed, awk)、系统管理(top, ps, kill, df, free)、网络管理(ping, ifconfig, ssh, scp)、权限用户管理(chmod, chown, useradd, passwd)、软件管理(apt, yum, pacman)、编程开发(gcc, git, make)、帮助信息(man, info, whatis)。这些指令用于系统操作、网络诊断、软件安装及用户管理等任务。
|
3天前
|
Unix Linux
【Linux】基本指令
【Linux】基本指令
11 1
|
3天前
|
人工智能 Linux 网络安全
【Linux】安装+基本指令
【Linux】安装+基本指令
10 2
【Linux】安装+基本指令
|
7天前
|
Shell Linux C++
【Linux】关于环境变量——你需要知道这些原理&指令
【Linux】关于环境变量——你需要知道这些原理&指令
|
7天前
|
Shell Linux 开发工具
【Linux】环境变量常见指令操作&基本实验(入门必看!)
【Linux】环境变量常见指令操作&基本实验(入门必看!)