rm

Delete files with string found in file - linux cli

*爱你&永不变心* 提交于 2019-11-29 19:32:10
I am trying to delete erroneous emails based on finding the email address in the file via Linux CLI. I can get the files with find . | xargs grep -l email@domain.com But I cannot figure out how to delete them from there as the following code doesn't work. rm -f | xargs find . | xargs grep -l email@domain.com Thank you for your assistance. For safety I normally pipe the output from find to something like awk and create a batch file with each line being "rm filename" That way you can check it before actually running it and manually fix any odd edge cases that are difficult to do with a regex

How to remove files and directories quickly via terminal (bash shell) [closed]

末鹿安然 提交于 2019-11-29 18:33:58
From terminal window: When I use the rm command it can only remove files. When I use the rmdir command it only removes empty folders. If I have a directory nested with files and folders within folders with files and so on, is there any way to delete all the files and folders without all the strenuous command typing? If it makes a difference, I am using the mac bash shell from terminal, not Microsoft DOS or linux. rm -rf some_dir -r "recursive" -f "force" (suppress confirmation messages) Be careful! rm -rf * Would remove everything (folders & files) in the current directory. But be careful!

How to recover the deleted files using “rm -R” command in linux server? [closed]

不羁的心 提交于 2019-11-28 23:19:25
I have unfortunately deleted some important files and folders using 'rm -R ' command in Linux server. Is there any way to recover? since answers are disappointing I would like suggest a way in which I got deleted stuff back. I use an ide to code and accidently I used rm -rf from terminal to remove complete folder. Thanks to ide I recoved it back by reverting the change from ide's local history. (my ide is intelliJ but all ide's support history backup) Short answer: You can't. rm r e m oves files blindly, with no concept of 'trash'. Some Unix and Linux systems try to limit its destructive

git - how to remove empty folder and push that change?

人走茶凉 提交于 2019-11-28 16:56:20
问题 How can I remove an empty folder locally and also have that happen for other collaborators that share the remote via pull-push? I know that folders aren't 'tracked' in that sense by git but the question remains. e.g. I moved a file to another folder and committed the change (of the move). But I can't git rm name the folder as I get "doesn't match" git rmdir name doesn't exist. I can do a git clean -f folder but how does that get pushed up? I can directly rm the file but how do I get that

Linux why can't I pipe find result to rm?

孤街浪徒 提交于 2019-11-28 16:11:54
sorry if this is a noobie question but I can't find a good answer. To find then remove something I can use find . -name ".txt" -exec rm "{}" \; But why can't I just pipe the results to rm like find . -name ".txt" | rm like I would pipe it to grep find . -name ".txt" | grep a I've read from somewhere that rm doesn't take input from stdin and therefore I can't pipe it but what does that mean? When I type in rm a.txt it reads from standard input just like I can grep right? Or is there a difference between stdin and command line. Help! Tim Pierce To expand on @Alex Gitelman's answer: yes, there's

Linux delete file with size 0 [duplicate]

放肆的年华 提交于 2019-11-28 15:11:55
This question already has an answer here: How to delete many 0 byte files in linux? 10 answers How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script. l filename.file | grep 5th-tab | not eq 0 | rm Something like this? This will delete all the files in a directory (and below) that are size zero. find /tmp -size 0 -print0 |xargs -0 rm -- If you just want a particular file; if [ ! -s /tmp/foo ] ; then rm /tmp/foo fi James.Xu you would want to use find : find . -size 0 -delete To search and delete empty files in the current

How to remove files and directories quickly via terminal (bash shell) [closed]

旧城冷巷雨未停 提交于 2019-11-28 13:08:31
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . From terminal window: When I use the rm command it can only remove files. When I use the rmdir command it only removes empty folders. If I have a directory nested with files and folders within folders with files and so on, is there any way to delete all the files and folders without all the strenuous command

Command line: piping find results to rm

折月煮酒 提交于 2019-11-28 02:46:01
I'm trying to work out a command which deletes sql files older than 15 days. The find part is working but not the rm. rm -f | find -L /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups -type f \( -name '*.sql' \) -mtime +15 It kicks out a list of exactly the files I want deleted but is not deleting them. The paths are correct. usage: rm [-f | -i] [-dIPRrvW] file ... unlink file /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups/20120601.backup.sql ... /usr/www2/bar/htdocs/foo/rsync/httpdocs/db_backups/20120610.backup.sql What am I doing wrong? You are actually piping rm 's output to the input

How to recover the deleted files using “rm -R” command in linux server? [closed]

佐手、 提交于 2019-11-27 21:13:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have unfortunately deleted some important files and folders using 'rm -R ' command in Linux server. Is there any way to recover? 回答1: since answers are disappointing I would like suggest a way in which I got deleted stuff back. I use an ide to code and accidently I used rm -rf from terminal to remove complete

Calling rm from subprocess using wildcards does not remove the files

白昼怎懂夜的黑 提交于 2019-11-27 14:45:06
问题 I'm trying to build a function that will remove all the files that start with 'prepend' from the root of my project. Here's what I have so far def cleanup(prepend): prepend = str(prepend) PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) end = "%s*" % prepend cmd = 'rm' args = "%s/%s" % (PROJECT_ROOT, end) print "full cmd = %s %s" %(cmd, args) try: p = Popen([cmd, args], stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True).communicate()[0] print "p", p except Exception as e: print