Renaming Files with xargs
Suppose you wan to rename all files with a “.txt” extension to have a “.php” extension. You use find command with xargs and mv for this task. Follow the following steps.
find . -name "*.txt" | xargs -I {} sh -c 'mv {} $(basename {} .txt).php'
This command uses ‘-I {}’ to specify a placeholder,and the ‘sh -c’ command allows the use of shell syntax for more complex operation. The ‘mv’ command renames each file by replacing the ‘.txt’ extension with ‘.php’. The following image demonstrates.
Output
Running multiple commands with xargs
Xargs is a command utility in Unix and Unix-like operating systems. It is used to build and execute commands from standard input which can be the output of the other command or data files. In this article, we will see how to run multiple commands with xargs.
Table of Content
- Syntax of `xargs` multiple command in Linux
- Understanding of xargs
- Deleting files with xargs Command:
- Renaming Files with xargs
- Xargs with three arguments
- Remove Delimeter