Shell script to delete multiple files

pickles

So, I have a file which contains a list of hundreds of files that need to be deleted from various directories. I figured the easiest method would be to create a batch file but I'm not having great success.

#/bin/bash
rm "/home/e-smith/files/users/bill/Maildir/cur/1392373930.28512.comp01:2,S"
rm "/home/e-smith/files/users/ted/Maildir/cur/1420726198.17690.comp01:2,S"

But when I run the script with

./myfile.txt

I get

rm: cannot remove '/home/e-smith/files/users/bill/Maildir/cur/1392373930.28512.comp01:2,S\r': no such file or directory
rm: cannot remove '/home/e-smith/files/users/ted/Maildir/cur/1420726198.17690.comp01:2,S\r': no such file or directory

I don't understand where the \r is coming from, I'm guessing it's a carriage return but it appends itself to the command.

What is the correct method/syntax for an exercise like this?

Gert

This is due to the line-endings that Windows uses (\r\n).

You can remove thes via vi:

$ vi myfile.txt
<ESC>
:set fileformat=unix
:wq

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Mac shell script to delete files

shell script run multiple files

Optimise a shell script / command to delete files

Shell script to delete files when disk is full

Shell script to delete oldest files and folders

shell script to delete certain files and rename others

Multiple files rename using linux shell script

Insert Into Multiple Files in Windows shell script

Shell script to input multiple files into program C

shell script to check for multiple files with different names

Rename multiple files via shell script

A shell script to run tabix command on multiple files

Linux shell script to copy and rename multiple files

Using shell script to sort files then delete old files

Shell Script for Delete all files in directory and print count of deleted files

Too many files to delete (rm) with wildcard in a shell script?

Shell script to delete whose files names are not in a text file

Shell script: Delete files when folder with same name does not exist

Delete files older than 10 days using shell script in Unix

Delete old files from ftp using shell script

shell script to convert .xls to .csv and then delete the .xls files that are converted?

Linux Bash Shell Script - To Find Files with Zero Size and Delete

shell script delete on date

Shell script to rename multiple files from their parent folders name

Put shell script for loop statement for multiple files in a function

Shell script/command for replacing a (single) string in multiple files?

How to run multiple .java files using shell script?

Shell script to copy and prepend folder name to files from multiple subdirectories

Rename multiple files by replacing a particular pattern in the filenames using a shell script