Title: How to embed data uri in css files automatically in a directory with many subdirectories?
Tags: css;linux;bash;shell;data-uri
Question: I am using cssembed to encodes all image references in the css files to base64 and replace the original css file with the changes. However, what I want to do is automate the process for all the css files in my folder with many subfolders/subdirectories.  I tried the following:

```java -jar cssembed-0.4.5.jar *.css &gt; *.css
```

But it produces the following output:

```bash: *.css: ambiguous redirect
```

I also tried 

```java -jar cssembed-0.4.5.jar *.css
```

But this only outputs the result in the terminal , does not replace the file with the encoded bits.

How to solve this ? Any suggestions?

NOTE: I am trying to do this on Ubuntu terminal.



Here is another answer: You can use ```find``` to locate all files in all subdirectories too:

```find -name "*.css" -exec java -jar cssembed-0.4.5.jar '{}' &gt; tmp \; -exec mv tmp '{}' \;
```

Here ```tmp``` is a temporary file that is written to, which is necessary because when you use ```&gt;``` the file you are writing to is truncated immediately. The second ```-exec``` is only run if the first one returns successfully, overwriting the original file with the contents of ```tmp```.

If the code above isn't working for you, perhaps you could try this:

```find -name "*.css" -exec sh -c 'java -jar cssembed-0.4.5.jar "$0" &gt; tmp &amp;&amp; mv tmp "$0"' '{}' \;
```

This invokes a separate shell for each file that is found. ```$0``` is the name of the file that has been found.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:02/05/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<css><linux><bash><shell><data-uri>', 'Title': 'How to embed data uri in css files automatically in a directory with many subdirectories?', 'ViewCount': 53, 'id': 28349494, 'user_AboutMe': '', 'user_AccountId': 2888715.0, 'user_DisplayName': 'HackCode', 'user_Reputation': 1827.0, 'user_Views': 586.0, 'user_id': 2477978.0}}