Reading view

There are new articles available, click to refresh the page.

​同言之枢|社区食堂不是餐饮:一场正在失控的制度实验

file

CDT 档案卡
标题:​社区食堂不是餐饮:一场正在失控的制度实验
作者:同言之枢
发表日期:2026.5.11
来源:微信公众号- 同言之枢
主题归类:社区食堂
CDS收藏:公民馆
版权说明:该作品版权归原作者所有。中国数字时代仅对原作进行存档,以对抗中国的网络审查。详细版权说明

当一个社会开始为”吃饭”建立公共系统,它真正宣告的,是家庭结构的终结、市场逻辑的边界,以及一个尚未做好准备的国家与它的老龄化未来之间,那场无声的遭遇战。

一半是热气腾腾的人间烟火,一半是不断累积的制度成本。

社区食堂看似在解决一顿饭的问题,实际上正在承载一个时代的结构性压力——当温情成为常态,代价也终将浮出水面。

一、当一顿饭开始需要国家来解决

历史上,一个社会真正发生结构性断裂时,最先出现裂缝的,从来不是宏观指标,而是最微观的日常行为。

比如——谁来做饭。

在一个功能正常的社会结构里,这个问题甚至不需要被提出。家庭作为最基本的生活单元,天然完成食物供给的分配:年轻人劳动挣钱,老人或主妇操持家务,照料与被照料之间存在代际互换的隐性契约。这套运转了数千年的系统,在工业化与城镇化到来之前,足够稳健,足够自洽。

但现在,这套系统正在失效。

失效的速度比多数人意识到的要快。根据国家统计局与民政部联合数据,截至2024年底,中国65岁及以上老年人口已达2.17亿,占总人口比例超过15.4%,正式跨入联合国标准定义的”深度老龄化社会”门槛。与此同时,中国平均家庭户规模已从1990年的3.96人持续收缩至2.62人,独居老人与空巢老人在城市老年人口中的比例,部分一线城市已突破55%。

两组数字叠加,产生了一个现代社会最难处理的结构性后果:

越来越多需要被照料的人,不再处于任何可以提供照料的关系结构之中。
他们不是没有家庭,而是家庭已经碎裂或远离。他们不是没有钱,而是钱买不到他们真正需要的东西——陪伴、照料与日常安全感。他们每天面对的”吃饭”问题,已不再只是一个消费选择,而是一个关乎尊严、健康与生存质量的结构性困境。

于是,原本由家庭内部解决的问题,被抛向了市场,市场无力承接,再被抛向了国家。

社区食堂,就是在这个链条的末端出现的。

它被官方叙事解读为温情工程,被基层干部视为治理抓手,被媒体包装为民生亮点,被迅速复制为所谓”标准动作”。但如果我们仅仅把它理解为一项餐饮供给,那就彻底错失了这件事真正揭示的东西。

因为社区食堂所触及的真实问题,不是”老人吃不好饭”,而是:

当家庭作为生活供给的基础单元开始退出历史舞台,市场又无力填补这片空白,一个国家将用什么来接住日常生活本身?

这不是餐饮问题。这是一个文明级别的制度命题。而我们,正处于它最初的断裂处。

二、七倍扩张背后的政治经济学

2020年,中国各类”社区食堂””老年助餐点”等机构总数约在1万家左右,主要集中在北京、上海、杭州等一线及新一线城市的试点社区,体量小,覆盖有限,更像是局部实验。

到2023年底,这一数字突破7万家。

三年,七倍。

如果这是市场现象,我们会追问:需求从哪里爆发?谁在赚钱?竞争格局是什么?但社区食堂不是市场现象,它是政策现象。没有一家社区食堂是因为发现了一个高利润赛道而自然涌现的。它们之所以扩张,是因为有人决定它们必须扩张。

这个”有人”,是中央与地方的治理意志。

2022年,国家发改委、民政部等部门联合发布《关于推进基本养老服务体系建设的意见》,明确将社区助餐服务纳入基本养老服务清单,并提出”到2025年,每个街道(乡镇)至少建有一个具备综合功能的养老服务机构”的量化目标。这一政策信号迅速被各省市转化为具体指标。浙江提出”县县有示范食堂”;上海宣布”助餐服务点覆盖全市70%的社区”;北京将助餐覆盖率纳入区级政府绩效考核体系。

指标一旦进入考核,资源配置立刻跟随。

地方政府开始以远超市场速度的节奏建立社区食堂:场地由街道办划拨,装修由专项资金支持,运营补贴由民政经费兜底,宣传由社区工作者跟进。整个供给链条的每个环节,都绕开了市场的成本筛选机制,由行政意志直接驱动。

但这里有一个被扩张叙事掩盖的关键问题:政策驱动的供给,从来不以效率为最优先目标,而以完成指标为第一准则。

当”每个街道至少一家”成为目标,建不建得好、可不可持续、有没有真实需求,都是次要考量。覆盖率才是那张答卷上最显眼的分数。

结果是:我们在全国铺开了7万家食堂,但没有人真正算清楚,这7万家食堂五年之后谁来养。

与此同时,扩张本身制造了一种视觉假象——数量上的繁荣,遮蔽了结构上的脆弱。从卫星地图上看,社区食堂遍地开花,但在运营数据里,相当比例的社区食堂日均就餐人数不足50人,处于半空转状态;部分食堂在政策检查期人满为患,检查结束后门可罗雀。这不是个案,而是系统性现象。

因为它们的诞生,从一开始就不是为了解决问题,而是为了呈现解决问题的姿态。

三、一场关于”值不值”的无效辩论

围绕社区食堂,公众舆论长期陷入一种二元分裂的争论结构。

一边是正面叙事:老人吃到了热饭,独居者有了社交场所,子女减轻了牵挂,社区凝聚力得到提升。这些叙事是真实的,也是可感知的,它们出现在每一篇官方通报和每一条暖心视频里。

另一边是质疑声浪:社区食堂补贴能持续多久?是否挤压了周边餐饮生存空间?食品安全如何保障?服务是否真正触达了最需要的人群?

