xargs
xargs linux command cheatsheet by Thamizhiniyan C S
Introduction
xargs
is a command line tool used to build and execute command from the standard input.
Syntax
Important Flags
Flags | Description |
---|---|
| Will terminate the arguments with null character (helps to handle spaces in the argument) |
| This option allows xargs to read item from a file |
| To specify the delimiter to be used when differentiating arguments in stdin |
| Specifies max number non-blank inputs per command line |
| Consider this as a buffer size that you allocate while running xargs, it sets the max-chars for the command, which includes it's initial arguments and terminating nulls as well.(You won't be using this most of the times but it's good to know). Default size is around 128kB (if not specified). |
| This flag will exit the command execution if the size specified is exceeded.(For security purposes.) |
| This is to specify the end-of-file string (You can use this in case you are reading arguments from a file) |
| (Capital i) Used to replace str occurrence in arguments with the one passed via stdin(More like creating a variable to use later) |
| prompt the user before running any command as a token of confirmation. |
| If the standard input is blank (i.e. no arguments passed) then it won't run the command. |
| This specifies the limit of max-args to be taken from command input at once. After the max-args limit is reached, it will pass the rest arguments into a new command line with the same flags issued to the previously ran command. (More like a looping) |
| verbose; (Print the command before running it).Note: This won't ask for a prompt |
Examples
Command | Description |
---|---|
To run multiple commands in one line | |
To find and delete files with a prompt | |
Looking out for files with the given pattern of words | |
To create files and change its permission to read-only to the owner | |
To list the directory, append all the names of the files in the directory to a file and remove those files. |
Last updated