Linked Questions

134
votes
10answers
168k 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 $...
3
votes
2answers
365 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 ...
2
votes
3answers
99 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
2answers
183 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
3answers
92 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 ...
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 ...
1
vote
1answer
33 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
0answers
38 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 --...
425
votes
6answers
676k views

How to run find -exec?

I'd like to find the files in the current directory that contain the text "chrome". $ find . -exec grep chrome find: missing argument to `-exec' What am I doing wrong?
199
votes
8answers
32k views

Why *not* parse `ls` (and what do to instead)?

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with ...
262
votes
4answers
203k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
186
votes
4answers
35k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
132
votes
6answers
57k views

When is xargs needed?

The xargs command always confuses me. Is there a general rule for it? Consider the two examples below: $ \ls | grep Cases | less prints the files that match 'Cases', but changing the command to ...
84
votes
6answers
243k views

How to merge all (text) files in a directory into one?

I've got 14 files all being parts of one text. I'd like to merge them into one. How to do that?
44
votes
15answers
24k views

How can I delete a file which filename has non-printing characters

I somehow managed to create a file that doesn't seem to have a filename. I found some information regarding how to get more details of the file in the following thread. However, I tried some of the ...

15 30 50 per page