- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: HELP to made a Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 07:23 AM
04-20-2006 07:23 AM
I need move one file from a directory but i need move the most recent from the original directory. ( in original directory have many files equals )
Some body can help me !
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 07:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 07:34 AM
04-20-2006 07:34 AM
Re: HELP to made a Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 07:36 AM
04-20-2006 07:36 AM
Re: HELP to made a Script
Assuming that you do not want to examine subordinate directories, but only want the most recently modified file, do:
# cd yourdir
# FILE=`ls -lt|awk '/^-/ {print $NF}'|head -1`
# mv ${FILE} destdir
The 'ls -lt' lists files in modification timestamp order; the most recent first. We look only for regular files with 'awk' printing the file names, and take only the first one in the ouput stream with 'head'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 09:18 AM
04-20-2006 09:18 AM
Re: HELP to made a Script
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 09:19 PM
04-20-2006 09:19 PM
Re: HELP to made a Script
a little modification of James solution,
to avoid an error message when no file is found:
cd yourdir
FILE=`ls -t | sed 1q`
[ "$FILE" ] && mv ${FILE} destdir
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2006 09:31 PM
04-20-2006 09:31 PM
Re: HELP to made a Script
but just saw the checking for a plain file, so:
cd yourdir
FILE=`ls -t | sed 1q`
[ -n "$FILE" -a -f "$FILE" ] && mv ${FILE} destdir
mfG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2006 08:01 AM
04-21-2006 08:01 AM
Re: HELP to made a Script
NEWDIR="" #Set the new dir of the file
cd $OLDDIR
set -A ARRAY1 $(ll -lt |grep "^-" |tail -1 | cut -d " " -f2-)
mv ${ARRAY1[$(print ${#ARRAY1[*]} - 1 |bc)]} $NEWDIR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2006 08:06 AM
04-21-2006 08:06 AM
Re: HELP to made a Script
NEWDIR="" #Set the new dir of the file
cd $OLDDIR
set -A ARRAY1 $(ll -lrt |grep "^-" |tail -1 | cut -d " " -f2-)
mv ${ARRAY1[$(print ${#ARRAY1[*]} - 1 |bc)]} $NEWDIR
Sorry... forgot the "-r". It is needed for me to use the "tail" command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2006 10:08 AM
04-21-2006 10:08 AM
Re: HELP to made a Script
thanks Josiah, Peter, Pete , James R. all this good boys help me to open my eyes !!!