在bash中查找和删除.txt文件 [英] Find and delete .txt files in bash

查看:67
本文介绍了在bash中查找和删除.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
命令行:通过管道将结果查找到rm

最近我的外部硬盘驱动器上的照片被分区分区整理了(无论如何,大多数都是DVD光盘,但是..).

recently frigged up my external hard drive with my photos on it (most are on DVD anyway, but..) by some partition friggery.

幸运的是,我能够将PhotoRec与另一个Unix分区实用程序和PDisk放在一起.

Fortunately I was able to put things back together with PhotoRec another Unix partition utility and PDisk.

PhotoRec返回了1000多个文件夹,其中充满了从.txt文件到重要的.NEF文件的所有内容.

PhotoRec returned over one thousand folders chalk full of anything from .txt files to important .NEF's.

所以我试图通过使用unix来使排序更容易,因为OSX Finder只会在选择和删除十亿个.txt文件的请求下崩溃.

So I tried to make the sorting easier by using unix since the OSX Finder would simply crumble under such requests as to select and delete a billion .txt files.

但是,当我尝试查找和删除txt文件,或将所有jpeg递归地移动并将其移动到名为jpegs的新文件夹中时,遇到了一些BS.我是unix菜鸟,所以需要一些帮助.

But I encounter some BS when I tried to find and delete txt files, or find and move all jpegs recursively into a new folder called jpegs. I am a unix noob so I need some assistance please.

这是我在bash中所做的事情.(我位于ls会列出我需要对其执行操作的所有文件夹和文件的目录中.)

Here is what I did in bash. (I am in the directory that ls would list all the folders and files I need to act upon).

查找.名称* .txt |rm

find . -name *.txt | rm

sudo查找.名称* .txt |rm -f

sudo find . -name *.txt | rm -f

因此,这给了我一些我需要取消链接文件的BS.随便.

So it's giving me some BS that I need to unlink the files. Whatever.

我需要以递归方式查找所有.txt文件,并最好将其删除.

I need to find all .txt files recursively and delete them preferably verbose.

谢谢.

推荐答案

您不能将文件名通过管道传输到 rm .您需要改用 xargs .另外,请记住引用文件模式.txt" ,否则shell会对其进行扩展.

You can't pipe filenames to rm. You need to use xargs instead. Also, remember to quote the file pattern ".txt" or the shell will expand it.

find . -name "*.txt" | xargs rm

这篇关于在bash中查找和删除.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