这两种声音看似对立,其实共享着同一个分析前提:社区食堂是一项可以被评估”值不值得做”的普通公共服务。

但这个前提是错的。

“值不值”的争论,把社区食堂当成了一个政策选项。而社区食堂真正的性质,是一个结构性强制——不是”我们选择建立它”,而是”我们没有其他选择只能建立它”。

如果不建立任何公共助餐机制,结果是什么?是2亿老年人里,失去家庭照料的那数千万人,自行承担营养失调、烹饪风险、社会隔离的系统性代价。这个代价最终仍然会转嫁给公共系统——以医疗支出、住院费用、紧急救护的方式出现,而且单位成本远高于餐饮补贴。

所以争论”要不要做”,本质上是一个伪命题。

真正的问题,从来不是”要不要建社区食堂”,而是:

以现有的模式建立社区食堂,我们能承受多远?建立之后,代价如何分配?当财政收缩时,谁最先被牺牲?

这才是值得严肃对待的问题。

然而这些问题,在当下的政策话语和媒体讨论里,几乎是缺席的。因为它们没有温情故事,没有感人画面,只有冷硬的数字和令人不安的预测。但正是这些被回避的问题,才是一个社会在集体下注之前,最需要认真回答的东西。

表层争议的无效,恰恰证明我们的讨论深度还远远不够。要真正理解这件事,必须下沉到结构层。

四、三个变量,一个无解方程

任何公共政策问题,表层现象之下都有结构变量在驱动。社区食堂的本质,是三个独立变量相互咬合之后,产生的一个系统性张力场。

变量一:人口结构——一台不会停止的压力机

人口数据是整个问题的硬底座,它不会因为政策意志的改变而改变。

中国老龄化进程正在以一种被严重低估的速度推进:

☞   2024年:65岁以上人口2.17亿,占比15.4%

☞   2030年预测:65岁以上人口将超过2.8亿,占比接近20%,正式进入”超级老龄化社会”

☞   2050年预测:65岁以上人口峰值将突破4亿,届时每三个中国人中就有一位老年人

与此同时,独居与空巢老人的比例还在持续攀升。国家卫健委的调查显示,中国城市独居老人比例从2000年的9.1%上升至2020年的17.5%,农村地区更高。随着独生子女政策带来的人口结构影响全面显现,未来十五年内,独居老人将成为规模数以千万计的主要社会群体。

这意味着什么?

意味着社区食堂的需求曲线是刚性的,而且是单向上行的。它不会因为政策调整而收缩,不会因为经济波动而消失,更不会自行解决。它只会随着时间的推移持续增长,以可预见的加速度,将压力转移到供给侧。

更重要的是,需求结构本身也在变化。当前使用社区食堂的老人,主要是70岁以下、具有一定行动能力的”低龄老人”。而未来十五年将大规模涌入老龄群体的,是身体机能更为衰退的高龄老人、失能老人,他们的需求不是一顿低价饭,而是系统性的生活照料。社区食堂作为一种供给形式,覆盖的只是这个需求冰山最浅薄的表层。

变量二:基层治理——一台偏好可见性的筛选机器

理解社区食堂的扩张,必须理解中国基层治理体系的激励结构。

在当下的地方治理逻辑中,一个公共服务项目能否获得资源倾斜,在相当程度上取决于它是否具备以下三个特征:

可视化:政绩是否可以被上级直接观察到,是否可以被媒体报道,是否能形成图像素材。

可量化:是否有清晰的数字指标——覆盖率、就餐人次、补贴金额——可以进入年度考核体系。

短周期:是否能在一个任期(通常为3-5年)内产生可观测的效果,完成”从无到有”的政绩闭环。

社区食堂在这三个维度上几乎满分:一顿热饭可以被拍摄,覆盖率可以量化,从选址到开业通常不超过半年。

这就是为什么社区食堂可以三年七倍扩张,而同样迫切的失能老人居家护理却推进迟缓。护理工作没有完美的照片,没有简洁的覆盖率指标,而且培养一个合格的养老护理员需要至少两年。

这种偏好不是个别官员的主观选择,而是整个激励结构的系统性输出。它持续地将资源引导向可见性最强的项目,同时持续地忽视可见性最弱的真实需求。

结果是:我们用可展示的政绩,填补了一个实际上无法被这种方式填补的结构性空缺。

变量三:财政能力——一道迟早会收紧的硬约束

财政是整个系统的硬边界。这个边界不会无限后退。

社区食堂的成本结构在全国范围内呈现较为稳定的区间:

成本项目                      典型区间

每餐实际综合成本             18—28元

老年居民自付价格             6—12元

财政补贴缺口/每餐           8—18元

综合补贴比例                    35%—65%

建设启动资金(每家)     30—80万元

按保守口径做规模测算:

全国7万家社区食堂,假设每家日均服务80人,每人每餐财政净补贴8元:

日均补贴总额 = 70,000 × 80 × 8 = 4.48亿元/天年度补贴总额估算 ≈ 1,600亿元

这仅是运营补贴,尚不含建设投入、人员社保、设备折旧等固定成本。

1,600亿元,相当于2023年全国民政事业费总支出的约30%。这不是边际支出,而是量级支出。

更关键的是,这笔钱的主要来源是地方财政。而当前中国地方财政正处于近年来压力最大的时期:土地出让收入从2021年的8.7万亿元骤降至2023年的5.8万亿元,降幅超过33%;地方政府显性与隐性债务合计规模据估算超过100万亿元,年化利息支出已构成显著负担。

在这张本已绷紧的财政地图上,再压上一项规模不断扩大、需求不断增长、政治上无法退出的支出项目,后果的方向是确定的,只是时间快慢的问题。

三个变量合在一起,构成了一个结构性方程:

需求刚性上行 + 供给激励扭曲 + 财政空间收窄 = 一个没有稳定解的系统

五、一个”不可稳定系统”的动态演化

