find -exec directories with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find -exec directories with spaces
# 22  
Old 03-16-2010
FWIW - there is no one implementation of find, or ls or xargs. Solaris has oddities buried in its core utils code, as does linux, HPUX and so on. The reason for this is usually cited as backwards compatibility.

So, reading Solaris find code tells you nothing about GNU find, for example. Not to mention the "family tree" differences in UNIX.
# 23  
Old 03-16-2010
Quote:
Originally Posted by radoulov
This is not true:

Code:
; find /tmp -type d -exec ls -ld {} +
syntax error
; find /tmp -type d -exec ls -ld '{}' +
drwxrwxrwt+ 1 sysadmin root 0 2010-03-16 17:01 /tmp
; echo $version
1.7.1 $Release: @(#)rc 1.7.1 2003-07-17 $

I think you'll get the same or similar error with es.
Granted. Thanks for reminding these is at least one of these beasts around. Plan 9 CLI does indeed interpret the curly braces. I forgot that but I doubt the open poster is using such an exotic shell.

This doesn't change my point single quoting curly braces alone has no effect whatsoever with find and embedded spaces and your second example is precisely supporting it:
Code:
$ find . -type f -ls
1096125622    0 -rw-r--r--   1 jlliagre jlliagre        0 Mar 16 22:01 ./a\ b
$ gfind . -type f -exec bash -c f={} - \;
-: b: command not found
$ gfind . -type f -exec bash -c 'f={}' - \;
-: b: command not found

You need to quote the quotes themselves for the exec subcommand to get them but this is a different issue and it appears with any shell.

---------- Post updated at 22:18 ---------- Previous update was at 22:12 ----------

Hmm, a closer look at the initial command makes me think it is broken anyway:

Code:
find /path -mindepth 3 -type d -exec rm -rf {} \;

There is a race condition. Find is at the same time exploring directories and removing them recursively. This can't work reliably and has nothing to do with embedded spaces in filenames.

Last edited by jlliagre; 03-16-2010 at 06:24 PM..
# 24  
Old 03-16-2010
Quote:
Originally Posted by jlliagre
[...]
This doesn't change my point single quoting curly braces alone has no effect whatsoever with find and embedded spaces and your second example is precisely supporting it:
Yes,
actually the example was a bit misleading (my fault), the file name doesn't matter in that case.

Quote:
Code:
$ find . -type f -ls
1096125622    0 -rw-r--r--   1 jlliagre jlliagre        0 Mar 16 22:01 ./a\ b
$ gfind . -type f -exec bash -c f={} - \;
-: b: command not found
$ gfind . -type f -exec bash -c 'f={}' - \;
-: b: command not found

You need to quote the quotes themselves for the exec subcommand to get them but this is a different issue and it appears with any shell.
I just wanted to show that in some situations you need to quote the braces.

---------- Post updated at 10:25 PM ---------- Previous update was at 10:24 PM ----------

Quote:
Originally Posted by jlliagre
[...]

Hmm, a closer look at the initial command makes me think it is broken anyway:

Code:
find /path -mindepth 3 -type d -exec rm -rf {} \;

There is a race condition. Find is at the same time exploring directories and removing them recursively. This can't work reliably and has nothing to do with embedded spaces in filenames.
Yep,
and this was already pointed out.
# 25  
Old 03-16-2010
Indeed, I missed posting #13. I was more (over)reacting to that {} myth being back on topic than following the thread. Alister got it definitely right.
# 26  
Old 03-16-2010
@jilliagre

Welcome back to this debate. I enjoyed the previous one.
However I must quote myself:
Quote:
Post #12

Thank you markdjones82 for your response.
It is clear that this is not a '{}' issue.
I continue to be interested in variations in unix which would be relevant to writing portable shell script or diagnosis of failures.

Yet again we find ourselves not knowing what Operating System the O/P is using or what variation and vintage of "bash".
There is also uncertainty about whether this command behaved the same when run from cron or shell.
This lack of basic information in posts such as this implies that many people believe that all unix and Linux commands behave the same. They don't.
These are living Operating Systems which undergo continuous improvement and change.

On the point of {} or '{}' it is not a myth I still maintain that I have seen and repaired that problem before but cannot reproduce it in the modern Operating Systems which I have to hand. Quoting '{}' is even mentioned in current Linux "man find". A poster in this thread suggested '{}' as a solution.

I have cold build a wide variety of pre-unix O/S (including the original not-the-Mac OS/9), umpteen unix variants, mainstream manufacture unix, and assorted Linux systems.

I accept the quirks but also need to know about them.




radoulov post is very interesting and triggered a flashback to a mainstream manufacturer proprietary software suite which used to create directories and files according to whatever the user typed (complete with control codes and escape sequences). I'll play around with "find" and directories with duff names (rather than strictly files).

Last edited by methyl; 03-16-2010 at 08:27 PM.. Reason: Appended reference to radoulov post.
# 27  
Old 03-16-2010
Quote:
Originally Posted by methyl
On the point of {} or '{}' it is not a myth I still maintain that I have seen and repaired that problem before but cannot reproduce it in the modern Operating Systems which I have to hand. Quoting '{}' is even mentioned in current Linux "man find". A poster in this thread even suggested it as a solution.
High methyl, you won't be surprised that I maintain {} vs '{}' in the context of the find command and filenames with spaces can't be but a myth in any present or past Unix or Unix like Operating System implementation.
Please don't confuse people again with gnu find (and POSIX find) manual pages which indeed mention '{}' but for a unrelated potential issue with exotic shells. This issue is not related in any way with embedded spaces.
# 28  
Old 03-16-2010
@jlliagre
After the last debate ended I came across a diary entry about a replacement script I created to replace a manufacture-supplied one-line cron in DRS/NX following a spate of incidents when /tmp filled on multiple systems on multiple sites.
There was a pretty basic one-line "find ... exec rm {} \;" to remove files more than 7 days old. It failed with filenames containing spaces or non-printable characters.
You can guess the rest.

BTW: Before making sweeping statements what is your experience of DRS/NX , Unixware, AIX, RSX, Berkeley unix, and pure unix System V to name but a few? I don't count SunOS or Solaris in any of these categories.

Last edited by methyl; 03-16-2010 at 09:08 PM.. Reason: addressee
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directories having spaces

Hi I have a list file with complete path of files and there are directories with spaces. Now when i read the list file, read the line and read the file it says no file found because of the space. How can I get through this issues for file in $(<list_file.txt) do first_line=`head -1... (8 Replies)
Discussion started by: lijjumathew
8 Replies

2. Shell Programming and Scripting

Directories with spaces

My code path=`find /root/folder/ -maxdepth 100 -type d | sort --random-sort | head -1` if this returns a directory with spaces in for instance: /root/folder/this is a folder is there a way to replace the value of path with the same value but with the spaces replaced so its... (2 Replies)
Discussion started by: digitalviking
2 Replies

3. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

4. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

5. UNIX for Dummies Questions & Answers

Find Exec

Hello All, Is there a way to make exec do a couple of operations on a single input from find? For example, find . -type d -exec ls -l "{}" ";" I would like to give the result of each "ls -l" in the above to a wc. Is that possible? I want to ls -l | wc -l inside... (1 Reply)
Discussion started by: prasanna1157
1 Replies

6. Shell Programming and Scripting

How to find 777 permisson is there or not for Directories and sub-directories

Hi All, I am Oracle Apps Tech guy, I have a requirement to find 777 permission is there or not for all Folders and Sub-folders Under APPL_TOP (Folder/directory) with below conditions i) the directory names should start with xx..... (like xxau,xxcfi,xxcca...etc) and exclude the directory... (11 Replies)
Discussion started by: gagan4599
11 Replies

7. Shell Programming and Scripting

Script to find folders with spaces and end of files and directories

Hi I need a script that can search through a set of directories and can locate any file or directory that has a space at the end Filename(space) Foldername(space) I then need to remove that space within the script Hope someone can help thanks in advance Treds (8 Replies)
Discussion started by: treds
8 Replies

8. Shell Programming and Scripting

find & dirname:problems with white spaces in Directories

Hi all, my problem: (little extract from my bash-script) I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one); after moving i want to create hardlinks to the old directories. Thatīs no problem, but now: source-directories... (4 Replies)
Discussion started by: tubian
4 Replies

9. Shell Programming and Scripting

Directories with spaces in name - looking for help with questions in that issue

I need to work with 'nice' directory names which have some spaces in name, and that brings some questions and not-understanding. Would some expert help me out how to deal with that?! My task is to document some processing, running from some script. I do need to have spaces in directories... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. UNIX for Advanced & Expert Users

find and exec

Hi, Happy new year. Would you be so kind to explain me what does this instruction : find /rep/app -type l -exec ls -l {} \;> allink.lst Many thanks. (2 Replies)
Discussion started by: big123456
2 Replies
Login or Register to Ask a Question