jeudi 26 février 2015

if command in find -exec


I was just trying to list all directories and files under current directory and also write if they are file or directory with the following command:



find -exec echo `echo {} : ;if [ -f {} ]; then echo file; else echo directory;fi` \;


I know it is a silly command, I can use other things like -type f or -type d, but I want to learn why that piece of code did not work as I expected. It just prints directory to all of them. For example while output of find is:



.
./dir
./dir/file


output of my code is :



. : directory
./dir : directory
./dir/file : directory


And output of



echo `echo dir/file : ;if [ -f dir/file ]; then echo file; else echo directory;fi`


is



dir/file : file


I am working on Ubuntu 14.10 and using find (GNU findutils) 4.4.2



Aucun commentaire:

Enregistrer un commentaire