You are on page 1of 2

EXTRACT RENAME AND EDIT FILES

shopt -s globstar nullglob


while set -- **/*.zip; [ $# -ge 1 ]
do
for z
do
( cd -- "$(dirname "$z")" &&
z=${z##*/} &&
cp -- "$z" "$z".bak &&
mkdir -- "$z"dir &&
unzip -- "$z" -d "$z"dir &&
rm -- "$z"
)
done
done
Unzip recursively into respective subdirectory

find . -depth -exec sh -c '


t=${0%/*}/$(printf %s "${0##*/}" | tr "[:upper:]" "[:lower:]");
[ "$t" = "$0" ] || mv -i "$0" "$t"
' {} \;
Find in directory and sub directories all files and convert their name from
uppercase to lowercase

find . -depth -exec sh -c '


t=${0%/*}/$(printf %s "${0##*/}" | tr "[:lower:]" "[:upper:]");
[ "$t" = "$0" ] || mv -i "$0" "$t"
' {} \;
Find in directory and sub directories all files and convert their name from
lowercase to uppercase

find ./ -depth -name "*.txt" -exec sh -c 'mv "$1" "${1%.txt}"' _ {} \;


Find in directory and sub directories all files that their name ending to .txt and
remove this

find ./ -type f -name 'R*' -print0 | xargs --null -I{} mv {} {}_startup-config.cfg


Find in directory and sub directories all files that their name starting with R and
append to the original name the _startup-config.cfg

sed -i 's/old-text/new-text/g' input.txt


It tells sed to find all occurrences of ‘old-text’ and replace with ‘new-text’ in a
file named input.txt

sed -i 's/old-text/new-text/g' *
It tells sed to find all occurrences of ‘old-text’ and replace with ‘new-text’ in
any file in working directory

sed -i 's/\ old-text/new-text\ /g' *


It tells sed to find all occurrences of ‘ old-text’ and replace with ‘new-text ’ in
any file in working directory
Use \ to escape special characters

find ./ -type f -exec sed -i -e 's/old-text/new-text/g' {} \;


Find and replace with sed in directory and sub directories all occurrences of ‘old-
text’ with ‘new-text’

find ./ -type f -name "R*" -exec sed -i -e 's/old-text/new-text/g' {} \;


Find and replace with sed in directory and sub directories all occurrences of ‘old-
text’ with ‘new-text’ only on files that have name pattern R*

You might also like