[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

mv file from ls command help

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
gagaliya
Asked:
gagaliya
1 Solution
 
ozoCommented:
mv `ls -r  xyz_*.txt|tail -1`  some_dir
0
 
gagaliyaAuthor Commented:
perfect thank you
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now