三个变量各自运动,叠加之后产生的,不是静态的矛盾,而是一个具有内在动力学的演化系统。理解这个系统的运动方式,才能预判它的未来轨迹。

第一阶段:启动期(当前进行中)

需求显现 → 政策响应 → 快速扩张。补贴充裕,政治意愿强烈,可见效果明显。社区食堂成为基层治理”展示窗口”。这个阶段的特征是:问题被解决的叙事压过问题本身,矛盾被扩张速度掩盖。

第二阶段:承压期(预计3—8年内)

规模扩大 → 补贴基数增加 → 财政压力显现。地方政府开始寻求减压路径,可能采取的手段包括:压低补贴标准、提高用餐价格、收紧服务对象资格认定。每一种手段都会产生新的问题:

1.降低标准 → 食品品质下降 → 用户投诉增加

2.提高价格 → 低收入老人被排斥在外 → 初衷受损

3.收紧资格 → 边界模糊引发争议 → 行政成本上升

第三阶段:分化期(8—15年内)

财力充裕的一线城市勉强维持体系运转,财力薄弱的中西部地区出现系统性服务收缩。两速分化的现实,将制造新的地区公平问题:同样是独居老人,在上海可以吃到8元的营养午餐,在某县城的对应服务可能已经名存实亡。

第四阶段:制度锁定(全过程伴随)

这是最危险的机制,也是最难被正视的:

一旦一项福利服务形成稳定的使用习惯和社会预期,它就从”政策选项”变成了”权利预期”。政策可以被调整,但权利预期是极难收回的。任何对社区食堂服务的缩减——哪怕是局部的、有充分财政理由的——都将在政治上被理解为”剥夺老人权利”,引发的社会反弹将远超当初建立时获得的政治收益。

这就是为什么社区食堂本质上是一扇只能推开、不能关上的门。推开它需要一个决策,关上它需要一场政治风暴。

动态演化的终点,不是稳定均衡,而是一个规模越来越大、成本越来越高、管理越来越难、退出越来越不可能的系统。

这个系统将持续存在,持续消耗资源,直到另一个更大的财政或社会危机将它强制重组。

六、它解决了问题,也制造了更大的问题

政策评估中最危险的陷阱,是只计算它解决了什么,而不计算它的解决方式制造了什么。

社区食堂制造了三个被系统性忽视的次生问题,其长期影响,可能远超它本身提供的价值。

次生问题一:对私人市场的扭曲性挤出

社区食堂的低价,不来自效率,来自财政补贴对成本的遮蔽。

当一个得到公共资金支持的供给者,以远低于市场成本的价格进入市场,它实际上是在用公共资金打击私人竞争对手。这不是正当竞争,而是一种制度性的不公平。

民政部相关课题组在2023年的调研数据显示,在社区食堂密度较高的区域,500米半径内小型餐饮门店营业额平均下降18%—32%,其中定位于老年群体的小餐馆降幅最为显著,部分地区出现了整街老年餐饮业态的关闭潮。

这些小餐馆,本来是私人市场对老年需求的自发响应。它们不完美,不够低价,但它们是可自我维持的,不需要财政输血。社区食堂将它们挤出,创造了更大的市场空白,然后用更多的公共资金来填补这个它自己制造的空白。

长期均衡的方向清晰可见:私人供给持续萎缩,公共供给被迫持续扩张,财政依赖程度螺旋式上升,系统韧性持续降低。

这不是养老服务的进步,这是供给系统的结构性弱化。

次生问题二:资源错配与需求优先序的系统性失衡

中国老年群体的需求是分层的,且各层之间的紧迫度差异巨大。

第一层:能自理、只是吃饭不方便的老人。这是社区食堂主要覆盖的群体。

第二层:半失能老人,日常生活需要部分辅助,但尚能独自行动。

第三层:失能老人,无法完成日常生活自理,需要全时照护。

第四层:认知症老人,具有走失、意外伤害等高危风险,需要专业干预。

根据国家卫健委2022年数据,中国失能和半失能老年人口已超过4,200万,认知症老人超过1,500万。这两个群体,才是老龄化危机中真正迫切、真正高成本、真正可能引发系统性风险的需求来源。

但专业护理床位缺口?超过400万张。养老护理员缺口?根据民政部预测,到2025年缺口将达500万人。

为什么最紧迫的需求反而最被忽视?

因为失能老人的照护,没有漂亮的照片,没有简洁的覆盖率指标,没有感人的暖心故事。一个护理员帮助失能老人翻身、清洁,是沉默的、辛苦的、难以被呈现的日常。

社区食堂吸纳了大量的政策注意力、基层资源与财政投入,而这些资源的机会成本,是那4200万失能老人继续在无法得到体面照护的处境中等待。

我们在用可见性最高的需求,消耗了本应用于优先级最高的需求的资源。这是一种正在发生的集体失误。

次生问题三:福利锁定效应与政策空间的永久性收窄

这是三个次生问题中最难被讨论、也最难被解决的一个。

行为经济学的大量研究证明,一旦一项利益进入个体的日常预期,对它的剥夺所产生的心理痛苦,是获得它时快乐的2—2.5倍(损失厌恶效应,Kahneman & Tversky,1979)。公共福利政策同样服从这一规律:建立时获得的政治红利,远小于收缩时承受的政治成本。

社区食堂一旦在全国规模建立并稳定运行,就将完成一次不可逆的”预期锚定”:数以千万计的老年居民将把这项服务视为理所当然的基本权利,而非可调整的政策工具。任何哪怕微小的调整——轻微提价、局部关闭、供给缩减——都将在政治上引发极不对称的反弹。

这意味着,社区食堂的规模一旦固化,就构成了地方财政的永久性刚性负债。它不再是一项政策,而是一项无法违约的社会契约。

在财政压力可能持续数十年的背景下,用数以千亿计的永久性刚性负债来换取一张展示治理温情的名片,这笔账,没有人真正算过。

七、一个文明的账单,还没有开始计算

现在,到了给出判断的时候。

