makh wrote:
I want to echo only file names less than 10.
Best approach:
Code:
for f in [1-9]; do echo "$f"; done
The syntax you're using is wrong. Instead of:
Code:
for i in *; do (if["$i" -lt 10] then echo "$i" fi); done
you'd write:
Code:
for i in *; do if [ "$i" -lt 10 ]; then echo "$i"; fi; done
[ is a command itself, it's just a shortcut to
test(0) ;
if is a shell keyword.
By following your idea, you can even write the condition with
(( ...
)) bash(1)'s syntax, like this:
Code:
for i in *; do if ((i < 10)); then echo "$i"; fi; done
----
makh wrote:
How can I rename the same by using above type cmd:
01 02 03 04 ...... 14
Well, since you know that each filename is simply an integer, then just add a zero to the left of the variable
that you're using to loop through your files, thanks to
mv(1).
Code:
for f in [1-9]; do mv "$f" "0$f"; done