ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cat doppelte-Dateien.log|while read f; do
if [ -e "$f" ]; then rm -f "$f"; fi; done
or
Code:
cat doppelte-Dateien.log|xargs -iF rm -f 'F'
BTW's: watch out for relative paths is you use current working directory "find . -type". You can pipe sort into uniq. Also try to use "mktemp" for tempfiles: works "better" when you script more.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
One BIG FAT WARNING if you do rm in scripts:
The bash shell scripting language is such that if you make a little mistake with one small character, the command can be entirely different.
Especially when a command like rm is involved.
It happened to me that I wiped out the entire directory I was working in, including my 250 line script I was working on at that moment. I think I forgot a quote or so
It is better to put this somewhere at the start:
Code:
RM=/usr/bin/echo
#RM=/usr/bin/rm
..your code here..
#finally THE command:
$RM whatever.files
If you are 100% sure that the code does what your expect, uncomment the /usr/bin/rm, and comment the /usr/bin/echo
I like jlinkles idea. I have been preceding the rm command with echo to see what the entire command would look like.
But then, I usually do this interactively instead of from a script.
I would add to his/her sig: If your question is about awk, read "Gawk: Effective Awk Programming" from the gawk-doc package.
If the filenames contain whitespace, you need to pipe the filelist through "tr".
cat doppelte-Dateien.log | tr '\n' '\000' | xargs -0 rm -f
If there are thousands of files in the list, then you also want to use one of the input limiting options to xargs.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by jschiwal
I would add to his/her sig: If your question is about awk, read "Gawk: Effective Awk Programming" from the gawk-doc package.
That's funny... the contents is almost the same as the GAWK user manual, but not quite. Unusual in the community to have two versions of a document, not verbatim equal.
One closer inspection, one of them may be a version of the gawk book I was referring to, but looks a lot different from the version that I printed. A version of a document produced with "make pdf" from the source may contain much more information from the info version.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.