回到文章标题中的那个词——实验。

对于一个实验,我们有义务给出评估,而不只是描述现象、罗列问题、然后留下一个开放式的问题让读者自己思考。那是一种知识上的懦弱。

我的判断是明确的:

社区食堂是一个方向正确、模式粗糙、边界失控、后果尚未出清的危险实验。

说方向正确:老龄化社会需要公共介入日常生活,这是真实的结构性需求,不可回避,也不应回避。

说模式粗糙:补贴密集、效率不敏感、以覆盖率代替可持续性、以扩张速度代替制度设计,这套运营逻辑在人口压力持续增加的背景下,不具备基本的长期稳健性。

说边界失控:在没有解决”谁来保证质量””钱从哪里长期来””如何设计有序退出””资源优先序如何确定”这四个基础制度问题之前,七倍的规模扩张是一场系统性的冒险,代价会在未来以倍数放大的方式偿还。

说后果尚未出清:这个实验的真正账单,还没有开始进入公众视野。因为它的后果是滞后的。今天建立的规模,今天锁定的预期,今天制造的市场扭曲,将在5年、10年、20年后以财政危机、服务崩溃、政治困境的方式显现。届时,做出这些决策的人已经离任,而承担后果的,是下一代的纳税人和下一代的老人。

这是代际之间的一次沉默的债务转移,只是目前没有人以这种方式来讨论它。

真正需要发生的转变

批评不是为了否定,而是为了看清改变的方向。

当前的社区食堂模式,需要发生一次根本性的转变:从展示性工程转变为制度性工程。

展示性工程关注覆盖率,制度性工程关注财务可持续性。展示性工程由政治意愿驱动,制度性工程由制度设计驱动。展示性工程以可见性作为成功标准,制度性工程以十年后的运营健康度作为成功标准。

具体而言,这个转变需要至少解决三个制度层面的问题:

第一,建立与人口结构动态挂钩的财政机制。 社区食堂的补贴规模,应当基于老龄人口预测、地方财政能力与服务成本的综合模型来设定,而不是以”覆盖率指标”为出发点倒推。这需要中央层面建立统一的精算框架,而不是让各地自行摸索、自行承担后果。

第二,明确并强制执行需求优先序。 失能老人的照护,应当在资源分配上具有明确的优先权,高于”吃饭不方便”的助餐需求。当前的资源分配格局颠倒了优先序,而这种颠倒是被激励结构系统性制造出来的,不是靠道德呼吁能纠正的,必须在考核机制上直接矫正。

第三,设计可执行的有序退出机制。 这是最政治敏感也最不可回避的一条。福利锁定效应意味着不设计退出路径,就等于允许它成为永久刚性负债。退出机制不是”关闭食堂”,而是将部分需求向市场侧引导——通过发放养老服务券、开放第三方运营竞争、鼓励适老餐饮认证等方式,在不损害服务连续性的前提下,逐步降低对财政补贴的依赖程度。

更大的命题

社区食堂只是一个入口,它引向的是中国未来三十年最核心的制度命题:

一个超大规模的老龄化社会,如何在家庭功能退出、市场能力有限的条件下,构建一套可负担、可持续、有尊严的生活支持体系?

这个命题没有现成答案。日本用了三十年、经历了”介护险”制度的多次危机与修正,才勉强形成了当前的框架,且仍在持续压力之下。德国的双轨制养老体系在人口结构变化下也在持续调整。没有一个高度老龄化的国家,找到了这个问题的完美解法。

中国面临的挑战,在规模上史无前例,在速度上史无前例,在财政约束上也史无前例。它没有可以直接移植的成功样本,只有从他人的失败和自身的试验中艰难摸索的余地。

在这个背景下,社区食堂最真实的价值,也许不在于它今天提供了多少顿饭,而在于它作为制度探索的第一步,迫使中国的治理体系开始正视一个过去长期被回避的问题:

当家庭不再是生活供给的可靠单元,谁来承担日常生活本身的重量?

这个问题,没有轻巧的答案。但它值得——也需要——比”建几万家食堂”更严肃、更深远的回应。

社区食堂的真实考验,不在于今天有多少老人吃到了一顿热饭。

而在于当那一代更庞大的老人到来,当财政已然收紧,当市场已被挤空,当政策已经锁死——我们是否还有能力,给出一个体面的答案。

而那一天,比我们想象的要近得多。

本文数据来源:国家统计局、民政部、国家卫健委、国家发改委政策文件及公开学术研究,部分区间数据来自地方调研报告。

有淘宝的员工不,咨询下到底怎样才可以关闭淘宝 App 的垃圾通知?

v321ex: 如题,V 站应该是有淘宝的程序员或者其他职能员工,真心求问 Android 上到底怎样才可以关闭淘宝 App 的垃圾营销通知,具体的通知见下面的截图:


作为一个不怎么用淘宝的,我想让我的淘宝只收到两类通知:1 )和店铺客服的对话通知 2 )物流通知。

其他什么一分钱抢个东西,抢个红包啥的通知我真的不需要,别在用那么低级诱导性的通知文案天天来用户手机上拉屎了。

设置里的消息通知截图如下:



尝试咨询过客服,只能说从业人员的职业能力真的很参差不齐。
- 有搞不清短信和应用通知的
- 有让我直接关闭通知的
- 有拽上天让我别用淘宝的

我特么的。

连接的方式

思维是神经细胞的连接产生的;

程序是传感器和硬件连接运行的;

人,是在和其他人连接的过程中诞生的。

构成「系统」的不是原子或者物质,而是原子和物质之间的连接方式,是连接的「方式」决定了涌现出来的东西是什么。

记忆是连接;

业务是连接;

灵魂,也是连接。

病,就是某些连接断了;死,就是所有连接断了;

生,就是新连接产生了;长,就是不断有新连接在产生。

成住坏空,就是「感知—连接—断连—消失」的过程。

因此,无常才是恒常。

自我,也不是什么固定的东西。

Linux Command Line Reference for Common Operations (2)


