diff --git "a/30 \345\210\230\346\265\267\351\224\213/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221.md" "b/30 \345\210\230\346\265\267\351\224\213/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221.md" new file mode 100644 index 0000000000000000000000000000000000000000..939ea010fc9aff1e401d5df43e60a437f2f33f90 --- /dev/null +++ "b/30 \345\210\230\346\265\267\351\224\213/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221/2024-06-12 \347\256\241\351\201\223\347\254\246\345\222\214\351\207\215\345\256\232\345\220\221.md" @@ -0,0 +1,75 @@ +## 重定向 + +- 标准输入 + + 键盘输入 + +- 标准输出1 + + 显示在屏幕上,不包含错误信息 + +- 标准错误 + + 只包含错误信息 + +- 覆盖输出重定向 ">" + + ``` + echo '123' > 1.txt + ``` + +- 追加输出重定向">>" + + ```bash + echo '456' >> 1.txt + ``` + +- 输入重定向 "<" + + ```bash + grep '1' < 1.txt + ``` + +- 错误输出重定向"2>" + + ```bash + find / -name '*.conf' 2> error.txt + ``` + +- 错误输出追加重定向 "2>>" + + ```bash + abcdef 666 2>> error.txt + ``` + +- 同时重定向标准输出和标准错误输出 + + ```bash + command &> output_and_error_log.txt # 正确和错误原版混搭,原封不动 + command > 1.txt 2>&1 # 正确和错误原版混搭,原封不动 + command > 1.txt 2>> 1.txt # 先正确后错误 + command 2> 1.txt >> 1.txt # 先错误后正确 + ``` + +- 将错误输出丢弃 "/dev/null" + + ```bash + find / -name '*.conf' 2> /dev/null + ``` + +## 管道 + +```bash +将命令的输出传递给另一个命令 +ls -l |grep 'error' + +多命令链式操作 +ps aux |grep 'nginx' |awk '{print $2}' +``` + +## tee + +```bash +tee 是一个在Unix和类Unix操作系统上非常有用的命令行实用程序。 +它的作用是从标准输入中读取数据,并同时将数据输出到标准输出和一个或多个文件中。 +``` \ No newline at end of file diff --git "a/30 \345\210\230\346\265\267\351\224\213/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204.md" "b/30 \345\210\230\346\265\267\351\224\213/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204.md" new file mode 100644 index 0000000000000000000000000000000000000000..940796647c33bd8140e5f49eb758d5587b6c839b --- /dev/null +++ "b/30 \345\210\230\346\265\267\351\224\213/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204/2024-06-14 \347\224\250\346\210\267\345\222\214\347\224\250\346\210\267\347\273\204.md" @@ -0,0 +1,164 @@ +创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令) + +```bash +mkdir -p guanli/{zonghe,jishu} +``` + +添加组帐号zonghe、caiwu、jishu,GID号分别设置为2001、2002、2003 + +```bash +sudo groupadd -g 2001 zonghe +sudo groupadd -g 2002 caiwu +sudo groupadd -g 2003 jishu + +#查看用户组 +getent group +cat /etc/group +``` + +创建jerry、kylin、tsengia、obama用户,其中的kylin用户帐号在2020年12月30日后失效 + +```bash +sudo useradd -m -s /bin/bash jerry +sudo useradd -m -s /bin/bash kylin +sudo useradd -m -s /bin/bash tsengia +sudo useradd -m -s /bin/bash obama + +sudo usermod -e 2020-12-30 kylin +sudo chage -l kylin #检查用户的详细信息,包括kylin用户的失效日期 +``` + +将jerry、kylin、tsengia、obama等用户添加到zonghe组内 + +```bash +sudo usermod -aG zonghe jerry +sudo usermod -aG zonghe kylin +sudo usermod -aG zonghe tsengia +sudo usermod -aG zonghe obama + +#验证用户是否已成功添加到zonghe组 +getent group zonghe +``` + +创建handy、cucci用户,其中cucci帐号的登录Shell设置为“/sbin/nologin” + +```bash +sudo useradd -m -s /bin/bash handy +sudo useradd -m -s /sbin/nologin cucci + +#检查用户的详细信息 +getent passwd handy +getent passwd cucci +``` + +将handy、cucci等用户添加到jishu组内 + +```bash +sudo usermod -aG jishu handy +sudo usermod -aG jishu cucci + +#验证用户是否已成功添加到jishu组 +getent group jishu +``` + +将上述的所有用户均要求加入到guanli组内 + +```bash +sudo usermod -aG guanli jerry +sudo usermod -aG guanli kylin +sudo usermod -aG guanli tsengia +sudo usermod -aG guanli obama +sudo usermod -aG guanli handy +sudo usermod -aG guanli cucci +``` + +将zonghe组内的obama用户删除 + +```bash +sudo gpasswd -d obama zonghe +``` + +为jerry用户设置密码为“123456”(使用普通方法)为cucci用户设置密码为“redhat” + +```bash +sudo passwd jerry +sudo passwd cucci +``` + +将jerry用户锁定,并查看锁定状态 + +```bash +sudo passwd -l jerry + +#查看锁定状态 +sudo passwd -S jerry +``` + +打开两个xshell窗口,通过(who 或者 w)命令查看连接状态,并通过fuser杀掉其中一个 + +```bash +sudo fuser -k /dev/pts/0 +``` + +查看cucci用户,属于那些组,并查看其详细信息 + +```bash +id cucci +groups cucci +``` + +手工创建账号student(预留) + +```bash +sudo useradd -m student +``` + +设置权限及归属:/guanli目录属组设为guanli, /guanli/zonghe目录的属组设为zonghe /guanli/jishu目录的属组设为jishu,设置3个目录都是禁止其他用户访问的权限 + +```bash +sudo chgrp guanli guanli/ +sudo chgrp zonghe zonghe/ +sudo chgrp jishu jishu/ +sudo chmod -R o-rwx guanli/ +``` + +建立公共目录/ceshi允许技术组内的所有用户读取、写入、执行文件, 禁止其他用户读、写、执行 + +```bash +sudo chmod g=rwx,o-rwx ceshi/ +sudo chmod 770 ceshi/ +``` + +清除jerry用户密码 + +```bash +sudo passwd -d jerry +``` + +锁定cucci用户密码并查看状态 + +```bash +sudo passwd -l cucci +sudo passwd -S cucci +``` + +修改obama用户的UID为8888 + +```bash +sudo usermod -u 8888 obama +``` + +通过passwd命令修改kylin用户的最长密码使用期限为60天 + +```bash +sudo passwd -x 60 kylin +sudo chage -l kylin +``` + +通过id groups等命令查看用户handy信息 + +```bash +id handy +groups handy #查看用户所属的组 +getent passwd handy +``` \ No newline at end of file diff --git "a/30 \345\210\230\346\265\267\351\224\213/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241.md" "b/30 \345\210\230\346\265\267\351\224\213/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..32969af9e294ec9ca9080bb7cfdb0cd2e95c9128 --- /dev/null +++ "b/30 \345\210\230\346\265\267\351\224\213/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241/2024-06-15 \345\256\232\346\227\266\344\273\273\345\212\241.md" @@ -0,0 +1,40 @@ +# 定时任务 + +1. cron是一个用于在预定时间执行命令的服务 + +2. 使用crontab + +​ 每个用户都有创建的crontab文件 + +​ 查看定时任务 + +```bash +crontab -1 +``` + +3. 编辑定时任务 + +```bash +crontab -e +* * * * * +分钟 小时 日期 月份 星期 命令或脚本 + +* 表示任意值 +*/n 表示每n个时间执行一次 */5 * * * * 每5分钟执行一次 +n 表示特定的时间单位 30 3 * * 1 在星期一的凌晨 3 点 30 分执行任务 + +1,5 1 或 5 +1-5 1 到 5 +``` + +- 删除定时任务 + + ```bash + crontab -r + ``` + +- 用户添加的周期任务 + + ```bash + /var/spool/cron/crontabs + ``` \ No newline at end of file diff --git "a/30 \345\210\230\346\265\267\351\224\213/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217.md" "b/30 \345\210\230\346\265\267\351\224\213/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217.md" new file mode 100644 index 0000000000000000000000000000000000000000..e9a04ca85fc04919a310ca093de66889e95e85f3 --- /dev/null +++ "b/30 \345\210\230\346\265\267\351\224\213/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217/2024-06-18 \347\216\257\345\242\203\345\217\230\351\207\217.md" @@ -0,0 +1,110 @@ +## 练习题 1: 显示当前所有的环境变量 + +- 使用`printenv`或`env`命令来显示所有的环境变量。 + +``` +printenv +env +``` + +## 练习题 2: 显示`HOME`环境变量的值 + +- 使用`echo`命令和`$`符号来显示`HOME`环境变量的值。 + +``` +echo $HOME +``` + +## 练习题 3: 临时设置一个新的环境变量 + +- 设置一个名为`MY_AGE`的环境变量,并将其值设置为`18`。 + +``` +export MY_AGE=18 +``` + +## 练习题 4: 显示新设置的环境变量 + +- 使用`echo`命令来显示`MY_AGE`的值。 + +``` +echo $MY_AGE +``` + +## 练习题 5: 在新的shell会话中检查环境变量 + +- 打开一个新的终端窗口或标签页,并尝试显示`MY_AGE`的值。你会看到什么?为什么? + +``` +看不到任何输出,空行。前面MY_AGE设置的是临时环境变量,只在前一个shell生效 +``` + +## 练习题 6: 修改`PATH`环境变量 + +- 将`你当前用户的家目录`添加到你的`PATH`环境变量的末尾位置 + +``` +export PATH="$PATH:$HOME" +``` + +将`/tmp`添加到你的`PATH`环境变量的开始位置,(注意:这可能会覆盖其他路径中的同名命令,所以请谨慎操作)。 + +``` +export PATH="/tmp:$PATH" +``` + +## 练习题 7: 验证`PATH`的修改 + +- 使用`echo`命令显示`PATH`的值,并确认`前面添加的目录`已经被添加到对应位置。 + +``` +echo $PATH +``` + +## 练习题 8: 永久设置环境变量 + +- 在你的shell配置文件中(如`~/.bashrc`、`~/.bash_profile`、`~/.zshrc`等,取决于你使用的shell和配置)添加一行来永久设置`MY_NAME`,值设置为`奥德彪`。 + +例如,对于bash shell,你可以使用: + +``` +export MY_NAME="你好" +``` + +如何让`MY_NAME`生效,并验证 + +``` +source ~/.bashrc +echo $MY_NAME +``` + +## 练习题 9: 清理 + +- 清除你之前设置的`MY_AGE`和`PATH`的修改(如果你不想永久保留它们)。 + +``` +unset MY_AGE +export PATH=$(echo $PATH | sed 's/\/tmp://') +``` + +## 练习题 10: 修改默认器 + +- 使用`EDITOR`变量,修改你默认的编辑器为nano。 + +``` +export EDITOR=nano +``` + +## 练习题 11: 修改语言 + +- 使用`LANG`变量,让你的文件支持中文和utf8编码来避免乱码。 + +``` +export LANG=zh_CN.utf8 +``` + +- 使用`LANGUAGE`变量,让你的命令提示为中文 + +``` +export LANGUAGE=zh_CN.utf8 +``` \ No newline at end of file diff --git "a/30 \345\210\230\346\265\267\351\224\213/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206.md" "b/30 \345\210\230\346\265\267\351\224\213/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..bfa73444b1037c9616650d01aa28385bf16cad26 --- /dev/null +++ "b/30 \345\210\230\346\265\267\351\224\213/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206/2024-06-19 \350\277\233\347\250\213\347\256\241\347\220\206.md" @@ -0,0 +1,100 @@ +#### 优先执行里面的命令,然后执行其他命令 + +#### 在反引号中的字符串将解释成shell命令来执行 + +#### `` 与 $() 用法一样 + +#### 1.进程管理 + +ps + +- ps -aux + + 显示所有用户的进程 + + - a + - 显示当前终端的所有进程信息 + - u + - 以用户的格式显示进程信息 + - x + - 显示后台进程的参数 + +- ps -ef + + 以完整格式显示所有进程 + +- pstree + + 以树状图的形式显示运行中的进程 + + '-p' + + - 显示进程的pid + + 'u' + + - 显示进程所属的用户 + +- top + +- htop + + 一个交互式和实时监视进程查看器 + +- kill + + kill [选项] 进程号 + + - kill -9 进程号 + - 强制终止 + +- killall + + - killall 服务名 + - killall nginx + +- pgrep + + - 根据进程名查找匹配的进程ID + - pgrep -u root nginx + +- bg,fg + + - bg + - 可以将执行的任务放在后台 + - bg %进程id + - fg + - 可以将放在后台执行的任务调到前台 + - fg %进程id + - & + - 启动一个程序 + - ctrl + z + - 挂起当前执行程序 + - jobs + - 查看所有后台进程 + +## 服务管理 + +##### systemctl + +1. 启动 + + - systemctl start 服务名 + +2. 停止 + + - systemctl stop 服务名 + +3. 重启 + + - systemctl restart 服务名 + +4. 查看 + + - systemctl status 服务名 + +5. 重新加载配置文件 + + - systemctl reload 服务名 + + \ No newline at end of file