百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

Linux 如何删除某路径下属主为root的所有文件和文件夹

ahcoder 2025-01-12 10:59 14 浏览

方法1

删除当前路径下属主为root的所有文件和文件夹

find ./* -user root -print0 | xargs -0 rm -rf

删除当前路径下属组为root的所有文件和文件夹

find ./* -group root -print0 | xargs -0 rm -rf

为了防止删错,开始时最好分步执行命令,当确定该删时才合并执行:

# 第一步
ls -l

# 第二步:
find ./* -user root

# 第三步:
find ./* -user root -print0

# 第四步:合并命令正式执行删除操作
find ./* -user root -print0 | xargs -0 rm -rf

方法2: 不要轻易执行rm -rf删除操作,若删除就后悔莫及了

find ./* -user root -exec ls -l {} +
find ./* -user root -exec rm -rf {} +

方法3:此方法不可靠,容易删错文件

step 1:

root@tdar-srv:/home/decisionmaker/.vscode# ls -al
total 172
drwxrwxr-x 17 decisionmaker decisionmaker  4096 9月  18 21:20  .
drwxr-xr-x 29 decisionmaker decisionmaker  4096 9月  18 21:37  ..
-rw-rw-r--  1 decisionmaker decisionmaker   984 9月  18 20:50  argv.json
drwxr-xr-x  2 root          root           4096 9月  18 21:17  Backups
drwx------  3 root          root           4096 9月  18 21:17  blob_storage
drwx------  3 root          root           4096 9月  18 21:18  Cache
drwxr-xr-x  3 root          root           4096 9月  18 21:17  CachedData
drwxr-xr-x  2 root          root           4096 9月  18 21:17  CachedExtensions
drwx------  4 root          root           4096 9月  18 21:17 'Code Cache'
-rw-------  1 root          root          20480 9月  18 21:18  Cookies
-rw-------  1 root          root              0 9月  18 21:18  Cookies-journal
drwx------  2 root          root           4096 9月  18 21:17 'Crash Reports'
drwx------  2 root          root           4096 9月  18 21:17  Dictionaries
drwxrwxr-x  3 decisionmaker decisionmaker  4096 9月  18 20:50  extensions
drwx------  2 root          root           4096 9月  18 21:17 'exthost Crash Reports'
drwx------  2 root          root           4096 9月  18 21:17  GPUCache
-rw-r--r--  1 root          root              2 9月  18 21:17  languagepacks.json
drwx------  3 root          root           4096 9月  18 21:17 'Local Storage'
drwxr-xr-x  3 root          root           4096 9月  18 21:17  logs
-rw-r--r--  1 root          root             36 9月  18 21:17  machineid
-rw-------  1 root          root            365 9月  18 21:18 'Network Persistent State'
-rw-r--r--  1 root          root            446 9月  18 21:17  rapid_render.json
drwx------  2 root          root           4096 9月  18 21:20 'Session Storage'
-rw-r--r--  1 root          root          59724 9月  18 21:17  storage.json
-rw-------  1 root          root            406 9月  18 21:18  TransportSecurity
drwxr-xr-x  4 root          root           4096 9月  18 21:17  User

step 2:

root@tdar-srv:/home/decisionmaker/.vscode# ls -al | grep root
drwxr-xr-x  2 root          root           4096 9月  18 21:17 Backups
drwx------  3 root          root           4096 9月  18 21:17 blob_storage
drwx------  3 root          root           4096 9月  18 21:18 Cache
drwxr-xr-x  3 root          root           4096 9月  18 21:17 CachedData
drwxr-xr-x  2 root          root           4096 9月  18 21:17 CachedExtensions
drwx------  4 root          root           4096 9月  18 21:17 Code Cache
-rw-------  1 root          root          20480 9月  18 21:18 Cookies
-rw-------  1 root          root              0 9月  18 21:18 Cookies-journal
drwx------  2 root          root           4096 9月  18 21:17 Crash Reports
drwx------  2 root          root           4096 9月  18 21:17 Dictionaries
drwx------  2 root          root           4096 9月  18 21:17 exthost Crash Reports
drwx------  2 root          root           4096 9月  18 21:17 GPUCache
-rw-r--r--  1 root          root              2 9月  18 21:17 languagepacks.json
drwx------  3 root          root           4096 9月  18 21:17 Local Storage
drwxr-xr-x  3 root          root           4096 9月  18 21:17 logs
-rw-r--r--  1 root          root             36 9月  18 21:17 machineid
-rw-------  1 root          root            365 9月  18 21:18 Network Persistent State
-rw-r--r--  1 root          root            446 9月  18 21:17 rapid_render.json
drwx------  2 root          root           4096 9月  18 21:20 Session Storage
-rw-r--r--  1 root          root          59724 9月  18 21:17 storage.json
-rw-------  1 root          root            406 9月  18 21:18 TransportSecurity
drwxr-xr-x  4 root          root           4096 9月  18 21:17 User

step 3:

root@tdar-srv:/home/decisionmaker/.vscode# ls -al | grep root | awk '{print $9}'
Backups
blob_storage
Cache
CachedData
CachedExtensions
Code
Cookies
Cookies-journal
Crash
Dictionaries
exthost
GPUCache
languagepacks.json
Local
logs
machineid
Network
rapid_render.json
Session
storage.json
TransportSecurity
User

step 4:

root@tdar-srv:/home/decisionmaker/.vscode# ls -al | grep root | awk '{print $9}' | xargs 
Backups blob_storage Cache CachedData CachedExtensions Code Cookies Cookies-journal Crash Dictionaries exthost GPUCache languagepacks.json Local logs machineid Network rapid_render.json Session storage.json TransportSecurity User

step 5:

root@tdar-srv:/home/decisionmaker/.vscode# ls -al | grep root | awk '{print $9}' | xargs rm -rf

相关推荐

PC也能装MAX OS X

MACBOOK向来以其时尚的外观以及易用的OSX操作系统成为了时(zhuang)尚(bi)人士的最爱。但是其动不动就上万元的昂贵价格,也将一批立志时(zhuang)尚(bi)人士的拒之门外。但是最近...

一千多元的笔记本能买吗?英特尔11代+大屏幕,豆小谷值得选吗?

前言:有很多粉丝都问过本人,一千多元到底能买到什么样的笔记本?在此笔者只想说,这样的资金预算真的太低了!如果想买全新的,那大概率买的就是性能比较拉垮的上网本,比如搭载英特赛扬N系列、J系列处理器的轻薄...

首款配备骁龙X Elite处理器的Linux笔记本:采用KDE Plasma桌面环境

德国Linux硬件供应商TUXEDOComputers宣布正在开发一款配备高通骁龙XElite处理器(SnapdragonXEliteSoC)的ARM笔记本电脑,内部将该...

System76推出Gazelle Linux笔记本:配酷睿i9-13900H处理器

IT之家3月30日消息,主打Linux硬件的厂商System76于今天发布了新一代Gazelle笔记本电脑,共有15英寸和17英寸两个版本,将于3月30日接受预订,...

Kubuntu Focus Xe Gen 2笔记本发布,预装Linux系统

IT之家3月25日消息,KubuntuFocusXeGen2笔记本于近日发布,这是一款预装Kubuntu22.04LTSGNU/Linux发行版的轻薄本。上一代Kub...

这台Linux笔记本已用上英特尔12代酷睿,最高可选i7-1255U、卖1149美元起

Linux笔记本可能因为比较小众,一般都是拿Windows笔记本换个系统而来,硬件上也会落后同期Windows笔记本一两代,不过现在专门做Linux电脑的System76,推出了一款名为LemurP...

戴尔Inspiron 14 Plus骁龙笔记本迎新补丁,支持启动Linux

IT之家4月25日消息,科技媒体phoronix今天(4月25日)发布博文,报道称最新发布的Linux内核补丁,针对骁龙芯片的戴尔Inspiron14Plus笔记本,让其...

TUXEDO推出InfinityFlex 14二合一Linux笔记本,配i5-1335U

IT之家8月12日消息,Linux硬件企业TUXEDO当地时间本月2日推出了InfinityFlex14二合一Linux笔记本。该笔记本搭载2+8核的英特尔酷睿i5-...

登月探测器嫦娥使用什么操作系统,是Linux还是其它自主研发?

这是不是国家机密啊。事实什么样的不知道,但是从美国的探测器来看,就算不是也是相似的东西。下面我来说说我知道的。龙芯已经随北斗卫星上天了.就算登月探测器嫦娥是用"龙芯+Linux"也不出奇.没必要...

DNS分离解析实验

如果本文对你有帮助,欢迎关注、点赞、收藏、转发给朋友,让我有持续创作的动力目录一、分离解析概述二、实验需求三、实验步骤3.1双网卡服务器配置3.1.1添加两张网卡(内外网)3.1.2对两个网卡进...

一个小实验巩固下进程管理

先回顾下之前的三篇文章:Linux进程在内核眼中是什么样子的?Linux进程线程是如何创建的?Linux是如何调度进程的?通过这三篇文章的学习我们知道,无论内核进程还是用户进程,都是可以用task...

VMware Kali无线WIFI密码破解

WIFI破解前准备工作一张支持Kali系统监听的无线网卡VMware虚拟机安装好Kali系统(本实验用的是Kali2022版本)Kali系统下载、安装官方网站:https://www.kali.or...

python多进程编程

forkwindows中是没有fork函数的,一开始直接在Windows中测试,直接报错importosimporttimeret=os.fork()ifret==0:...

拔电源十台电脑藏后门!德国实验惊曝Windows致命漏洞

2025年4月15日,央视突然曝出一个超级大新闻!原来美国国家安全局通过黑龙江,往微软Windows系统里发送加密信息,激活了系统里藏着的后门程序,想破坏哈尔滨亚冬会!这消息一出来,大家才发现,竟然已...

深度探索RK3568嵌入式教学平台实战案例:设备驱动开发实验

一、产品简介TL3568-PlusTEB人工智能实验箱国产高性能处理器64位4核低功耗2.0GHz超高主频1T超高算力NPU兼容鸿蒙等国产操作系统二、实验目的1、熟悉基本字符设备的驱动程序...