# Tag Info

0

Deleting a file inturn translates to vfs_unlink and then fs specific fs_unlink system call to get executed. Precisely these calls get to parent directory and removes the inode of corresponding file causing that file's dentry to become negative. The data on disk(whatever size it is of) remains as it is, with only one change: block where it's residing are ...

2

rm deletes files regardless of their size. Very large files can take a little time to delete, because the filesystem needs to mark all the blocks that the file used as available. That cost has to be paid at one time or another; if you don't pay it at deletion time, you pay it when files are created. Zfs offers a way to defer the cost of deleting a directory ...

0

I ran into problems using find with -delete due to the intentional behavior of find (i.e. refusing to delete if the path starts with ./, which they do in my case) as stated in its man page: -delete Delete found files and/or directories. Always returns true. This executes from the current working directory as find recurses down the tree. It will ...

3

-size with a suffix of b is for 512-byte blocks, not bytes. 5000000b is 2,560,000,000 bytes or 2.5 GB Try: find /home -size +5M -name "error_log" -exec rm -rf {} \; From the GNU find man page: -size n[cwbkMG] File uses n units of space. The following suffixes can be used: b' for 512-byte blocks (this is the default if no suffix is ...

1

Making rm prompt for confirmation (as in Rui F Ribeiro's answer) will get you in the habit of depending on that. Then should you ever log in to a different system, you'll be in for an unwelcome surprise. Instead, I'd suggest retraining yourself—two approaches come to mind: One, which you suggested, is to make rm just not work. That's fairly easy, alias ...

2

Usually a good strategy, and specially to users with admin privileges, is aliasing the rm command to rm -i, that requires confirmation. place it on your .bashrc alias rm='rm -i'

0

Using ricchard's idea removing all except last in month: rm -f ls *.sql | sort | uniq w11 -D -u` To view what will be deleted: ls *.sql | sort | uniq w11 -D -u

1

if rm -rf directoryname fails you, try using rm -R -f directoryname, or rm --recursive -f directoryname. If you are not having any luck with these, you should consider reinstalling rm or switching shells.

0

how about running a file system check on the SD card? insert the card and under linux run fsck /dev/mmcblk01p1 for example. If you're note sure what's the name of the device name given, just see dmesg upon inserting the card. Aaand do not forget to umount it prior fsck

0

I had a similar issue with my SD card recently. I was not able to fix it under Linux. However, as soon as I plugged the card into a Windows machine, the system came up with a message asking whether I want to repair the card as apparently it was not unmounted correctly. The repair under Windows helped.

0

find . -depth -type d -exec rmdir {} + is the simplest and standard compliant answer to this question. The other answers given here unfortunately all depend on vendor specific enhancements that do not exist on all systems.

1

Under bash, you can bypass an alias by prepending a \ to the command, so rm filename becomes \rm filename

10

GNU rm supports -i, which I assume is what you are referring to and asks for confirmation for each file, but also -I, which is a little different: -I prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giv‐ ing protection against most mistakes As to whether it's ...

2

with Ctrl+c you will be able to cancel the operation. But if you look in your .bashrc file, you can comment the alias that force the confirmation, it use the -i param as expained dhag. in you .bashrc you will find a entry like this : alias rm='rm -i' if you comment it, your rm -f will works directly

17

To accomplish request 1 you will need to use a more sophisticated program than yes to send y N number of times and then pass keyboard input through beyond that. You can't do it with rm except to always ask (rm -i) or to never ask (rm -f). You can always abort rm by pressing Control-C to interrupt it (sends SIGINT), pressing Control-Z to stop it (sends ...

4

Another quickie, also without an explicit loop. Don't forget, you can prefix the rm -f with echo to test this out. ( cd dir2 && find . -maxdepth 1 -type f -print0 ) | ( cd dir1 && xargs -0 rm -f ) You can put this into a script, replacing dir1 with "$1" and dir2 with "$2"

-1

Use rsync : rsync --verbose --remove-source-files xyz/* . pop3-2.dump pop3-3.dump pop3.dump popcorn-build.log sent 852,069,995 bytes received 124 bytes 113,609,349.20 bytes/sec total size is 851,861,745 speedup is 1.00

0

Quick answer... #!/bin/bash #finddel dir1 dir2 for i in $(ls$1) do [ -f $2/$i ] && echo "Deleting $2/$i" && rm -f $2/$i done

4

To handle filenames with spaces: #!/bin/bash OPWD=$(pwd) cd "$1" for MYFILE in "$2"/* do if [ -f "${MYFILE##/*/}" ] then echo "removing ${MYFILE##/*/}" rm "${MYFILE##/*/}" fi done cd "\$OPWD"

1

rsync can do this with the --existing option: rsync -v --existing dir2/* dir1/

2

Actually, there's a single command that does exactly what you're asking. rsync -av --existing dir2/ dir1/ This will recursively copy the files from dir2 into dir1 only if the file already exists in dir1. The -av options are the options you'll usually use for copying files using rsync. The --existing option tells rsync to skip creating new files on ...

Top 50 recent answers are included