Tuesday, April 21, 2015

Rename files recursively in Linux


copy folders between linux servers

rsync -avh ssh /home/foo jerry@openbsd.nixcraft.in:/home/madhu/

#In the specified directory

find /my/directory/ -name "*.jpeg" -exec rename s/.jpeg/.jpg/ {} ;

# In all subdirectories 
# Rename '.gz%0D' extension to '.gz' 

find . -name "*.gz%0D" -exec rename s/.gz%0D/.gz/ {} \;


# Unzip recursievly  in all subdirectories


find . -name "*.gz" | xargs gunzip

# find number of file in all subdirectories

find . -type f | wc -l

# Delete files with specified extension in all subbirectories

find . -name \*.tiff -type f -delete 

Delete ZIP files in all sub folders

find . -name "*.ZIP" -print0 | xargs -0 rm -rf

Unzip files in all sub folders


find . -name "*.ZIP" -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;

Find all files in sub directories and copy to desired folder

find <start directory> -iname "<all my files type>" -exec cp {} <target_dir> \;

# See this

$ rename 's/search/replace/;' file1 [file2 file3...]
$ rename 's/tutorial0/mymodel/;' *

No comments: