folder with 25000 rpm packages

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.
 
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
 
Code:
for i in `ls`; do
  if [ `file -ib $i | awk '{print [red]$i[/red]}'` == 'text/plain;' ]; then
    mv $i /some/path
  fi
done
 
killasmurf86 said:
Code:
for i in `ls`; do
  if [ `file -ib $i | awk '{print $1}'` == 'text/plain;' ]; then
    mv $i /some/path
  fi
done

when I run this command
Code:
 sh ./move.sh
I see this error
Code:
[: 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
Code:
for i in `ls`; do
  if [ `file -ib $i | awk '{print $1}'` == 'text/plain;' ]; then
    mv $i /home/narges/cod
  fi
done
 
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
 
killasmurf86 said:
Fixed typo in my script

now I see this error
Code:
: ==: 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
 
crap, $1 was corret, there was other issue
Code:
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.
 
killasmurf86 said:
crap, $1 was corret, there was other issue
Code:
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.

with this new script I see this error
Code:
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
 
You'll probably need to quote or curly-brace some variables, e.g.

Code:
mv "${i}" /some/path
 
DutchDaemon said:
You'll probably need to quote or curly-brace some variables, e.g.

Code:
mv "${i}" /some/path

I put "" but still I see error
Code:
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
 
The same goes for the file command ...
Code:
file -ib "${i}"

Try to focus less and generalise more ;)
 
Run this inside the directory.

Code:
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.
 
DutchDaemon said:
Run this inside the directory.

Code:
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.

when I run that command I see this error
Code:
while: Expression Syntax.
 
DutchDaemon said:
Type [cmd=]sh[/cmd] to get a different shell, and try again.

after I type
Code:
sh
my shell prompt change to this
Code:
%{%}%n%{%} %{%}%~%{%} %{%}[%!]%{%}
and I see very bad character before this was like this and I can not read it
Code:
/usr/ports/net/hping
when I type that command after type sh
I see this error
Code:
: 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%{%} %{%}%~%{%} %{%}[%!]%{%}
 
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.
 
Back
Top