Solved

mv file from ls command help

Posted on 2010-11-08
2
552 Views
Last Modified: 2012-05-10
Hi guys, can someone give me the shell script code for below:  

1) ls -lr  xyz_*.txt
xyz_2_222.txt
xyz_2_111.txt
xyz_1_333.txt
xyz_1_222.txt

2) mv  xyz_1_222.txt  some_dir   (pick the lowest file from the list)

How do i do the above 2 steps in  a *.sh script, basically how to get the lowest file name of the ls -lr commnand and pass it to the mv command.

thanks
0
Comment
Question by:gagaliya
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 34088811
mv `ls -r  xyz_*.txt|tail -1`  some_dir
0
 
LVL 1

Author Closing Comment

by:gagaliya
ID: 34093954
perfect thank you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now