搜索并替换所有系统上的字符串工具
replacefs的Python项目详细描述
替换
搜索并替换所有系统上的字符串工具。
replacefs工具允许在整个文件系统中以直观、愉快的方式执行大量的、可控的字符串替换。您将能够从一个路径递归地将定义的字符串替换为另一个,或者在定义的路径或文件列表中本地替换。
安装
with pip: sudo pip3 install replacefs with yay: yay -a replace with yaourt: yaourt -a replace
兼容性
python>;=3
用法
replacefs [-h] [-l] [-r] [-s] [-a] [-c] [--initial_string INITIAL_STRING] [--destination_string DESTINATION_STRING] [--directory_path FOLDER_PATH] [--file_paths_list FILE_PATH_01 FILE_PATH_02 ...] [--filename_must_end_by END_STRING_01 END_STRING_02 ...] [--no_ask_confirmation] [--case_insensitive ] [--extension_filter] [--all_extensions] [--add_excluded_extensions END_STRING_01 END_STRING_02 ...] [--add_excluded_strings STRING_01 STRING_02 ...] [--excluded_paths EXCLUDED_PATH_01 EXCLUDED_PATH_01 ...] [--binary_exclusion] [--binary_accepted] [--symlink_exclusion] [--symlink_accepted] [--end_param] options:-h, --help show this help message and exit -l perform local replacement in FOLDER_PATH. Enabled by default -r perform recursive replacement from FOLDER_PATH-s perform specific replacement on FILE_PATH_01 FILE_PATH_02 given by --list_files_paths_to_apply -a, --ask_confirmation, --ask ask for confirmation to perform replacement at any INITIAL_STRING occurrence. Enabled by default -c, --case_sensitive, --case_respect respect case when searching for occurrences. Enabled by default --initial_string, --initial, --init INITIAL_STRING precise the string to search and replace --destination_string, --destination, --dest DESTINATION_STRING precise the string to replace the INITIAL_STRING strings found --directory_path, --dirpath, --path FOLDER_PATH precise the path of the directory to perform the replacement from --file_paths_list, --file_paths FILE_PATH_01 FILE_PATH_02 ... precise the list of file paths to perform the replacement on --filename_must_end_by, --end_by END_STRING_01 END_STRING_02 ... precise the list of acceptable end string to filter the files regarding their end names --no_ask_confirmation, --no_ask enable no asking mode. Perform replacement without asking confirmation --case_insensitive, --no_case_respect enable case insensitive. Search for INITIAL_STRING string in insensitive case mode --extension_filter, --no_all_extensions enable blacklist extension filter. The blacklist extension owns more than 60 audio, image and video extensions such as "mp3", "jpg" or "mp4". This mode is enabled by default --all_extensions, --no_extension_filter disable blacklist extension filter. --add_excluded_extensions, --filter_extensions END_STRING_01 END_STRING_02 ... precise the unacceptable end strings to filter the files regarding their end names --add_excluded_strings, --filter_strings STRING_01 STRING_02 ... precise the unacceptable strings to filter the files regarding their names --excluded_paths EXCLUDED_PATH_01 EXCLUDED_PATH_01 precise the paths to exclude when searching for the INITIAL_STRING in the file system --binary_exclusion, --no_binary refuse binary files. Enabled by default --binary_accepted, --no_binary_exclusion, --binary accept binary files --symlink_accepted, --no_symlink_exclusion, --symlink refuse symlinks. Enabled by default --symlink_exclusion, --no_symlink accept symlinks -end_param, --end precise the end of a parameter enumeration
示例
如需帮助:
rp -h or replacefs --help
local将当前目录中出现的“titi”替换为“to to”:
rp -l titi toto .
recursive从子目录“test”替换:
replacefs -r titi toto test
specific在“test01”“test/test02”文件中替换:
replacefs -s titi toto test01 test/test02
黑名单扩展名
黑名单中默认的所有扩展名:
“mp3”,“mp3”,“wav”,“wav”,“m4a”,“m4a”,“aac”,“aac”,“mp1”,“mp2”,“mp2”,“mpg”,“mpg”,“flac”,“flac”,“jpg”,“jpg”,“jpg”,“jpeg”,“png”,“png”,“tif”,“tif”,“gif”,“bmp”,“bmp”,“pjpeg”,“pjpeg”,“mp4”,“mpeg”,“mpeg”,“avi”,“avi”,“wma”,“ogg”,“ogg”,“quicktime”,“quicktime”,“webm”,“mp2t”,“mp2t”,“flv”,“flv”,“mov”,“mov”,“webm”,“webm”,“mkv”,“mkv”,“class”,“class”
使用--所有扩展名或--无扩展名筛选器禁用黑名单扩展筛选器。 使用--添加排除的扩展名或--筛选扩展名添加更多扩展名
建议
具有replace的一些有用bash函数:
function replace {#ex: replace titi totonb_param="$#"if["$nb_param" -lt 2];thenecho -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"elif["$nb_param" -eq 2];then rp -l "$@" . elif["$nb_param" -eq 3];then rp -l "$@"elif["$nb_param" -gt 3];thenecho -e "$WARNING specific mode replace" rp -s "$@"fi}function rplocal { replace $@;}function rprecursive {#ex: rprecursive titi totonb_param="$#"if["$nb_param" -lt 2];thenecho -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"elif["$nb_param" -eq 2];then rp -r "$@" . elif["$nb_param" -eq 3];then rp -r "$@"elseecho -e "\n\t$WARNING at most 3 arguments ..."fi}function rpcaseinsensitive {#ex: rpcaseinsensitive titi totonb_param="$#"if["$nb_param" -lt 2];thenecho -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"elif["$nb_param" -eq 2];then rp --case_insensitive -l "$@" . elif["$nb_param" -eq 3];then rp --case_insensitive -l "$@"elif["$nb_param" -gt 3];thenecho -e "$WARNING specific mode replace" rp --case_insensitive -s "$@"fi}function rpcaseinsensitivelocal { rpcaseinsensitive $@;}function rprecursivecaseinsensitive {#ex: rprecursivecaseinsensitive titi totonb_param="$#"if["$nb_param" -lt 2];thenecho -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"elif["$nb_param" -eq 2];then rp --case_insensitive -r "$@" . elif["$nb_param" -eq 3];then rp --case_insensitive -r "$@"elseecho -e "\n\t$WARNING at most 3 arguments ..."fi}