My previous reference for practical Linux commands was surprisingly popular
with over 3.5 million hits in nearly 5 years. So I've decided to start compiling
another list of somewhat more involved/esoteric commands.
Examples marked with • are valid/safe to paste without modification into a terminal, so
you may want to keep a terminal window open while reading this so you can cut & paste.
CommandDescription
grep . /proc/sys/net/ipv4/*List the contents of flag files
set | grep $USERSearch current environment
tr '\0' '\n' < /proc/$$/environDisplay the startup environment for any process
echo $PATH | tr : '\n'Display the $PATH one per line
kill -0 $$ && echo process exists and can accept signalsCheck for the existence of a process (pid)
find /etc -readable | xargs less -K -p'*ntp' -j $((${LINES:-25}/2))Search paths and data with full context. Use n to iterate
Low impact admin
#apt-get install "package" -o Acquire::http::Dl-Limit=42 \
-o Acquire::Queue-mode=access
Rate limit apt-get to 42KB/s
 echo 'wget url' | at 01:00Download url at 1AM to current dir
#apache2ctl configtest && apache2ctl gracefulRestart apache if config is OK
nice openssl speed sha1Run a low priority command (openssl benchmark)
chrt -i 0 openssl speed sha1Run a low priority command (more effective than nice)
renice 19 -p $$; ionice -c3 -p $$Make shell (script) low priority. Use for non interactive tasks
Interactive monitoring
watch -t -n1 uptimeClock with system load
htop -d 5Better top (scrollable, tree view, lsof/strace integration, ...)
iotopWhat's doing I/O
#watch -d -n30 "nice ps_mem.py | tail -n $((${LINES:-12}-2))"What's using RAM
#iftopWhat's using the network. See also iptraf
#mtr www.pixelbeat.orgping and traceroute combined
Useful utilities
pv < /dev/zero > /dev/nullProgress Viewer for data copying from files and pipes
wkhtml2pdf http://.../linux_commands.html linux_commands.pdfMake a pdf of a web page
timeout 1 sleep 3run a command with bounded time. See also timeout
Networking
python -m SimpleHTTPServerServe current directory tree at http://$HOSTNAME:8000/
openssl s_client -connect www.google.com:443 </dev/null 2>&0 |
openssl x509 -dates -noout
Display the date range for a site's certs
curl -I www.pixelbeat.orgDisplay the server headers for a web site
#lsof -i tcp:80What's using port 80
#httpd -SDisplay a list of apache virtual hosts
vim scp://user@remote//path/to/fileEdit remote file using local vim. Good for high latency links
curl -s http://www.pixelbeat.org/pixelbeat.asc | gpg --importImport a gpg key from the web
tc qdisc add dev lo root handle 1:0 netem delay 20msecAdd 20ms latency to loopback device (for testing)
tc qdisc del dev lo rootRemove latency added above
Notification
echo "DISPLAY=$DISPLAY xmessage cooker" | at "NOW +30min"Popup reminder
notify-send "subject" "message"Display a gnome popup notification
 echo "mail -s 'go home' P@draigBrady.com < /dev/null" | at 17:30Email reminder
 uuencode file name | mail -s subject P@draigBrady.comSend a file via email
 ansi2html.sh | mail -a "Content-Type: text/html" P@draigBrady.comSend/Generate HTML email
Better default settings (useful in your .bashrc)
#tail -s.1 -f /var/log/messagesDisplay file additions more responsively
seq 100 | tail -n $((${LINES:-12}-2))Display as many lines as possible without scrolling
#tcpdump -s0Capture full network packets
Useful functions/aliases (useful in your .bashrc)
md () { mkdir -p "$1" && cd "$1"; }Change to a new directory
strerror() { python -c "import os; print os.strerror($1)"; }Display the meaning of an errno
plot() { { echo 'plot "-"' "$@"; cat; } | gnuplot -persist; }Plot stdin. (e.g: • seq 1000 | sed 's/.*/s(&)/' | bc -l | plot)
hili() { e="$1"; shift; grep --col=always -Eih "$e|$" "$@"; }highlight occurences of expr. (e.g: • env | hili $USER)
alias hd='od -Ax -tx1z -v'Hexdump. (usage e.g.: • hd /proc/self/cmdline | less)
alias realpath='readlink -f'Canonicalize path. (usage e.g.: • realpath ~/../$USER)
ord() { printf "0x%x\n" "'$1"; }shell version of the ord() function
chr() { printf $(printf '\\%03o\\n' "$1"); }shell version of the chr() function
Multimedia
DISPLAY=:0.0 import -window root orig.pngTake a (remote) screenshot
convert -filter catrom -resize '600x>' orig.png 600px_wide.pngShrink to width, computer gen images or screenshots
 mplayer -ao pcm -vo null -vc dummy /tmp/Flash*Extract audio from flash video to audiodump.wav
 ffmpeg -i filename.aviDisplay info about multimedia file
ffmpeg -f x11grab -s xga -r 25 -i :0 -sameq demo.mpgCapture video of an X display
DVD
 for i in $(seq 9); do ffmpeg -i $i.avi -target pal-dvd $i.mpg; doneConvert video to the correct encoding and aspect for DVD
 dvdauthor -odvd -t -v "pal,4:3,720xfull" *.mpg;dvdauthor -odvd -TBuild DVD file system. Use 16:9 for widescreen input
 growisofs -dvd-compat -Z /dev/dvd -dvd-video dvdBurn DVD file system to disc
