/dev/null a file using xargs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers /dev/null a file using xargs
# 8  
Old 07-11-2011
Quote:
Originally Posted by jlliagre
Code:
find /data/logs/ -name server.log -size +10G -exec sh -c 'for i; do > $i; done' {} +

You need to add a command name between the sh command string and the arguments that find will pass to the shell. If the command name is absent, the first pathname from find will be assigned to $0 and will never be seen by the for loop (which in this case loops over "$@" -> $1..$N).

Modified exec primary: -exec sh -c 'for i; do > $i; done' sh {} +

Regards,
Alister

---------- Post updated at 05:40 PM ---------- Previous update was at 05:32 PM ----------

Quote:
Originally Posted by shamrock
And so is this...
Code:
find /data/logs/ -name server.log -size +10G -exec cp /dev/null {} +

That will almost certainly yield an error. When cp is called with more than 2 arguments, the final argument must be a directory.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 9  
Old 07-12-2011
Quote:
Originally Posted by alister
If the command name is absent, the first pathname from find will be assigned to $0 and will never be seen by the for loop (which in this case loops over "$@" -> $1..$N).

Modified exec primary: -exec sh -c 'for i; do > $i; done' sh {} +
Thanks for the correction. I indeed forgot to properly set $0.
# 10  
Old 07-12-2011
Quote:
Originally Posted by alister
That will almost certainly yield an error. When cp is called with more than 2 arguments, the final argument must be a directory.
I am not sure what makes you see more than 2 arguments Smilie
# 11  
Old 07-12-2011
Quote:
Originally Posted by shamrock
I am not sure what makes you see more than 2 arguments Smilie
My guess is you are misunderstanding how the final + works with find.
# 12  
Old 07-12-2011
Quote:
Originally Posted by jlliagre
My guess is you are misunderstanding how the final + works with find.
I see yes suppose i had only one file namd server.log in mind when i did that.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

2>/dev/null

Friends have the following problem a search may not find anything which would correct example: ls -ltr *prueba.txt | nawk '{ print $9 }' > Procesar.dat 2>/dev/null When he finds nothing gives me the following error ls: prueba.txt: No such file or directory because 2> / dev / null... (4 Replies)
Discussion started by: tricampeon81
4 Replies

2. AIX

Size of file /dev/./null 2>&1

Hello Can I just remove/delete flile ? rw-r--r-- 1 root system 2385088512 Jun 30 21:25 /dev/null 2>&1 size of this flile is 2274.75 m and fill up my filesystem: Filesystem MB blocks Used Free %Used Mounted on /dev/hd4 2560.00 2558.59 1.41 100% / (10 Replies)
Discussion started by: primo102
10 Replies

3. AIX

/dev/null file issue

Hi Experts, I Have a query. In one of my server I just came to know that there was /dev/null file which is a not a character file. Its just a normal file. I know the command to create the character file (/dev/null) but what is the procedure. Like should i delete /dev/null and create or... (7 Replies)
Discussion started by: jayadeava
7 Replies

4. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

5. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

6. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

7. UNIX for Advanced & Expert Users

/dev/NULL can't open this file ??

when i write the following two statements : cp /dev/NULL /clocal/mqbrkrs/user/mqsiadm/sanjay/dspmq_temp cat /dev/NULL > /clocal/mqbrkrs/user/mqsiadm/sanjay/dspmq_temp its gives me errors like : cp: /dev/NULL: A file or directory in the path name does not exist. cat : /dev/NULL can't open... (2 Replies)
Discussion started by: varungupta
2 Replies

8. Solaris

URGENT - setup port and dump all output to /dev/null or a file

Please help urgently. I need to setup up some sort of service on a solaris server on a port. I dont need it do anything special, anything that is sent to this port from an external server should be dump to /dev/null or a flat file.. Can you help urgently? (1 Reply)
Discussion started by: frustrated1
1 Replies

9. UNIX for Advanced & Expert Users

Q1 :/dev/null Q2 -A

Hi, Q1-What does nroff -ms > /dev/null Q2- What does mean -A under STAT column : ps aux |head -20 UTIL PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND root 516 93,0 0,0 12 12 - A 04 nov 3906:51 wait Thank you. (4 Replies)
Discussion started by: big123456
4 Replies

10. UNIX for Dummies Questions & Answers

Creating a file / /dev/null

First of all, hello there cOmMuNity ! :cool: Well, I've got two basic questions: 1) In how many ways it's possible to create a file ? I know one manner using "touch", other typing something like echo "" > file ... The fact is that I need to overwrite the file if it exists, and touch... (8 Replies)
Discussion started by: 435 Gavea
8 Replies
Login or Register to Ask a Question