Sponsored Content
Top Forums Shell Programming and Scripting Delete all but 3 newest files Post 303021458 by RudiC on Thursday 9th of August 2018 02:00:34 PM
Old 08-09-2018
Had you taken to heart the advice given in your other thread to use an easy to sort date format (2018-08-01T01:02, or epoch seconds), it would be a simple
Code:
ls -1r Ubuntu_Documents.zip_* | tail -n+4

to find the to-be-deleted files...
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the newest files based on date

Hello friends, I'm learning to script, and I need help. How can I get the latest/newest files based on date? the format is as following: Feb 07 19:25 TESTPWD_file_1vk6pn40_19519_1 Feb 07 19:46 TESTPWD_file_1uk6pn40_19518_2 Feb 07 19:47 TESTPWD_file_20k6pn40_19520_2 Feb 07 19:56... (5 Replies)
Discussion started by: Beginer0705
5 Replies

2. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

3. Homework & Coursework Questions

Newest file changed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The program should search all files in current directory and it's subdirectories and list out the newest file by... (8 Replies)
Discussion started by: petel1
8 Replies

4. Shell Programming and Scripting

finding the 5 newest files in a directory

I have a folder that has new files created everyday, is there a way i can filter them so that only the 5 newest files are displayed? I'm hoping this can be done by a one liner without a script. for example my directory contains -rw-r--r-- 1 root root 0 Jun 24 08:34 file112 -rw-r--r-- 1 root... (2 Replies)
Discussion started by: zerofire123
2 Replies

5. Shell Programming and Scripting

Get the newest file in a directory.

I am new to shell scripting so i need some help need how to go about with this problem. I have a directory which contains files in the following format. The files are in a diretory called /incoming/external/data AA_20100806.dat AA_20100807.dat AA_20100808.dat ... (4 Replies)
Discussion started by: ziggy25
4 Replies

6. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

7. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

8. Shell Programming and Scripting

Delete all but newest of given file name type

I use this to make it easier to see when a backup script ran. touch /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/$( date '+%m-%d-%Y_%I:%M-%p' ) I would like a script that would delete all but the newest file ONLY of this type 08-20-2018_01:24-PM (4 Replies)
Discussion started by: drew77
4 Replies

9. Shell Programming and Scripting

Remove all but newest two files (Not a duplicate post)

TARGET_DIR='/media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/' REGEX='{4}-{2}-{2}_{2}:{2}' # regular expression that match to: date '+%Y-%m-%d_%H:%M' LATEST_FILE="$(ls "$TARGET_DIR" | egrep "^${REGEX}$" | tail -1)" find "$TARGET_DIR" ! -name "$LATEST_FILE" -type f -regextype egrep -regex... (7 Replies)
Discussion started by: drew77
7 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 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy