xargs

How can I use aliased commands with xargs?

為{幸葍}努か 提交于 2019-12-18 10:35:36
问题 I have the following alias in my .aliases: alias gi grep -i and I want to look for foo case-insensitively in all the files that have the string bar in their name: find -name \*bar\* | xargs gi foo This is what I get: xargs: gi: No such file or directory Is there any way to use aliases in xargs, or do I have to use the full version: find -name \*bar\* | xargs grep -i foo Note: This is a simple example. Besides gi I have some pretty complicated aliases that I can't expand manually so easily.

Batch renaming files in command line and Xargs

◇◆丶佛笑我妖孽 提交于 2019-12-17 23:44:10
问题 So, I have the following structure: . .. a.png b.png c.png I ran a command to resize them ls | xargs -I xx convert xx -resize xx.jpg Now my dir looks like this . .. a.png.jpg a.png b.png.jpg b.png c.png.jpg c.png The firs question is, how do i rename the file so that I can just have one extension. Not two. (basically, how do I clean up my original mistake)? The second question is, in the future, using xargs, how do I change the extension of the file simular to second command? 回答1: how do i

Using grep to search for hex strings in a file

女生的网名这么多〃 提交于 2019-12-17 17:42:23
问题 I have been trying all day to get this to work. Does anyone know how to get grep, or something of the like, to retrieve offsets of hex strings in a file? I have a bunch of hexdumps that I need to check for strings and then run again and check if the value has changed. I have tried hexdump and dd, but the problem is because it's a stream, I lose my offset for the files. Someone must have had this problem and a workaround. What can I do? To clarify, I have a series of dumped memory regions from

How to delete many 0 byte files in linux?

天大地大妈咪最大 提交于 2019-12-17 17:26:06
问题 I've a directory with many number of 0 byte files in it. I can't even see the files when I use the ls command. I'm using a small script to delete these files but sometimes that does not even delete these files. Here is the script: i=100 while [ $i -le 999 ];do rm -f file${i}*; let i++; done Is there any other way to do this more quickly? 回答1: Use find combined with xargs . find . -name 'file*' -size 0 -print0 | xargs -0 rm You avoid to start rm for every file. 回答2: With GNU's find (see

How can I use xargs to copy files that have spaces and quotes in their names?

情到浓时终转凉″ 提交于 2019-12-17 10:07:59
问题 I'm trying to copy a bunch of files below a directory and a number of the files have spaces and single-quotes in their names. When I try to string together find and grep with xargs , I get the following error: find .|grep "FooBar"|xargs -I{} cp "{}" ~/foo/bar xargs: unterminated quote Any suggestions for a more robust usage of xargs? This is on Mac OS X 10.5.3 (Leopard) with BSD xargs . 回答1: You can combine all of that into a single find command: find . -iname "*foobar*" -exec cp -- "{}" ~

Make xargs execute the command once for each line of input

泪湿孤枕 提交于 2019-12-17 08:00:33
问题 How can I make xargs execute the command exactly once for each line of input given? It's default behavior is to chunk the lines and execute the command once, passing multiple lines to each instance. From http://en.wikipedia.org/wiki/Xargs: find /path -type f -print0 | xargs -0 rm In this example, find feeds the input of xargs with a long list of file names. xargs then splits this list into sublists and calls rm once for every sublist. This is more efficient than this functionally equivalent

Make xargs handle filenames that contain spaces

最后都变了- 提交于 2019-12-17 07:59:43
问题 $ ls *mp3 | xargs mplayer Playing Lemon. File not found: 'Lemon' Playing Tree.mp3. File not found: 'Tree.mp3' Exiting... (End of file) My command fails because the file "Lemon Tree.mp3" contains spaces and so xargs thinks it's two files. Can I make find + xargs work with filenames like this? 回答1: The xargs command takes white space characters (tabs, spaces, new lines) as delimiters. You can narrow it down only for the new line characters ('\n') with -d option like this: ls *.mp3 | xargs -d '

Make xargs execute the command once for each line of input

百般思念 提交于 2019-12-17 07:59:24
问题 How can I make xargs execute the command exactly once for each line of input given? It's default behavior is to chunk the lines and execute the command once, passing multiple lines to each instance. From http://en.wikipedia.org/wiki/Xargs: find /path -type f -print0 | xargs -0 rm In this example, find feeds the input of xargs with a long list of file names. xargs then splits this list into sublists and calls rm once for every sublist. This is more efficient than this functionally equivalent

How to ignore xargs commands if stdin input is empty?

孤街醉人 提交于 2019-12-17 07:10:41
问题 Consider this command: ls /mydir/*.txt | xargs chown root The intention is to change owners of all text files in mydir to root The issue is that if there are no .txt files in mydir then xargs thows an error saying there is no path specified. This is a harmless example because an error is being thrown, but in some cases, like in the script that i need to use here, a blank path is assumed to be the current directory. So if I run that command from /home/tom/ then if there is no result for ls

GNU parallel not working at all

笑着哭i 提交于 2019-12-17 05:00:56
问题 I have been trying to use GNU parallel for some time, but I have never been able to get it to function at all! For example, running (in a non-empty directory!): ls | parallel echo # Outputs single new line ls | parallel echo echo echo # Outputs three new lines. ls | parallel echo {} # /bin/bash: {}: command not found ls | parallel echo '{}' # /bin/bash: {}: command not found ls | parallel 'echo {}' # Outputs: {} ls | parallel -IMM 'echo MM' # Outputs: MM It seems that it is simply executing