搜索并替换所有系统上的字符串工具

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}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java验证Spring上资源服务器的JWT令牌   java在Jmeter中计算步进线程组执行的持续时间   java如何在Kabeja中读取块中的行?   显示滚动RecyclerView CoordinatorLayout时的java   java解释eclipse。类路径文件。“kind=“con”和“exported=“true”是什么意思?   IntelliJ中的java Spring MVC 4项目模板   java Android:在片段交互侦听器上出错   java无法在安卓 WebView中滚动到顶部   在setRGB(intX,intY,intRGB)方法中使用的图像设置颜色为int值?JAVA   java使用哪种技术动态更新组合框中的值?   java将学生分配到课程中   java Android CertificateFactory。generateCertificates(Inputstream)返回0   使用SSL访问Web服务时发生java错误   编译Java程序后,它显示错误:不兼容类型:double无法转换为double[]   java Android库使用asp。NETWebAPI   java gwt celltable非工作类型类构造函数未定义   java扑克EV计算器:计算手的价值?   MVC控制器方法中的java Spring绑定结果   春季启动问题java。lang.IllegalArgumentException:值必须仅包含有效字符   java Why mybatis force将log4j调试信息打印到控制台