Sponsored Content
Top Forums Shell Programming and Scripting delete files except most recent Post 75666 by pixelbeat on Tuesday 21st of June 2005 10:55:38 AM
Old 06-21-2005
Code:
DIR=/u02/oracle/CMDR/archive

find $DIR -type f -maxdepth 1 -printf "%T@\t%p\n" | #list files with timestamps
sort -k1,1n | #sort oldest -> newest
cut -f2- | #remove timestamps
sed '$d' | #remove the last one (newest file)
tr '\n' '\0' | #delimit with NULs in case spaces in names
xargs -r0 rm -f

Also have a look at my newest script
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To keep only the most recent files

Hi all, I'm running on a Sun Solaris machine. I would only want to keep the last 2 most recent files on 1 of my directory. Below shows my script, but it is incomplete. For the ?? part I do not know how to continue. please help:confused: DIR=/tmp/abc OUTPUT=/tmp/output.out... (1 Reply)
Discussion started by: *Jess*
1 Replies

2. Shell Programming and Scripting

Get Files from ftp which are uploaded recent week

Hi All, Here is a brief scenario for my requirement .. There is a directory in FTP Server, where would files be uploaded on weekly basic. I need to get those files which are uploaded during this week and not the files which are uploaded the previous week and download them to locale... (1 Reply)
Discussion started by: narramadan
1 Replies

3. OS X (Apple)

How do you list the most recent files writen to a volume

Hi, I have a couple of xRaids and recently over night something happened on one of the volumes which maxed out all the disk space. What is the shell command to list the most recent files written to a volume as there are like millions of files on this share. I'm thinking along the lines of... (1 Reply)
Discussion started by: williamhsman
1 Replies

4. UNIX for Dummies Questions & Answers

sort biggest most recent files

if i am in /tmp file, and i have a few DIRs under /tmp. i want to find the biggest and most recent files (from 7 days ago) in /tmp and subfolders. (3 Replies)
Discussion started by: tjmannonline
3 Replies

5. UNIX for Advanced & Expert Users

Back up of recent modified files

Hi, I want to identify the files that are recently modified or with in a specified period (15 Days) in UNIX box. After identifying the files should be transferred to windows machine through FTP. The files should be overwritten in windows if it is already available. Please help... (1 Reply)
Discussion started by: lathish
1 Replies

6. Shell Programming and Scripting

Find most recent files in dirs and tar them up?

Hey all.. This should be simple but stoopid here can't get head around it! I have many directories, say 100 each with many files inside. I need a script to traverse through the dirs, find most recent file in each dir and add it to a tar file. I can find the files with something like for... (1 Reply)
Discussion started by: bobdung
1 Replies

7. AIX

List only the recent log files

Hi Friends, I have a list of files in a directory as shown below. It is basically in this format-> yymmdd.hhmmss.filename.out I want to list the latest log of each file. ie. the lastest a.out, b.out, c.out, which means I am looking for only the below 3 files out of these 5 files: ... (3 Replies)
Discussion started by: sudvishw
3 Replies

8. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

9. Shell Programming and Scripting

How to recursively copy directory only for recent files?

I love the -newerct flag for the Cygwin find command on windows. Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
Discussion started by: siegfried
4 Replies

10. Shell Programming and Scripting

Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks. Not sure if it makes a... (1 Reply)
Discussion started by: DavidHoffman
1 Replies
ftpls(1)						      General Commands Manual							  ftpls(1)

       ftpls - generate a ftp directory listing

SYNOPSIS
ftpls ftp://host[:port]/directory or ftpls host[:post] /directory DESCRIPTION
ftpls generates a listing of files and directories in a FTP directory. ftpls by default prints a human readable ascii output, but may also create HTML and machine parsable output. OPTIONS
Login options -u, --user=NAME Use NAME to login on the ftp server. Note that this option overrides an user name given in an URL. The default is `anonymous'. Use an empty name to force to not log in. -p, --pass=PASSWORD Use PASS as password to login on the ftp server. Note that this option overrides a password given in an URL. The default is `anonymous@invalid.example'. Use an empty password to enforce not sending any password. --account=ACCOUNT Send ACCOUNT as the account name using the ACCT ftp command if the ftp servers asks for one. ACCOUNT in ftp speak is some kind of sub account in some other terminologies. If you don't understand what it means you have a good chance to never need this option anyway. If you think you need it please try the -u option first. --tries=NUMBER Number of tries to connect and log in. The default is 1, meaning that ftpls will give up after the first error. --login-sleep=NUMBER ftpls will sleep for NUMBER seconds after a try to connect or login has failed. The default is 5, a zero is treated as one, and abuse (especially together with --tries) is likely to annoy the server administrator. This option was added in version 0.4.5. Output mode options -h, --html Create HTML index containing all files together with modification time and size. Note: The links in this index will contain username and password if you include them into an URL given to ftpls on the command line (either as argument or through the --urlprefix option). They will not be included otherwise, for security and privacy reasons. -m, --machine Create machine parsable output. -t, --title=TEXT Title text to use on the HTML output. -U, --urlprefix=URL URL-Prefix to use in listings. If this option is not given then an URL given on the command line will be used instead, and if this has not been given an URL will be created from host, port and directory given on the command line. --print-dir Print the name of a sub directory before printing it's content. Do not print the name of the top level directory of the listing. Use this option together with --raw. Do not use it together with --html. SORTING -a, --alpha sort alphabetical. -z, --omega sort reverse alphabetical. -n, --newest sort youngest first. -o, --oldest sort oldest first. -s, --shortest sort shortest first. -l, --longest sort longest first. Other options --ascii-listings Do directory listings in ASCII mode instead of binary mode. Use this option if the FTP server is unable to correctly list directories in binary mode, for example, if you see a message like this: ftpls: failed to read directory listing: protocol error This option was added in version 0.5.2. -L, --list-options=OPTS Add OPTS to LIST command. This allows to pass arbitrary options to the FTP servers LIST command. Note that ftpls does not cope well with recursive directory listings. --interactive ftpls will read the directories to be listed from the standard input. Any remote directory given on the command line will be ignored. Each directory listing is terminated by a END-OF-LISTING line. Do not use this together with the --html option. This option was added in version 0.3.6. -R, --recursive Do a recursive directory listing by first printing one directory, including sub directory names, and then traversing into sub directories. --raw Output directory listings in the original format and sort order. -T, --timeout=SECONDS Timeout to use for network read/write and connect operations. The default is 30 seconds and is usually sufficient. This option was added in version 0.3.8. --force-select Do not use the poll() system call even if it's available, but use select(). This allows ftpls to be used together with the runsocks program from the socks5 reference implementation. Please note that you'll need a directly reachable name server anyway, as the DNS library in use does not support SOCKS (you can always use IP addresses). This option was added in version 0.3.8. --max-depth Descend at most LEVEL directories deep. 0 means do not enter sub directories at all, 1 means enter sub-directories, but not their sub-directories, and so on. This option enables the --recursive option, too. The default is 2^32-1, meaning enter all. This option was added in version 0.5.2. EXAMPLES
Generate a HTML index page ftpls --html --title "CVS tree index by date" --urlprefix ftp://ftp.ohse.de/uwe/cvs-trees/ --newest ftp://serak.ohse.de/uwe/cvs-trees > SOMEWHERE/cvs-trees/index-by-date.html AUTHOR
Uwe Ohse, uwe@ohse.de SEE ALSO
ftpcopy(1). The homepage may be more up-to-date, see http://www.ohse.de/uwe/ftpcopy.html. ftpcopy 0.5.2 ftpls(1)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy