# folder with 25000 rpm packages



## mfaridi (Mar 2, 2010)

I have one folder with 25000 rpm packages and I have some text and txt files too ,
I want find all text and sh anf txt files and copy them to another folder ,
searching them in 25000 packages is so hard and take long time.


----------



## graudeejs (Mar 2, 2010)

How about
`$ mv *.txt /some/path/`
Which will move all *.txt files


----------



## mfaridi (Mar 2, 2010)

killasmurf86 said:
			
		

> How about
> `$ mv *.txt /some/path/`
> Which will move all *.txt files



some files dose not have txt in end files
some text make by touch and dose not have .txt


----------



## graudeejs (Mar 2, 2010)

```
for i in `ls`; do
  if [ `file -ib $i | awk '{print [red]$i[/red]}'` == 'text/plain;' ]; then
    mv $i /some/path
  fi
done
```


----------



## mfaridi (Mar 2, 2010)

killasmurf86 said:
			
		

> ```
> for i in `ls`; do
> if [ `file -ib $i | awk '{print $1}'` == 'text/plain;' ]; then
> mv $i /some/path
> ...



when I run this command

```
sh ./move.sh
```
I see this error

```
[: application/x-empty: unexpected operator
[: video/x-unknown: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/octet-stream: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/xml: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/octet-stream: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/xml: unexpected operator
[: text/plain: unexpected operator
[: video/x-unknown: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: application/x-not-regular-file: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
/home/narges #
```
and this move.sh

```
for i in `ls`; do
  if [ `file -ib $i | awk '{print $1}'` == 'text/plain;' ]; then
    mv $i /home/narges/cod
  fi
done
```


----------



## sixtydoses (Mar 2, 2010)

This command will move all text files to /path/to/text/folder.

`$ find . \! -iname "*rpm" -type f -print0 | xargs -0 -I {} mv {} /path/to/text/folder`


----------



## graudeejs (Mar 2, 2010)

Fixed typo in my script


----------



## mfaridi (Mar 2, 2010)

killasmurf86 said:
			
		

> Fixed typo in my script



now I see this error

```
: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operator
awk: illegal field $(), name "i"
 input record number 1, file 
 source line number 1
[: ==: unexpected operato
```


----------



## avilla@ (Mar 2, 2010)

killasmurf86 said:
			
		

> Fixed typo in my script



use only one "=" in the if

anyway, i suggest using the command by sixtydoses


----------



## graudeejs (Mar 2, 2010)

crap, $1 was corret, there was other issue

```
for i in `ls`; do
  if [ `file -ib $i | sed 's/; .*//g'` = 'text/plain' ]; then
    mv $i /some/path
  fi
done
```

Now this should really work.


----------



## mfaridi (Mar 2, 2010)

killasmurf86 said:
			
		

> crap, $1 was corret, there was other issue
> 
> ```
> for i in `ls`; do
> ...



with this new script I see this error

```
move.sh" 5 lines, 117 characters
/home/Mostafa/code # sh ./move.sh
file: invalid option -- Ã˜
file: invalid option -- Â§
file: invalid option -- Ã™
file: invalid option -- Â…
file: invalid option -- Ã˜
file: invalid option -- Â§
file: invalid option -- Ã™
file: invalid option -- Â…
file: invalid option -- Ã›
file: invalid option -- ÂŒ
file: invalid option -- Ã™
file: invalid option -- Â‡
file: unrecognized option `--88.jpg'
Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
       file -C -m magicfiles
Try `file --help' for more information.
[: =: unexpected operator
file: invalid option -- Ã˜
file: invalid option -- Â§
file: invalid option -- Ã™
file: invalid option -- Â…
file: invalid option -- Ã˜
file: invalid option -- Â§
file: invalid option -- Ã™
file: invalid option -- Â…
file: invalid option -- Ã›
file: invalid option -- ÂŒ
file: invalid option -- Ã™
file: invalid option -- Â‡
file: invalid option -- .
file: invalid option -- j
file: invalid option -- g
Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
       file -C -m magicfiles
Try `file --help' for more information.
[: =: unexpected operator
[: text/plain: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
```


----------



## sixtydoses (Mar 2, 2010)

killasmurf's script works just fine.


----------



## DutchDaemon (Mar 2, 2010)

You'll probably need to quote or curly-brace some variables, e.g.


```
mv "${i}" /some/path
```


----------



## mfaridi (Mar 2, 2010)

DutchDaemon said:
			
		

> You'll probably need to quote or curly-brace some variables, e.g.
> 
> 
> ```
> ...



I put "" but still I see error

```
ile: invalid option -- g
Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
       file -C -m magicfiles
Try `file --help' for more information.
[: =: unexpected operator
[: text/plain: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
[: cannot: unexpected operator
```


----------



## DutchDaemon (Mar 2, 2010)

The same goes for the file command ... 
	
	



```
file -ib "${i}"
```

Try to focus less and generalise more


----------



## mfaridi (Mar 2, 2010)

DutchDaemon said:
			
		

> The same goes for the file command ...
> 
> 
> 
> ...



Yes I see that error again when I put "" in file -ib


----------



## DutchDaemon (Mar 2, 2010)

Run this *inside* the directory.


```
find . -depth 1 -type f | while read i; do if [ `file -ib "${i}" | sed 's/; .*//g'` = 'text/plain' ]; then mv "${i}" /some/path; fi; done
```

Adjust the "depth" to how far into subdirectories you need to go. If it's all in one directory, use -depth 1.


----------



## mfaridi (Mar 2, 2010)

DutchDaemon said:
			
		

> Run this *inside* the directory.
> 
> 
> ```
> ...



when I run that command I see this error

```
while: Expression Syntax.
```


----------



## DutchDaemon (Mar 2, 2010)

Type [cmd=]sh[/cmd] to get a different shell, and try again.


----------



## mfaridi (Mar 2, 2010)

DutchDaemon said:
			
		

> Type [cmd=]sh[/cmd] to get a different shell, and try again.



after I type

```
sh
```
my shell prompt change to this

```
%{%}%n%{%} %{%}%~%{%} %{%}[%!]%{%}
```
and I see very bad character before this was like this and I can not read it 

```
/usr/ports/net/hping
```
when I type that command after type sh 
I see this error

```
: text/x-c++: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c: unexpected operator
[: text/plain: unexpected operator
[: text/x-c: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
[: text/x-c++: unexpected operator
[: text/plain: unexpected operator
[: text/x-c++: unexpected operator
^C%{%}%n%{%} %{%}%~%{%} %{%}[%!]%{%}
```


----------



## DutchDaemon (Mar 2, 2010)

If you don't get a simple *$* or *#* prompt after [cmd=]sh[/cmd] you have a very weird .profile or /etc/profile or .shrc or whatever governs your shell logins. You could try [cmd=]bash[/cmd] if you have it installed already, but if that produces the same weirdness, you have other problems to solve first. That 'find' command should work with sh and bash.


----------

