In theory, this should be fairly straightforward. If you want to delete all files created from 2017 and beyond (i.e. also files from 2016, 2015, etc - anything older than 2017), then you could do something like this:
That would find all files older than 549 days (at the time of writing, the number of days since December 31st 2017) and remove them.
Now, if you really want to only remove files from 2017, and only 2017, then it's slightly more complicated, but not much so. Assuming your version of find supports it, this would do the trick:
This will very specifically remove files whose modification time is newer than 1st January 2017, but not newer than 1st January 2018 (in other words - files from 2017).
Hope this helps. Please test carefully before running this with a live rm command - swap it out for an ls or switch out the -exec for a -print first just to be sure it really is going to catch what you want, and only what you want, before turning this loose on your filesystem for real.
These 2 Users Gave Thanks to drysdalk For This Post:
I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used
( ls -lR |... (5 Replies)
Hi,
Would like to ask, which command is used to list all the files for specific date (says 1st May) and its size, for all files (including its subdirectory), in a mounted NFS disk to HP-UX.
I would like to check for the total files came into my disk on 1st May.
Very much appreciating your... (2 Replies)
There is a system logging a huge amount of data and we need to delete some of the older logs .I mean the files that are created before one week from today. Here is a listing of files that are sitting there:
/usr/WebSphere/AppServer/logs
# ls -l
-rw-r--r-- 1 root system 3740694 May... (5 Replies)
can someone provide a command to delete files by year? I have several files created last year 2009.
Im trying to list first ls -lrt | grep '/2009/ {print $10}' by it returns no result.
Pls advise (2 Replies)
Hi
I have lot of files and subdirectories inside a directory which are created in the years 2006, 2007, 2008, 2009 and 2010.
I want to delete all the files and subdirectories belonging to the year 2006 alone.
How can I do that ? (5 Replies)
Hi All,
I want to login to a remote server using FTP command and then check for files older than 1 year and delete those files.
Please let me know how can i achieve this using Unix Commands.
Thanks in Advance, (10 Replies)
Hi,
I want to display the file names and the record count for the files in the 2nd column for the files created today.
i have written the below command which is listing the file names. but while piping the above command to the wc -l command
its not working for me.
ls -l... (5 Replies)
Hi All,
how can i delete files from my Unix directory on the basis of year, i have files from 2001 to till 2014, but from their, i have to delete only 2013 file.Below is my file name
rwxrwxrwx 1 guopt users 5169 Jul 12 00:30 grt592_20130712003000.SAP
Thanks
Kki (2 Replies)
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)
Hello Gurus,
I am facing one issue to get a file for a specific time. There are about 300 files created between 6.30 pm to 7.15 pm everyday.
Now I wanted only the file which is created on 6.45pm. No other files required.
I have used "find" command to get the files, but not getting the expected... (3 Replies)
Discussion started by: pokhraj_d
3 Replies
LEARN ABOUT BSD
find
FIND(1) General Commands Manual FIND(1)NAME
find - find files
SYNOPSIS
find pathname-list expression
find pattern
DESCRIPTION
In the first form above, find recursively descends the directory hierarchy for each pathname in the pathname-list (i.e., one or more path-
names) seeking files that match a boolean expression written in the primaries given below. In the descriptions, the argument n is used as
a decimal integer where +n means more than n, -n means less than n and n means exactly n.
The second form rapidly searches a database for all pathnames which match pattern. Usually the database is recomputed weekly and contains
the pathnames of all files which are publicly accessible. If escaped, normal shell "globbing" characters (`*', `?', `[', and ']') may be
used in pattern, but the matching differs in that no characters (e.g. `/') have to be matched explicitly. As a special case, a simple pat-
tern containing no globbing characters is matched as though it were *pattern*; if any globbing character appears there are no implicit
globbing characters.
-name filename
True if the filename argument matches the current file name. Normal shell argument syntax may be used if escaped (watch out for
`[', `?' and `*').
-perm onum
True if the file permission flags exactly match the octal number onum (see chmod(1)). If onum is prefixed by a minus sign, more
flag bits (017777, see stat(2)) become significant and the flags are compared: (flags&onum)==onum.
-type c True if the type of the file is c, where c is b, c, d, f, l or s for block special file, character special file, directory, plain
file, symbolic link, or socket.
-links n True if the file has n links.
-user uname
True if the file belongs to the user uname (login name or numeric user ID).
-nouser True if the file belongs to a user not in the /etc/passwd database.
-group gname
True if the file belongs to group gname (group name or numeric group ID).
-nogroup True if the file belongs to a group not in the /etc/group database.
-size n True if the file is n blocks long (512 bytes per block).
-inum n True if the file has inode number n.
-atime n True if the file has been accessed in n days.
-mtime n True if the file has been modified in n days.
-exec command
True if the executed command returns a zero value as exit status. The end of the command must be punctuated by an escaped semi-
colon. A command argument `{}' is replaced by the current pathname.
-ok command
Like -exec except that the generated command is written on the standard output, then the standard input is read and the command
executed only upon response y.
-print Always true; causes the current pathname to be printed.
-ls Always true; causes current pathname to be printed together with its associated statistics. These include (respectively) inode
number, size in kilobytes (1024 bytes), protection mode, number of hard links, user, group, size in bytes, and modification time.
If the file is a special file the size field will instead contain the major and minor device numbers. If the file is a symbolic
link the pathname of the linked-to file is printed preceded by ``->''. The format is identical to that of ``ls -gilds'' (note
however that formatting is done internally, without executing the ls program).
-newer file
True if the current file has been modified more recently than the argument file.
-cpio file
Write the current file on the argument file in cpio format.
-xdev Always true; causes find not to traverse down into a file system different from the one on which current argument pathname
resides.
The primaries may be combined using the following operators (in order of decreasing precedence):
1) A parenthesized group of primaries and operators (parentheses are special to the Shell and must be escaped).
2) The negation of a primary (`!' is the unary not operator).
3) Concatenation of primaries (the and operation is implied by the juxtaposition of two primaries).
4) Alternation of primaries (`-o' is the or operator).
EXAMPLES
To find all accessible files whose pathname contains `find':
find find
To typeset all variants of manual pages for `ls':
vtroff -man `find '*man*/ls.?'`
To remove all files named `a.out' or `*.o' that have not been accessed for a week:
find / ( -name a.out -o -name '*.o' ) -atime +7 -exec rm {} ;
FILES
/etc/passwd
/etc/group
/var/db/find.codes coded pathnames database
SEE ALSO sh(1), test(1), fs(5)
Relevant paper in February, 1983 issue of ;login:.
BUGS
The first form's syntax is painful, and the second form's exact semantics is confusing and can vary from site to site.
More than one `-newer' option does not work properly.
7th Edition October 11, 1996 FIND(1)