Unicode
python -c "import unicodedata as u; print u.name(unichr(0x2028))"Lookup a unicode character
uconv -f utf8 -t utf8 -x nfcNormalize combining characters
printf '\300\200' | iconv -futf8 -tutf8 >/dev/nullValidate UTF-8
printf 'ŨTF8\n' | LANG=C grep --color=always '[^ -~]\+'Highlight non printable ASCII chars in UTF-8
fc-match -s "sans:lang=zh"List font match order for language and style
Development
gcc -march=native -E -v -</dev/null 2>&1|sed -n 's/.*-mar/-mar/p'Show autodetected gcc tuning params. See also gcccpuopt
for i in $(seq 4); do { [ $i = 1 ] && wget http://url.ie/6lko -qO-||
./a.out; } | tee /dev/tty | gcc -xc - 2>/dev/null; done
Compile and execute C code from stdin
cpp -dM /dev/nullShow all predefined macros
echo "#include <features.h>" | cpp -dN | grep "#define __USE_"Show all glibc feature macros
 gdb -tuiDebug showing source code context in separate windows
udev
udevadm info -a -p $(udevadm info -q path -n /dev/input/mouse0)List udev attributes of a device, for matching rules etc.
udevadm test /sys/class/input/mouse0See how udev rules are applied for a device
#udevadm control --reload-rulesReload udev rules after modification
Extended Attributes (Note you may need to (re)mount with "acl" or "user_xattr" options)
getfacl .Show ACLs for file
setfacl -m u:nobody:r .Allow a specific user to read file
setfacl -x u:nobody .Delete a specific user's rights to file
 setfacl --default -m group:users:rw- dir/Set umask for a for a specific dir
 getcap fileShow capabilities for a program
 setcap cap_net_raw+ep your_gtk_progAllow gtk program raw access to network
stat -c%C .Show SELinux context for file
 chcon ... fileSet SELinux context for file (see also restorecon)
getfattr -m- -d .Show all extended attributes (includes selinux,acls,...)
setfattr -n "user.foo" -v "bar" .Set arbitrary user attributes
BASH specific
echo 123 | tee >(tr 1 a) | tr 1 bSplit data to 2 commands (using process substitution)
 meld local_file <(ssh host cat remote_file)Compare a local and remote file (using process substitution)
Multicore
taskset -c 0 nprocRestrict a command to certain processors
find -type f -print0 | xargs -r0 -P$(nproc) -n10 md5sumProcess files in parallel over available processors
 sort -m <(sort data1) <(sort data2) >data.sortedSort separate data files over 2 processors

Linux Command Line Reference for Common Operations


