Programming :: Xargs With Output Of Find
Jul 15, 2011
I'm testing some multi-plat java code and I'm getting a bit frustrated with the Linux tests. I need to run the command:
Code:
$ java -jar /home/developer/TCO/TabletComicOptimizer.jar <file> <args[]>
against all the files that match a specific criteria. I've tried various find syntax and I can't seem to get it right.
Normally I would just create a bash script and populate the results of find into an array and then just enumerate the collection but in this specific case I want to demonstrate this operation at the bash terminal.
I've tried things like:
Code:
~/TCO $ find . -type f -iname "*.cb[rz]" | xargs java -jar TabletComicOptimizer.jar {} 1200x1800 ;
Thinking that the {} is the substitution for each file returned by find but it's not working. How do I execute my java program against each result in the find operation?
View 6 Replies
ADVERTISEMENT
May 25, 2011
I will eventually script this but wanted to know where I screwed up when trying to get this oneliner to work. In a nutshell, I want to created a backup directory, find any files that have changed in the last 48hrs and them copy them to the newly made backup directory.
PHP Code:
date=$(date +%m%d%Y)mkdir -p /home/test_dir/backup$date;find . -mtime 1|xargs -0 cp -r -t /home/test_dir/backup$date
When I do this I get:
PHP Code:
a bunch of junk !#$#$$#! File name too long
I also tried:
PHP Code:
date=$(date +%m%d%Y)mkdir -p /home/test_dir/backup$date;find
. -mtime 1|xargs -0 cp -r {} /home/test_dir/backup$date
View 7 Replies
View Related
Nov 18, 2010
What am I doing wrong here ? Shredding a directory with files is incredibly slow. If I create a file of similar size it is around 1000 times faster. Filesystem is ext4, OS is Slack current. Looking at top it shows shred's status as 'D' which, according to the man page, means uninterruptible sleep ! Also /usr/bin/time shows around 10 minutes but that time was printed on stdout approx. 7 minutes before the command prompt reappeared !
Code:
[virgil@thunderbird2:~/q] $ du -sh
336M.
[virgil@thunderbird2:~/q] $ find . -type d | wc
160 160 12038
[virgil@thunderbird2:~/q] $ find . -type f | wc
6721 6721 687549
[virgil@thunderbird2:~/q] $ /usr/bin/time find . -type f -print0 | xargs -0 -r shred -zu
0.00user 0.00system 10:11.76elapsed 0%CPU (0avgtext+0avgdata 3616maxresident)k
0inputs+0outputs (0major+285minor)pagefaults 0swaps
[virgil@thunderbird2:~]
[virgil@thunderbird2:~] $ dd if=/dev/urandom of=qwerty bs=336M count=1
1+0 records in
1+0 records out
352321536 bytes (352 MB) copied, 51.6693 s, 6.8 MB/s
[virgil@thunderbird2:~]
[virgil@thunderbird2:~] $ ls -l qwerty
-rw-r--r-- 1 virgil virgil 352321536 2010-11-18 15:13 qwerty
[virgil@thunderbird2:~]
[virgil@thunderbird2:~] $ /usr/bin/time shred -zu qwerty
0.92user 0.78system 0:16.94elapsed 10%CPU (0avgtext+0avgdata 2912maxresident)k
0inputs+2752528outputs (0major+235minor)pagefaults 0swaps
View 3 Replies
View Related
Mar 24, 2011
I often want to extract some info using awk from a variable/filename while running other things using xargs and sh. Below is an example:
Code: ls -1 *.txt | xargs -i sh -c 'NEW=`echo $0 | awk -F'_' '{print $1}'`; echo $NEW' {}
In the above case I would like to grab just the first field from a filename (delimited by '_') from within an sh command. This is a simplified example, where normally I would be doing some further data processing with the sh command(s).
The error message that I get is:
Code: }`; echo $NEW: -c: line 0: unexpected EOF while looking for matching ``'
}`; echo $NEW: -c: line 1: syntax error: unexpected end of file.
I haven't been able to figure out how to escape the awk command properly.
View 1 Replies
View Related
Jun 17, 2011
I get this behavior on Slackware 13.37, which includes BASH 4.1.010. Yes, BASH is my shell. I have a file called a.flac and I'm in the directory that contains it.
The output of the ls command is expected:
Code:
ls *.flac
gives:
Code:
a.flac
Removing the extension with basename works as expected:
Code:
basename a.flac .flac
gives:
Code:
a
Putting the above command in a variable substitution works as expected:
Code:
echo `basename a.flac .flac`
gives:
Code:
a
Using xargs with ls and a variable substitution works as expected:
Code:
ls *.flac | xargs -i echo `echo {}`
gives:
Code:
a.flac
However, when I try to add the basename command to the above command, it stops working.
Code:
ls *.flac | xargs -i echo `basename {} .flac`
gives:
Code:
a.flac
Whereas the result I expect is:
Code:
a
Why is it not working, and how do I make it work?
View 3 Replies
View Related
Jan 12, 2009
I have an awk program that finds all files of a specific filename and deletes them from selected subdirectories. There is logic in the awk to avoid certain subdirectories, and this is initialized via a parameter in the beginning statement of the awk. The parameter should have all of the subdirectory names at the top level. This varies from time to time, so I cannot hard-code the value.I'm having a problem initializing the awk parameter using sed. I'm setting a variable (named subdir) using an "ls" command piped to "xargs". I'm then trying to substitute that value into the awk using the sed command.
View 3 Replies
View Related
Mar 26, 2010
I'm trying to pull out sections from a bunch of files. For one file, I use:
Code:
sed '/string1/,/string2/ !d' <filename.ext >newfilename.ext
to pull out everything between two strings in the original file and put them in a new file.
[code]....
View 3 Replies
View Related
Nov 24, 2010
I want to find out my IP and I test this code from beej tutorial:
Code:
char hostname[128];
int i;
struct hostent *he;
struct in_addr **addr_list;
struct in_addr addr;
gethostname(hostname, sizeof hostname);
printf("My hostname: %s
", hostname);
he = gethostbyname(hostname);
if (he == NULL) { // do some error checking
herror("gethostbyname"); // herror(), NOT perror()
return 1;
} // print information about this host:
printf("Official name is: %s
", he->h_name);
printf("IP address: %s
", inet_ntoa(*(struct in_addr*)he->h_addr));
printf("All addresses: ");
addr_list = (struct in_addr **)he->h_addr_list;
for(i = 0; addr_list[i] != NULL; i++) {
printf("%s ", inet_ntoa(*addr_list[i]));
}
printf("
");
return 0;
But my output is this:
Code:
My hostname: vBx
gethostbyname: Unknown host
I heard that it works in windows, why isn't working in linux?
View 1 Replies
View Related
Nov 11, 2010
We make everyday a DB Mysql backup on Linux redhat Enterprise. We are using a bash shell script (and putting it in the crontab) to execute it automatically everyday. We added a line to this script telling, once the backup has completed, to find old backup files (stored on hard disk after each backup) older than x days to remove them. We use the find command (search for file type) with the mtime option and in combination with rm command. Everything runs ok but we also want to add some new code to the same line: If find command cannot find anything or fails, for example if it cannot delete file or fails, send the error message (standard error output) to an error file (like error000001 and increasing) and mail the errorxxxx file to an email address for example to admin@companyname.com. What would be the code for this issue to add it to our find command in the same bash shell script??
View 2 Replies
View Related
Jan 22, 2011
I'm still trying to find out if my coby mp3 player will actually play mtv video files as is advertised.
ffmpeg -formats does list mtv but the only command I really ever used was one to convert a vid to an mp3 so I tried Code: ffmpeg -i test.mp4 -acodec copy output.mtv it returns Code: Unable to find a suitable output format for 'output.mtv' I can't find any mtv files online for purchase or free for that matter, so I know this is all pretty obscure but shouldn't there be a way to convert them since ffmpeg lists mtv format?
View 6 Replies
View Related
Jun 29, 2011
I have a directory like this:
mkdir test
cd test
touch file{0,1}.txt otherfile{0,1}.txt stuff{0,1}.txt
I want to run some command such as ls on certain types of files in the directory and have the * (glob) expand to all possibilities for the filename.
echo 'file otherfile' | tr ' ' '
' | xargs -I % ls %*.txt
This command does not expand the glob and tries to look for the literal 'file*.txt'
How do I write a similar command that expands the globs? (I want to use xargs so the command can be run in parallel)
View 1 Replies
View Related
Jun 10, 2009
I'm trying to copy a list of files except the files which has ".log" in the filename to another folder.I can run it correctly when I am located in the Source folder, but not when I am in any other location.cd /home/me/Sourcels /home/me/Source -1|grep -v "^.*log$" |xargs -n 1 -iHERE cp -r HERE /home/me/DestinationHow can I indicate both Source and Destination Folder?
View 2 Replies
View Related
Jan 23, 2010
I used the command shown below to remove a list of software using yum. It worked, but is there a way of doing this without using the -y option? I would like to review the results before the transaction takes place. I would like to use the same method for installing additional software after a clean install.
cat filename | xargs yum -y remove
View 8 Replies
View Related
Mar 18, 2010
Please explain why
Code:
echo some_directory | xargs cd
is not working.
Code:
echo some_directory | xargs ls
is working as expected.
View 14 Replies
View Related
Jun 17, 2011
I want to insert a picture into a group of pictures (I memorized their names in a text file) resulting a new group of picture (which I also memorized their name in another text file), but I have a problem doing that. I want to write something like that:
$> cat file1 | cat file2 | xargs composite -blend 30 text.jpg line_file1 line_file2
where
file1 is:
frame1.jpg
frame2.jpg
frame3.jpg
....
and file2 is:
new_frame1.jpg
new_frame2.jpg
new_frame3.jpg
...
View 4 Replies
View Related
Mar 9, 2011
I'm trying to copy all my photos from a windows drive to my Linux partition. So i created this small one-liner:
[code]...
the output from find has no space esc-character, i.e. /path/sub folder should be /path/sub folder.
View 3 Replies
View Related
Feb 19, 2010
I'm wondering where I can find description of mpstat output?.. I'm talking about the output of all available counters presented by mpstat. For instance:
Code:
$ mpstat -Au
Linux 2.6.31-19-generic (lenovo-S102) 02/19/10 _i686_(2 CPU)
17:32:15 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
17:32:15 all 36.00 0.18 10.39 0.73 0.08 0.03 0.00 0.00 52.60
17:32:15 0 36.81 0.15 11.58 1.14 0.16 0.04 0.00 0.00 50.11
17:32:15 1 35.26 0.22 9.31 0.34 0.00 0.02 0.00 0.00 54.86
[Code]...
View 4 Replies
View Related
Jun 22, 2009
I'm trying to find all zip files timestamped from the past 7 days, then unzip them into a different director.I tried the following, but it only unzipped one of three files that meet the 7 day criteria. What am I missing?Code:find /home/user/public_html/zip_files/ -iname "*.zip" -mtime -7 -print0 | xargs -n10 unzip -LL -o -d /home/user/public_html/another_directory/
View 1 Replies
View Related
May 15, 2011
I need your inputs on performing some operations:-
a. Traverse from top Level directory, find all the directories
b. Rename all these directories to <original name>.dir
c. Once the renaming is done - search from top level and retain only those directories which has .txt content in them.
d. Delete rest all.....
Can i use xargs here to perform operation a and b , or will sed will be useful.
View 14 Replies
View Related
Mar 9, 2010
I would like to ask the following:
1) ls -l |grep test -> this will grep every "ls -l" output line
2) ls -1 |xargs grep test -> this will grep every single file with test
3) ls -1 |xargs echo -> this will echo directory list
4) ls -1 |echo -> this does nothing!!!
My question is: how some command can receive input from "both sides" (grep can grep whole output or every single file - xargs, the same is for i.e. wc command). 4) echo does nothing (it's a single echo command).
View 1 Replies
View Related
Nov 17, 2010
I'm fairly new to writing bash scripts and haven't been able to find a an example of effectively using a the find command in a bash script.
I want to run some git commands on any sub directory that has a .git project in it. Getting to the directory is not my problem, its how to find them
What i want to do is execute
Code:
find -name .git
Then act on each response line that is printed out. E.G Navigate to the directory and run git status.
How do i use the output of the find command in the bash script?
View 6 Replies
View Related
Aug 18, 2010
Where can I find document re "how to read anova output"? Google found many of them. But seemingly non of them can explain to me following output:-
> tabA = c(5.67, 5.67, 5.55, 5.57)
> tabB = c(5.75, 5.47, 5.43, 5.45)
> tabC = c(4.74, 4.45, 4.65, 4.94)
> tabs = data.frame(tabA, tabB, tabC)
> tablets = stack(tabs)
> anova(lm(values ~ ind, data = tablets))
Code:
Analysis of Variance Table
Response: values
Df Sum Sq Mean Sq F value Pr(>F)
ind 2 2.05787 1.02893 45.239 2.015e-05 ***
Residuals 9 0.20470 0.02274
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> TukeyHSD(aov(values ~ ind, data = tablets))
Code:
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = values ~ ind, data = tablets)
$ind
diff lwr upr p adj
tabB-tabA -0.09 -0.3877412 0.2077412 0.6866791
tabC-tabA -0.92 -1.2177412 -0.6222588 0.0000321
tabC-tabB -0.83 -1.1277412 -0.5322588 0.0000731
View 3 Replies
View Related
Jan 10, 2011
I am trying to automate an svnadmin dump command for a backup script, and I want to do something like this:
find /var/svn/* ( ! -name dir -prune ) -type d -exec svnadmin dump {} > {}.svn ;
This seems to work, in that it looks through each svn repository in /var/svn, and runs svnadmin dump on it.
However, the second {} in the exec command doesn't get substituted for the name of the directory being processed. It basically just results a single file named {}.svn.
I suspect that this is because the shell interprets > to end the find command, and it tries redirecting stdout from that command to the file named {}.svn.
View 2 Replies
View Related
Mar 22, 2010
I have some big files of logs that contain errors printed by an app. They are most of the time relevant, however most of them are similar. So i figured i could check what happened between a time interval with a find.
Im using this one
Code:
And I get an output similar to this one.
Code:
Is there a way to condensate the output lines to get only one or two, indicating the start and last occurrence of a block? Or I need to create a program to do so?
Because right now I get thousands of similar lines, but when I'm scrolling through them i sometimes miss relevant information that i would've otherwise noted if it wasn't all that spammy.
View 10 Replies
View Related
Jan 28, 2010
As i am new to C++ i couldn't figure out how to input a file and make some change on the file and produce a output file. like this problem i have is.
"Program that processes an input file and produces an output file. The input file will contain lines of data, each containing two floating point numbers. The lines of the output file should contain the two numbers read and their average (with a '$' sign and 2 places after the decimal point)."
View 2 Replies
View Related
Apr 25, 2010
I have a file with something like** The total time for processing is 1245 seconds *when I doawk 'BEGIN{FS="The total time for processing"} {print $2 } ' fileI get correctly on screen 1245 seconds *but when I try to direct this to a file awk 'BEGIN{FS="The total time for processing"} {print $2 } ' file > outputthenoutput is empty ie the 1245 seconds * is not saved in ...Know why?
View 4 Replies
View Related
Dec 19, 2008
I am unable to find a description of alsa's programing language, this sort of stuff:
[Code]...
I need to know what, for example, 'ttable' means and what is its syntax. This seems to be a state secret.
View 2 Replies
View Related
May 10, 2010
With the command "tail -300 /var/log/apache2/access.log | less" i can look in the log for the 300 latest visitors. and i wanted to ask if it's possiblle to get that command to run from a php file and if yes how ?
View 4 Replies
View Related
Apr 6, 2011
Lex's (actually Flex) output contains this:
Code:
#ifdef __cplusplus
extern "C" int yywrap (void );
[code]...
View 8 Replies
View Related
Jun 8, 2010
I am trying to learn C Programing and I'm having trouble on the output of my script. my script should count the characters in input but it doesn't give me any numbers..
here's my program code:
Code:
#include <stdio.h>
main()
{
double nc;
[code]....
View 14 Replies
View Related