Find and rm files with spaces in the name


 
Thread Tools Search this Thread
Operating Systems AIX Find and rm files with spaces in the name
# 8  
Old 11-20-2014
I didn't mention this is AIX 5.3.

Apparently -maxdepth is not a valid option on this flavor of AIX. Smilie
Code:
# find . -maxdepth 1 -prune -type f
find: 0652-017 -maxdepth is not a valid option.

# 9  
Old 11-20-2014
Well...ain't that somethn'

There is an -xdev option: ( the order matters as you know )
Change echo to rm if it works...
Code:
find . -xdev -type f -name "* *" -exec echo {} \;

Have a look here and locate the find command.
AIX Commands Support Tips
or
IBM Systems Magazine - Search Smarter with the find command | AIX | IBM Systems Magazine | System p, System p5, Power System | find, command, search

Last edited by ongoto; 11-20-2014 at 05:29 PM..
# 10  
Old 11-20-2014
Find every file that meets your mod time/age requirement, use "sed" to remove the leading "./" characters, remove any names that still have a '/' directory separator in them, and remove what's left:

Code:
find . -mtime N -type f -name '* *' | sed 's/\.\///g' | grep -v '/' | while read ff; do rm "$ff"; done

# 11  
Old 11-20-2014
Been busy in meetings and calling it a day - finally. Will take a look at the recent suggestions tomorrow and let you know the results.

Again, thanks for the suggestions/examples. At the very least I'm learning more about this environment and sharpening the knife of my *NIX knowledge. Smilie
# 12  
Old 11-21-2014
The find -xdev primary only helps if the subdirectories are all mount points for different filesystems. However, the following command should do what you want:
Code:
find . \( -type d  ! -name . -prune \) -o \( -type f -name '* *' -mtime +30 -exec echo rm {} + \)

If the output correctly shows the rm command (or commands) you want to run, remove the echo and rerun the find.
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 11-21-2014
Quote:
Originally Posted by Papa Lee
Code:
# find ./* -prune -print
ksh: /usr/bin/find: 0403-027 The parameter list is too long.

It doesn't matter where you put the asterisk - as long as you put it anywhere it will expand to a long (and obviously too long) list of filenames.

The suggestion was to avoid the asterisk altogether, not to put it somewhere else in the command.

bakunin
# 14  
Old 11-21-2014
You are not printing anything because you're -prune-ing them all.

And then, you cram in too many arguments again, causing it to die from too many arguments.

Stop doing that.

Code:
find ./

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find and replace a string with spaces and / recursively?

Hi all, I wanted to find and replace an email id from entire directory structure on a Linux server. I found that find . -type f -print0 | xargs -0 sed -i 's/abc@yahoo.com/xyz@gmail.com/g' would do it perfectly. But my search criteria has extended and now I want to search for a string1 like... (2 Replies)
Discussion started by: pat_pramod
2 Replies

2. Shell Programming and Scripting

Loop with Find—damn spaces!

Hi Guys, I'm trying to find all files with a particular extension and then loop some actions. The problem is that if the files have spaces in their names I get end up being each word as a separate result rather than the entire file. ext=".txt" out=".rtf" for i in $( find "$1" -name "*$ext" );... (9 Replies)
Discussion started by: imonkey
9 Replies

3. Shell Programming and Scripting

How to find spaces and update values on the same line.

Dear all, I'm trying to write a script where: A file contains more or less 2000 lines. To some of those lines, in a specific position, let's say 89-92 there are spaces. So, this script should find these spaces on specific position and update a value (from 2 to 1) to another position of the... (4 Replies)
Discussion started by: paniklas
4 Replies

4. UNIX for Dummies Questions & Answers

Regular Expressions -- Find spaces outside

Hello, I need help with using grep and regular expressions.... I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt: 意文 yìwén (given name) 貴姓 guìxìng (honorable surname) 貴 guì (honorable) 姓 xìng (one's surname is; to be surnamed; surname) 呢 ne (interrogative... (2 Replies)
Discussion started by: arduino411
2 Replies

5. Shell Programming and Scripting

find -exec directories with spaces

All, I have a cleanup script that removes directories and all contents underneath, but I am having issues with directories with spaces. This is the command I am currently running, how can I get it to work with directories with spaces? find /path -mindepth 3 -type d -exec rm -rf {} \; (29 Replies)
Discussion started by: markdjones82
29 Replies

6. Shell Programming and Scripting

awk help with find command and filenames with spaces

I have the following code: find /usr/local/test5 -type f -mtime +30 -exec ls -l {} \; | awk '{print $5, $6, $7, $8, $9}' I have this as output: 14 Aug 12 00:00 /usr/local/test5/file1 14 Aug 12 00:00 /usr/local/test5/lastname, The bolded part is where I run into trouble. The actual... (4 Replies)
Discussion started by: streetfighter2
4 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. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

9. UNIX for Dummies Questions & Answers

For loop using find with file name spaces

Hello All, This question is actually for the service console of VMware ESX 3.5 but is relevant to this forum I think. I have been advised to use the following commands: for i in `find /vmfs/volumes/Test_VMFS/ -name "*.vmx"` do echo "$i" #sed -i 's/scsi1:0.present =... (3 Replies)
Discussion started by: mronsman
3 Replies

10. UNIX for Dummies Questions & Answers

Find fields with no spaces in value

This is what I need to do I have a file that has a field with values like this 1111 2222 3333 4444 55555 666 333333333 444444444 I need for my command to out put only those fields that do not have spaces in them. So my output for the above file would be 333333333 444444444 how... (10 Replies)
Discussion started by: alfredo123
10 Replies
Login or Register to Ask a Question