Linked Questions

165
votes
6answers
17k views

Why is looping over find's output bad practice?

This question is inspired by Why is using a shell loop to process text considered bad practice ? I see these constructs for file in `find . -type f -name ...`; do smth with ${file}; done and for ...
6
votes
3answers
14k views

For loop in Unix : including files from sub directories [duplicate]

A simple for loop in Unix would be: for FILE in $BASE_WORK_DIR/*.pdf do echo $FILE done This will echo all .pdf files inside BASE_WORK_DIR directory. What if BASE_WORK_DIR contains sub ...
2
votes
6answers
12k views

How do I deal with directories that have spaces in their names from `find`? [duplicate]

I have this: #!/bin/bash for file in `find . -type d` do echo $file done If I have just one directory called My Directory, the output is My Directory How do I fix this? The echo $file is just ...
3
votes
2answers
20k views

passing filename with spaces to a shell script [duplicate]

The shellscript is very simple: retroarch $* -c /tmp/retroarch/Data/retroarch/gambatte.cfg ("retroarch" is another shellscript) If the filename passed contains spaces it fails: RetroArch [ERROR] ::...
2
votes
3answers
1k views

Find and rename files (including directories) whose filenames contain space [duplicate]

I have quite a number of files and directories with spaces in their filenames in my ext4 filesystems. How should I safely find and rename them? I have bash and am running Ubuntu. Is it possible ...
0
votes
1answer
918 views

Replacing white-space / characters with backslashes [duplicate]

I want to convert a bunch of mkvs to mp4s with the following command: for i in $(ls *mkv); do ffmpeg -i $i -vcodec copy -acodec copy $i.mp4; done; However, the filenames have whitespaces and hyphens ...
1
vote
1answer
1k views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f -mmin ...
0
votes
1answer
1k views

Spaces in directory name Bash [duplicate]

I'm new to bash and I'm working on script that traverses the tar.gz file archive and in each file changes a string specified to an another string. Args of script: name of archive, searched string, ...
0
votes
1answer
989 views

How to ignore spaces in file path for bash select statement [duplicate]

I have the following Bash Script: #!/bin/bash cd ~/Library/Developer/CoreSimulator/Devices/; files=$(find . -name iaGambro_gambro.sql) select file in $files; do if [ -n "$files" ]; then ...
0
votes
1answer
49 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 ...
36
votes
4answers
40k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using a ...
10
votes
5answers
9k views

using stat to provide timestamp for touch

Am trying to OCR some documents insitu (from a linux command line on a windows share). The process of OCRing is find and I have muddled through using the find command to pipe the files through the ...
10
votes
2answers
2k views

Why is $'\0' the same as ''?

A common way to do things with a couple of files is—and don't hit me for that: for f in $(ls); do … Now, to be safe against files with spaces or other strange characters, a naive way would be to do: ...
4
votes
3answers
9k views

Count number of characters per listed filename

Given the following ls result: $ ls Desktop Documents Downloads Music Pictures Public Templates Videos This will give the total number of characters for all files: $ ls | wc -m 67 But how ...
4
votes
6answers
11k views

Loop in text files shell script

I have a list of files in one directory and a set of jpegs corresponding to each file in another directory. I need to loop over all files, and for each file name, determine the target directory. For ...

15 30 50 per page