Linked Questions
260 questions linked to/from Why is looping over find's output bad practice?
240 votes
9 answers
328k views
Looping through files with spaces in the names? [duplicate]
I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff $...
4 votes
2 answers
3k views
shellcheck warns about loops over find output even when given the path to begin search [duplicate]
Ubuntu 16.04 #!/bin/bash site="hello" wDir="/home/websites/${site}/httpdocs/" for file in $(find "${wDir}" -name "*.css") do echo "$file"; done exit 0; shellcheck warns me even if I define the ...
3 votes
1 answer
2k views
Handle names with spaces when iterating recursively over files [duplicate]
I am trying to recursively convert all .mkv files in a folder structure with subfolders to .mp4. I got a standard line that works in just the present folder for video in *.mkv; do ffmpeg -i "$...
3 votes
2 answers
2k views
Why I should avoid loops in shells? [duplicate]
The following link recommends against using loops in shells. bash variables in for loop range Why is this? Here is an example loop I just happened to be looking at when I came across that answer: ...
2 votes
3 answers
420 views
How to modify a find function loop to handle backslashes and whitespaces? [duplicate]
Currently, I am trying to parse out all the files inside a directory. I have a find function, but it appears to not be able to parse in file directories with whitespaces into a loop. Here, "$DIR" is ...
1 vote
3 answers
678 views
Fix space in path from find command [duplicate]
I would like to copy many files with the below command. cp `find /Volumes/DATA/ -name "*.app" -depth 1 2> /dev/null` /Volumes/VMWare/img/ But that doesn't work because if it finds a space then it ...
1 vote
2 answers
561 views
Can a pipe be used instead of exec in - find / -name “.txt” -exec cp {} /junk \; [duplicate]
If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder, I understand I could use the following: find / -name ".txt" -exec cp {} /junk \; ...
0 votes
1 answer
773 views
remove spaces in filenames in find output [duplicate]
I want to list the size of directories under a given root (using du -hs) . The issue is that where the directory names have spaces the du command is getting each word of the name as a whole directory ...
1 vote
3 answers
139 views
A for-do loop not working for filenames containing a space [duplicate]
for X in $(find ~/Documents/ -type f);do date -r "${X}";done The above line works fine when the filenames in "/Documents/" contain no space. However, if the filenames contain a ...
0 votes
0 answers
802 views
Shell scripting with brackets/parenthesis in folder names [duplicate]
I have a music library that I am trying to restore from backup. The original source library was on a QNAP NAS and I copied it over to a CentOS system without any problems. Now that I am trying to copy ...
0 votes
1 answer
130 views
Problem using find with filenames containing spaces [duplicate]
I'm trying to run join a bunch of files using the find command. I have determined that filenames containing spaces are giving me a problem. The following comand works for files that do not contain ...
1 vote
1 answer
95 views
How to match files that have spaces in their file naming format [duplicate]
I have a file test.txt which contains file names like below where some file names will have spaces and some will not. Mon - Tue corrected item.csv Sat -Sun incorrect item.csv Wed_THU_corrected_item....
0 votes
0 answers
104 views
Working with strange filenames [duplicate]
How can the script below be made to always work no matter the filenames returned by find ? #!/bin/sh cmds_should_always_work() { echo "\n\n*********************************" $1 stat --...
0 votes
1 answer
74 views
How to loop over subdirectories and perform action while ignoring spaces in file names [duplicate]
I have the below folder structure in Linux env: |-- Fixed_Zip | |-- ipython_notebooks | | |-- notebook editor for compute_0anXhGEj.ipynb | | |-- notebook editor for compute_aucScores.ipynb | ...
0 votes
0 answers
19 views
Loop through files from current directory and subdirectories [duplicate]
I'm trying to loop through each files from current directory and subdirectories. But the problem is file names with blank-space are getting treated as separate files. How do I prevent that. I want to ...