Vi mode:
set -o vi
Emacs mode (default):
set -o emacs
To show the command in command-line press <Ctrl+P>
.
Use built-in command fc
to open some editor and insert last command into it.
if [ -d "$path" ]; then
# $path is a path a directory that exists
fi
Other useful operators:
-d - File exists and it is a folder
-e - File exists
-r - You have a right to read a file
-s - File exists and it's not empty
-w - You have a right wo write to a file
...
In a current directory:
find . -name "<pattern>"
find . -name "<pattern>" | while read fname; do mv $fname ${fname/<from>/<to>}; done
You can use echo for debugging:
find . -name "<pattern>" | while read fname; do echo "mv $fname ${fname/<from>/<to>}"; done
For more verbosity do this:
find . -name "<pattern>" | while read fname; do echo "mv $fname ${fname/<from>/<to>}"; done | bach -x
while read
is a very useful stuff. You can redirect output from one app with pipe to while read construction and do anything you want with it on bash:
smth | while read line; do echo $line; done