This is a linux command line reference for common operations.
Examples marked with • are valid/safe to paste without modification into a terminal, so
you may want to keep a terminal window open while reading this so you can cut & paste.
All these commands have been tested both on Fedora and Ubuntu.
See also more linux commands.
CommandDescription
apropos whatisShow commands pertinent to string. See also threadsafe
man -t ascii | ps2pdf - > ascii.pdfmake a pdf of a manual page
which commandShow full path name of command
time commandSee how long a command takes
time catStart stopwatch. Ctrl-d to stop. See also sw
dir navigation
cd -Go to previous directory
cdGo to $HOME directory
(cd dir && command)Go to dir, execute command and return to current dir
pushd .Put current dir on stack so you can popd back to it
file searching
alias l='ls -l --color=auto'quick dir listing
ls -lrtList files by date. See also newest and find_mm_yyyy
ls /usr/bin | pr -T9 -W$COLUMNSPrint in 9 columns to width of terminal
find -name '*.[ch]' | xargs grep -E 'expr'Search 'expr' in this dir and below. See also findrepo
find -type f -print0 | xargs -r0 grep -F 'example'Search all regular files for 'example' in this dir and below
find -maxdepth 1 -type f | xargs grep -F 'example'Search all regular files for 'example' in this dir
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; doneProcess each item with multiple commands (in while loop)
find -type f ! -perm -444Find files not readable by all (useful for web site)
find -type d ! -perm -111Find dirs not accessible by all (useful for web site)
locate -r 'file[^/]*\.txt'Search cached index for names. This re is like glob *file*.txt
look referenceQuickly search (sorted) dictionary for prefix
grep --color reference /usr/share/dict/wordsHighlight occurances of regular expression in dictionary
archives and compression
gpg -c fileEncrypt file
gpg file.gpgDecrypt file
tar -c dir/ | bzip2 > dir.tar.bz2Make compressed archive of dir/
bzip2 -dc dir.tar.bz2 | tar -xExtract archive (use gzip instead of bzip2 for tar.gz files)
tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'Make encrypted archive of dir/ on remote machine
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2Make archive of subset of dir/ and below
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parentsMake copy of subset of dir/ and below
(tar -c /dir/to/copy) | ( cd /where/to/ && tar -x -p )Copy (with permissions) copy/ dir to /where/to/ dir
(cd /dir/to/copy && tar -c .) | ( cd /where/to/ && tar -x -p )Copy (with permissions) contents of copy/ dir to /where/to/
(tar -c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ && tar -x -p'Copy (with permissions) copy/ dir to remote:/where/to/ dir
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'Backup harddisk to remote machine
rsync (Network efficient file copier: Use the --dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file fileOnly get diffs. Do multiple times for troublesome downloads
rsync --bwlimit=1000 fromfile tofileLocally copy with rate limit. It's like nice for I/O
rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html'Mirror web site (using compression and encryption)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/Synchronize current directory with remote one
ssh (Secure SHell)
ssh $USER@$HOST commandRun command on $HOST as $USER (default command=shell)
ssh -f -Y $USER@$HOSTNAME xeyesRun GUI command on $HOSTNAME as $USER
scp -p -r $USER@$HOST: file dir/Copy with permissions to $USER's home directory on $HOST
scp -c arcfour $USER@$LANHOST: bigfileUse faster crypto for local LAN. This might saturate GigE
ssh -g -L 8080:localhost:80 root@$HOSTForward connections to $HOSTNAME:8080 out to $HOST:80
ssh -R 1434:imap:143 root@$HOSTForward connections from $HOST:1434 in to imap:143
ssh-copy-id $USER@$HOSTInstall public key for $USER@$HOST for password-less log in
wget (multi purpose download tool)
(cd dir/ && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html)Store local browsable version of a page to the current dir
wget -c http://www.example.com/large.fileContinue downloading a partially downloaded file
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/Download a set of files to the current directory
wget ftp://remote/file[1-9].iso/FTP supports globbing directly
wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | headProcess output directly
echo 'wget url' | at 01:00Download url at 1AM to current dir
wget --limit-rate=20k urlDo a low priority download (limit to 20KB/s in this case)
wget -nv --spider --force-html -i bookmarks.htmlCheck links in a file
wget --mirror http://www.example.com/Efficiently update a local copy of a site (handy from cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
ethtool eth0Show status of ethernet interface eth0
ethtool --change eth0 autoneg off speed 100 duplex fullManually set ethernet interface speed
iwconfig eth1Show status of wireless interface eth1
iwconfig eth1 rate 1Mb/s fixedManually set wireless interface speed
iwlist scanList wireless networks in range
ip link showList network interfaces
ip link set dev eth0 name wanRename interface eth0 to wan
ip link set dev eth0 upBring interface eth0 up (or down)
ip addr showList addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0Add (or del) ip and mask (255.255.255.0)
ip route showList routing table
ip route add default via 1.2.3.254Set default gateway to 1.2.3.254
host pixelbeat.orgookup DNS ip address for name or vice versaL
hostname -iLookup local ip address (equivalent to host `hostname`)
whois pixelbeat.orgLookup whois info for hostname or ip address
netstat -tuplList internet services on a system
netstat -tupList active connections to/from system
windows networking (Note samba is the package that provides all this windows specific networking support)
smbtreeFind windows machines. See also findsmb
nmblookup -A 1.2.3.4Find the windows (netbios) name associated with ip address
smbclient -L windows_boxList shares on windows machine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/shareMount a windows share
echo 'message' | smbclient -M windows_boxSend popup to windows machine (off by default in XP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing with the -i option)
sed 's/string1/string2/g'Replace string1 with string2
sed 's/\(.*\)1/\12/g'Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d'Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta'Concatenate lines with trailing \
sed 's/[ \t]*$//'Remove trailing spaces from lines
sed 's/\([`"$\]\)/\\\1/g'Escape shell metacharacters active within double quotes
seq 10 | sed "s/^/      /; s/ *\(.\{7,\}\)/\1/"Right align numbers
sed -n '1000{p;q}'Print 1000th line
sed -n '10,20p;20q'Print lines 10 to 20
sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q'Extract title from HTML web page
sed -i 42d ~/.ssh/known_hostsDelete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4nSort IPV4 ip addresses
echo 'Test' | tr '[:lower:]' '[:upper:]'Case conversion
tr -dc '[:print:]' < /dev/urandomFilter non printable characters
tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4cut fields separated by blanks
history | wc -lCount lines
set operations (Note you can export LANG=C for speed. Also these assume no duplicate lines within a file)
sort file1 file2 | uniqUnion of unsorted files
sort file1 file2 | uniq -dIntersection of unsorted files
sort file1 file1 file2 | uniq -uDifference of unsorted files
sort file1 file2 | uniq -uSymmetric Difference of unsorted files
join -t'\0' -a1 -a2 file1 file2Union of sorted files
join -t'\0' file1 file2Intersection of sorted files
join -t'\0' -v2 file1 file2Difference of sorted files
join -t'\0' -v1 -v2 file1 file2Symmetric Difference of sorted files
math
echo '(1 + sqrt(5))/2' | bc -lQuick math (Calculate φ). See also bc
seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -lCalculate π the unix way
echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bcMore complex (int) e.g. This shows max FastE packet rate
echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | pythonPython handles scientific notation
echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | gnuplot -persistPlot FastE packet rate vs packet size
echo 'obase=16; ibase=10; 64206' | bcBase conversion (decimal to hexadecimal)
echo $((0x2dec))Base conversion (hex to dec) ((shell arithmetic expansion))
units -t '100m/9.58s' 'miles/hour'Unit conversion (metric to imperial)
units -t '500GB' 'GiB'Unit conversion (SI to IEC prefixes)
units -t '1 googol'Definition lookup
seq 100 | (tr '\n' +; echo 0) | bcAdd a column of numbers. See also add and funcpy
calendar
cal -3Display a calendar
cal 9 1752Display a calendar for a particular month year
date -d friWhat date is it this friday. See also day
[ $(date -d '12:00 +1 day' +%d) = '01' ] || exitexit a script unless it's the last day of the month
date --date='25 Dec' +%AWhat day does xmas fall on, this year
date --date='@2147483647'Convert seconds since the epoch (1970-01-01 UTC) to date
TZ='America/Los_Angeles' dateWhat time is it on west coast of US (use tzselect to find TZ)
date --date='TZ="America/Los_Angeles" 09:00 next Fri'What's the local time for 9AM next Friday on west coast US
locales
printf "%'d\n" 1234Print number with thousands grouping appropriate to locale
BLOCK_SIZE=\'1 ls -lUse locale thousands grouping in ls. See also l
echo "I live in `locale territory`"Extract info from locale database
LANG=en_IE.utf8 locale int_prefixLookup locale info for specific country. See also ccodes
locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | lessList fields available in locale database
recode (Obsoletes iconv, dos2unix, unix2dos)
recode -l | lessShow available conversions (aliases on each line)
recode windows-1252.. file_to_change.txtWindows "ansi" to local charset (auto does CRLF conversion)
recode utf-8/CRLF.. file_to_change.txtWindows utf8 to local charset
recode iso-8859-15..utf8 file_to_change.txtLatin9 (western europe) to utf8
recode ../b64 < file.txt > file.b64Base64 encode
recode /qp.. < file.qp > file.txtQuoted printable decode
recode ..HTML < file.txt > file.htmlText to HTML
recode -lf windows-1252 | grep euroLookup table of characters
echo -n 0x80 | recode latin-9/x1..dumpShow what a code represents in latin-9 charmap
echo -n 0x20AC | recode ucs-2/x2..latin-9/xShow latin-9 encoding
echo -n 0x20AC | recode ucs-2/x2..utf-8/xShow utf-8 encoding
CDs
gzip < /dev/cdrom > cdrom.iso.gzSave copy of data cdrom
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gzCreate cdrom image from contents of dir
mount -o loop cdrom.iso /mnt/dirMount the cdrom image at /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fastClear a CDRW
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom -Burn cdrom image (use dev=ATAPI -scanbus to confirm dev)
cdparanoia -BRip audio tracks from CD to wav files in current dir
cdrecord -v dev=/dev/cdrom -audio -pad *.wavMake audio CD from all wavs in current dir (see also cdrdao)
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'Make ogg file from wav file
disk space (See also FSlint)
ls -lSrShow files by size, biggest last
du -s * | sort -k1,1rn | headShow top disk users in current dir. See also dutop
du -hs /home/* | sort -k1,1hSort paths by easy to interpret disk usage
df -hShow free space on mounted filesystems
df -iShow free inodes on mounted filesystems
fdisk -lShow disks partitions sizes and types (run as root)
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1nList all packages by installed size (Bytes) on rpm distros
dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1nList all packages by installed size (KBytes) on deb distros
dd bs=1 seek=2TB if=/dev/null of=ext3.testCreate a large test file (taking no space). See also truncate
> filetruncate data of file or create an empty file
monitoring/debugging
tail -f /var/log/messagesMonitor messages in a log file
strace -c ls >/dev/nullSummarise/profile system calls made by command
strace -f -e open ls >/dev/nullList system calls made by command
strace -f -e trace=write -e write=1,2 ls >/dev/nullMonitor what's written to stdout and stderr
ltrace -f -e getenv ls >/dev/nullList library calls made by command
lsof -p $$List paths that process id has open
lsof ~List processes that have specified path open
tcpdump not port 22Show network traffic except ssh. See also tcpdump_not_me
ps -e -o pid,args --forestList processes in a hierarchy
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'List processes by % cpu usage
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNSList processes by mem (KB) usage. See also ps_mem.py
ps -C firefox-bin -L -o pid,tid,pcpu,stateList all threads for a particular process
ps -p 1,$$ -o etime=List elapsed wall time for particular process IDs
last rebootShow system reboot history
free -mShow amount of (remaining) RAM (-m displays in MB)
watch -n.1 'cat /proc/interrupts'Watch changeable data continuously
udevadm monitorMonitor udev events to help configure rules
system information (see also sysinfo) ('#' means root access is required)
uname -aShow kernel version and system architecture
head -n1 /etc/issueShow name and version of distribution
cat /proc/partitionsShow all partitions registered on the system
grep MemTotal /proc/meminfoShow RAM total seen by the system
grep "model name" /proc/cpuinfoShow CPU(s) info
lspci -tvShow PCI info
lsusb -tvShow USB info
mount | column -tList mounted filesystems on the system (and align output)
grep -F capacity: /proc/acpi/battery/BAT0/infoShow state of cells in laptop battery
#dmidecode -q | lessDisplay SMBIOS/DMI information
#smartctl -A /dev/sda | grep Power_On_HoursHow long has this disk (system) been powered on in total
#hdparm -i /dev/sdaShow info about disk sda
#hdparm -tT /dev/sdaDo a read speed test on disk sda
#badblocks -s /dev/sdaTest for unreadable blocks on disk sda
interactive (see also linux keyboard shortcuts)
readlineLine editor used by bash, python, bc, gnuplot, ...
screenVirtual terminals with detach capability, ...
mcPowerful file manager that can browse rpm, tar, ftp, ssh, ...
gnuplotInteractive/scriptable graphing
linksWeb browser
xdg-open .open a file or url with the registered desktop application
© Jan 7 2008   [Comments] | [Add link to ...] |

Linux系统信息查看命令大全


最近看了一些Linux命令行的文章,在系统信息查看方面学到不少命令。发现这些系统信息查看命令也可以总结出一篇小小的东西来了。

另外这里还有非常多的命令, 可以作为参考。


系统
# uname -a               # 查看内核/操作系统/CPU信息
# head -n 1 /etc/issue   # 查看操作系统版本
# cat /proc/cpuinfo      # 查看CPU信息
# hostname               # 查看计算机名
# lspci -tv              # 列出所有PCI设备
# lsusb -tv              # 列出所有USB设备
# lsmod                  # 列出加载的内核模块
# env                    # 查看环境变量
资源
# free -m                # 查看内存使用量和交换区使用量
# df -h                  # 查看各分区使用情况
# du -sh <目录名>        # 查看指定目录的大小
# grep MemTotal /proc/meminfo   # 查看内存总量
# grep MemFree /proc/meminfo    # 查看空闲内存量
# uptime                 # 查看系统运行时间、用户数、负载
# cat /proc/loadavg      # 查看系统负载
磁盘和分区
# mount | column -t      # 查看挂接的分区状态
# fdisk -l               # 查看所有分区
# swapon -s              # 查看所有交换分区
# hdparm -i /dev/hda     # 查看磁盘参数(仅适用于IDE设备)
# dmesg | grep IDE       # 查看启动时IDE设备检测状况
网络
# ifconfig               # 查看所有网络接口的属性
# iptables -L            # 查看防火墙设置
# route -n               # 查看路由表
# netstat -lntp          # 查看所有监听端口
# netstat -antp          # 查看所有已经建立的连接
# netstat -s             # 查看网络统计信息
进程
# ps -ef                 # 查看所有进程
# top                    # 实时显示进程状态
用户
# w                      # 查看活动用户
# id <用户名>            # 查看指定用户信息
# last                   # 查看用户登录日志
# cut -d: -f1 /etc/passwd   # 查看系统所有用户
# cut -d: -f1 /etc/group    # 查看系统所有组
# crontab -l             # 查看当前用户的计划任务
服务
# chkconfig --list       # 列出所有系统服务
# chkconfig --list | grep on    # 列出所有启动的系统服务
程序
# rpm -qa                # 查看所有安装的软件包

附加一张总结的很好Linux常用命定的图片:
Linux 文件结构大全

❌