need help with xargs command..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with xargs command..
# 1  
Old 12-12-2011
need help with xargs command..

Code:
ls -lrt | awk '$7==12{print $9}' | xargs -i mv {} $dir

i executed this command but $dir does not exists.......
and the files hv been moved but i dont know where .....
plz help(ASAP)

thanks in advance.

Last edited by methyl; 12-12-2011 at 04:49 PM.. Reason: please use code tags
# 2  
Old 12-12-2011
Do you know the exact name of one of the files?

Code:
find / -name exactnameoffile -exec ls -l {} \;

# 3  
Old 12-12-2011
find / ....
will search in each directory????
# 4  
Old 12-12-2011
What was the value of $dir ?

I think I know what has happened. Not good I'm afraid.
If the value of $dir was not the name of a directory, the "mv" command will assume that it is a file ... and create it.

Unfortunately every file in your current directory with a day-of-month field of "12" has been moved to the same file. That file has the name of the directory that didn't exist. The only file which is salvageable is the last file which was moved (as long as you know what the name of the file was).
# 5  
Old 12-12-2011
thanks for ur reply
i got it
only the last file is moved to a $dir(a file being created)......

i hv another doubt
suppose my $dir is like /abc/def/
should i provide "/abc/def/" or "/abc/def/." in my command
# 6  
Old 12-12-2011
(Prefix: Sorry, I do not understand you last post #5 at all. Please write again in better English. This is not an answer to your last post, it is an answer about how to find the file which was created).


In this context I've assumed that directory "/abc" exists or the "mv" command would have failed.

This should provide the answer.
Code:
ls -la $dir

Or:
Code:
ls -la /abc/def/

Or:
Code:
ls -la /abc/def

All of which should give the same result.



ANALYSIS of Post #5
Quote:
thanks for ur reply
i got it
only the last file is moved to a $dir(a file being created)......

i hv another doubt
suppose my $dir is like /abc/def/
should i provide "/abc/def/" or "/abc/def/." in my command
1) ALL your files dated day "12" (in any month and in any year) got moved to the single named file when $dir was not a directory.
Only the last file to be moved was not overwritten. It was a disaster. We hope you were just testing.
2) When $dir is a directory, the best format is "/abc/def/" . Get into the habit of putting double quotes round strings. One day it will save you.
Code:
dir="/abc/def/"
ls -lrt | awk '$7==12{print $9}' | xargs -i mv {} "${dir}"

3) I have real trouble reading text speak ! Words like "ur" and "hv".

Last edited by methyl; 12-12-2011 at 05:42 PM..
# 7  
Old 12-12-2011
suppose like i have 26 files named a.txt,b.txt,c.txt,....y.txt,z.txt
i have to move them to a directory /dir1/dir2/dir3
but by mistake dir3 does not exists
i executed
Code:
ls -lrt | awk '$7==12{print $9}' | xargs -i mv {} /dir1/dir2/dir3

then a file named dir3 is created in directory /dir1/dir2/
which is nothing but z.txt
---------------------
and my doubt was what is the difference in below two
Code:
ls -lrt | awk '$7==12{print $9}' | xargs -i mv {} /dir1/dir2/dir3/.
ls -lrt | awk '$7==12{print $9}' | xargs -i mv {} /dir1/dir2/dir3


Last edited by Franklin52; 12-13-2011 at 04:08 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Xargs -P command execution status

Hi, I am working on a file copier utility where I have written the copy commands to a batch file e.g. file_copier.bat which i pass to xargs command as follows. cat file_copier.bat | xargs -n 1 -P 40 I also want to record the copy command status of each file/command in the form "command... (1 Reply)
Discussion started by: ankur singh
1 Replies

2. Shell Programming and Scripting

Looking for XARGS command Silent options

ls | grep -E '^+$' | xargs --verbose -I{} rm -vfr "{}"; When i execute the command it works fine by removing the directories and its writing the output as below about which files are deleting.What i want know is,is there any XARGS command option that it should done silently in background with... (2 Replies)
Discussion started by: nareshreddy443
2 Replies

3. Shell Programming and Scripting

Pipe output a command to another using xargs

xargs work great when a command gives multiple line output which can be input to another. In my case it is not working coz the second command uses two words in it. $ scr.sh gives output like 193740 638102 375449 .. .. another command takes these number as inputs. it works great... (1 Reply)
Discussion started by: mahesh113
1 Replies

4. Shell Programming and Scripting

Doubt in xargs command

Hi, What is the difference in capitalizing the option 'i' of xargs command, (i.e) xargs -i and xargs -I? Also, what is the difference between the below 2 commands? output_from_cmd | xargs -I {} grep '{}' file output_from_cmd | xargs -I grep '{}' file Any efficiency or performance... (4 Replies)
Discussion started by: royalibrahim
4 Replies

5. Shell Programming and Scripting

xargs command

Hi The command below does not work. what I am doing wrong ? For some reason second part of the xargs command is not does what I expect If I get this working I intend to use it for multiple file rename later. echo archDP105144_1_702159963.dbf|xargs -i cp {} `echo {}|awk... (11 Replies)
Discussion started by: zam
11 Replies

6. Shell Programming and Scripting

xargs command problem

Hi I am trying to use "xargs" command to loop through each file, modify it and overwrite the old file with the modification but with the same file name. I thought it is easy but I just can't get it to work I tried the following I thought {} would give me the current file name, but it... (1 Reply)
Discussion started by: tiger66
1 Replies

7. UNIX for Dummies Questions & Answers

querry about xargs command

what is the real use of xargs command ..? ls -tr |xargs -I{} rm -f {} ....can any one tell me what is the significance of {} curly brackets in this command (1 Reply)
Discussion started by: mobydick
1 Replies

8. AIX

command usage on find with xargs and tar

my task : tar up large bunch of files(about 10,000 files) in the current directories that created more than 30 days ago but it come with following error find ./ -ctime +30 | xargs tar rvf test1.tar tar: test1.tar: A file or directory in the path name does not exist. (3 Replies)
Discussion started by: darkrainbow
3 Replies

9. Shell Programming and Scripting

Xargs command outupt to file

Hello, I'm on a mac trying to have the follow cmd list the files after touch, but very unsuccessful. Please can you help. sort $BOTHFILE | uniq -u | xargs -I {} -t touch {} >> $LOGFILE ; BOTHFile contents in form of /directory/file.txt thanx (3 Replies)
Discussion started by: byblos
3 Replies

10. UNIX for Dummies Questions & Answers

use of xargs command

Hi Everybody, Can you explain the difference between the following commands: 1. find . -print|xargs grep -i dba_2pc_pending 2. find . -print|grep -i dba_2pc_pending (5 Replies)
Discussion started by: kishorebabu
5 Replies
Login or Register to Ask a Question