linux ubuntu系统 命令备忘(树莓派)

本文列举了一系列用于Linux系统管理的命令,包括软件包的安装、升级、卸载,程序运行查看,配置定时任务,系统日志检查以及蓝牙状态管理。这些命令涵盖了基础的系统维护和操作,是系统管理员和开发者日常工作的必备工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、安装软件包的命令

1、验证安装包是否安装

dpkg -s <软件包名>

2、从软件源服务器获取最新的软件信息并缓存到本地

apt update

3、从本地仓库中对比系统中所有已安装的软件,如果有新版本的话则进行升级

apt upgrade

4、列出本地仓库中所有的软件包名

apt list

5、从本地仓库中查找指定的包名,支持通配符

apt list [package]

6、列出系统中所有已安装的包名

apt list --installed

7、与list类似,通过给出的关键字进行搜索,列出所有的包和其描述

apt search [key]

8、列出指定包的详细情况,包名要填写完整

apt show [package]

9、安装指定的包,并同时安装其依赖的其他包

apt install -y [package]

10、卸载包,但不删除相关配置文件。包名支持通配符

apt remove [package]

11、卸载因安装软件自动安装的依赖,而现在又不需要的依赖包

apt autoremove

12、卸载包,同时删除相关配置文件。包名支持通配符

apt purge [package]

13、删除所有已下载的软件包

apt clean

14、类似clean,但删除的是过期的包(即已不能下载或者是无用的包)

apt autoclean

二、程序运行查看

1、查看服务运行情况

ps -ef|grep 【server name】
ps -aux|grep  【server name】
ps -ef|grep redis

2、查看后台进程pid:

ps -aux

3、关闭进程:

kill [pid]

三、配置定时任务

1、编辑定时执行文件

sudo vi  /etc/crontab

## 在下方输入(每天7:45重启系统)
45 7    * * *   root    /sbin/reboot
## 每两分钟执行 a.sh 的命令
*/2  *    * * * root  sh   /home/bak/a.sh

2、命令解释

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
# You can also override PATH, but by default, newer versions inherit it from the environment
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

3、系统关机命令:

        立刻关机:

        1)shutdown -h now

        2)poweroff

4、重新加载所有服务的配置文件:

systemctl daemon-reload

5、定时任务不按当前时间执行,查看配置

查看当前时间 以及 时区
timedatectl 
输入以下命令来列出所有可用的时区:
timedatectl list-timezones
到你想要设置的时区,然后使用以下命令进行设置(
sudo timedatectl set-timezone  Asia/Shanghai
确认更改生效,使用以下命令:
timedatectl

四、系统日志查看

1、最近的关机记录

last -x | grep shutdown

2、使用过的命令

history

3、相关操作命令:

last #查看近期用户或终端的登录情况
who -b #最近一次开机时间
last -1 reboot #最近一次开机时间
sudo lastb -i #查看失败登录记录, 来源以IP显示

4、查询某时段的系统程序日志

sudo journalctl --since "2024-07-01 18:30:00" --until "2024-07-01 19:05:00"

五、蓝牙配置关闭

ps -aux | grep bt-agent		-- 是否有蓝牙的控件
systemctl status bluetooth --查看蓝牙状态
systemctl stop bluetooth  -- 停止蓝牙活动

systemctl is-enabled  bluetooth.service  --- 查看crond是否为开机自启动
systemctl enable bluetooth.service  --- 将服务设置为开启启动
systemctl disable bluetooth.service  --- 关闭服务开机自启动

六、文件相关

1、查看文件夹大小: 
-s:表示汇总目录的总大小。
-h:意味着“人类可读”的格式,如KB、MB或GB等。
du -sh /path/to/directory


2、查看存储信息
df -h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值