Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
09-06-2017, 09:24 AM
#1
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 5,963
How would you extract older entries from this listing?
I am working on a script to clean stale files from a local repository.
Given a listing like:
Code:
/var/cache/packages20170115/slackware/ap/zsh-5.3.1-i586-1.txz zsh 20170115
/var/cache/packages20170327/slackware/l/zlib-1.2.11-i586-1.txz zlib 20170327
/var/cache/packages20170115/slackware/l/zlib-1.2.10-i586-1.txz zlib 20170115
/var/cache/packages20170211/slackware/n/zd1211-firmware-1.5-fw-1.txz zd1211-firmware 20170211
/var/cache/packages20170115/slackware/n/ytalk-3.3.0-i586-3.txz ytalk 20170115
/var/cache/packages20170722/slackware/n/yptools-2.14-i586-8.txz yptools 20170722
/var/cache/packages20170115/slackware/a/xz-5.2.3-i586-1.txz xz 20170115
/var/cache/packages20170412/slackware/xap/xv-3.10a-i586-8.txz xv 20170412
/var/cache/packages20170715/slackware/x/xterm-330-i586-1.txz xterm 20170715
/var/cache/packages20170613/slackware/x/xterm-328-i586-1.txz xterm 20170613
/var/cache/packages20170115/slackware/x/xterm-327-i586-1.txz xterm 20170115
/var/cache/packages20161120/slackware/x/xterm-326-i586-1.txz xterm 20161120
/var/cache/packages20170709/slackware/xap/xscreensaver-5.37-i586-1.txz xscreensaver 20170709
/var/cache/packages20161102/slackware/xap/xscreensaver-5.36-i586-1.txz xscreensaver 20161102
/var/cache/packages20161120/slackware/x/xproto-7.0.31-noarch-1.txz xproto 20161120
/var/cache/packages20170818/slackware/x/xorg-server-xvfb-1.19.3-i586-2.txz xorg-server-xvfb 20170818
/var/cache/packages20170320/slackware/x/xorg-server-xvfb-1.19.3-i586-1.txz xorg-server-xvfb 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xvfb-1.19.2-i586-1.txz xorg-server-xvfb 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xvfb-1.19.1-i586-2.txz xorg-server-xvfb 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xvfb-1.19.1-i586-1.txz xorg-server-xvfb 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xvfb-1.19.0-i586-1.txz xorg-server-xvfb 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xvfb-1.18.4-i586-1.txz xorg-server-xvfb 20160724
/var/cache/packages20170818/slackware/x/xorg-server-xnest-1.19.3-i586-2.txz xorg-server-xnest 20170818
/var/cache/packages20170320/slackware/x/xorg-server-xnest-1.19.3-i586-1.txz xorg-server-xnest 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xnest-1.19.2-i586-1.txz xorg-server-xnest 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xnest-1.19.1-i586-2.txz xorg-server-xnest 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xnest-1.19.1-i586-1.txz xorg-server-xnest 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xnest-1.19.0-i586-1.txz xorg-server-xnest 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xnest-1.18.4-i586-1.txz xorg-server-xnest 20160724
/var/cache/packages20170818/slackware/x/xorg-server-xephyr-1.19.3-i586-2.txz xorg-server-xephyr 20170818
/var/cache/packages20170320/slackware/x/xorg-server-xephyr-1.19.3-i586-1.txz xorg-server-xephyr 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xephyr-1.19.2-i586-1.txz xorg-server-xephyr 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xephyr-1.19.1-i586-2.txz xorg-server-xephyr 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xephyr-1.19.1-i586-1.txz xorg-server-xephyr 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xephyr-1.19.0-i586-1.txz xorg-server-xephyr 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xephyr-1.18.4-i586-1.txz xorg-server-xephyr 20160724
/var/cache/packages20170818/slackware/x/xorg-server-1.19.3-i586-2.txz xorg-server 20170818
/var/cache/packages20170320/slackware/x/xorg-server-1.19.3-i586-1.txz xorg-server 20170320
/var/cache/packages20170311/slackware/x/xorg-server-1.19.2-i586-1.txz xorg-server 20170311
/var/cache/packages20170123/slackware/x/xorg-server-1.19.1-i586-2.txz xorg-server 20170123
/var/cache/packages20170115/slackware/x/xorg-server-1.19.1-i586-1.txz xorg-server 20170115
/var/cache/packages20161120/slackware/x/xorg-server-1.19.0-i586-1.txz xorg-server 20161120
/var/cache/packages20160724/slackware/x/xorg-server-1.18.4-i586-1.txz xorg-server 20160724
/var/cache/packages20170802/slackware/xap/xlockmore-5.54-i586-2.txz xlockmore 20170802
/var/cache/packages20170722/slackware/xap/xlockmore-5.54-i586-1.txz xlockmore 20170722
/var/cache/packages20170412/slackware/xap/xlockmore-5.51-i586-2.txz xlockmore 20170412
/var/cache/packages20170115/slackware/xap/xlockmore-5.50-i586-1.txz xlockmore 20170115
/var/cache/packages20170613/slackware/x/xkeyboard-config-2.21-noarch-1.txz xkeyboard-config 20170613
/var/cache/packages20160724/slackware/x/xkeyboard-config-2.18-noarch-1.txz xkeyboard-config 20160724
/var/cache/packages20170514/slackware/x/xkbcomp-1.4.0-i586-1.txz xkbcomp 20170514
/var/cache/packages20170115/slackware/xap/xine-ui-0.99.9-i686-2.txz xine-ui 20170115
/var/cache/packages20170802/slackware/xap/xine-lib-1.2.8-i586-3.txz xine-lib 20170802
/var/cache/packages20170722/slackware/xap/xine-lib-1.2.8-i586-2.txz xine-lib 20170722
/var/cache/packages20170412/slackware/xap/xine-lib-1.2.8-i586-1.txz xine-lib 20170412
/var/cache/packages20170211/slackware/xap/xine-lib-1.2.6-i586-10.txz xine-lib 20170211
/var/cache/packages20170115/slackware/xap/xine-lib-1.2.6-i586-9.txz xine-lib 20170115
/var/cache/packages20170320/slackware/xfce/xfwm4-4.12.4-i586-1.txz xfwm4 20170320
/var/cache/packages20170802/slackware/a/xfsprogs-4.12.0-i586-1.txz xfsprogs 20170802
/var/cache/packages20170626/slackware/a/xfsprogs-4.11.0-i586-1.txz xfsprogs 20170626
/var/cache/packages20170429/slackware/a/xfsprogs-4.10.0-i586-1.txz xfsprogs 20170429
how would you create a list of older versions of files that can be deleted?
The first field is the actual filename. (Needs to be expanded to include checksum and gpg files, with .md5 and .asc extensions respectively). The second field is the base package name.
The third field is the creation date in ISO format.
Last edited by allend; 09-06-2017 at 09:25 AM .
09-06-2017, 09:35 AM
#2
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 18,661
I would use a sort. In perl/python/other languages you can easily construct your own comparison operator which will make it quite easy. But probably a string based sort is enough
09-06-2017, 09:37 AM
#3
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,628
What do you do now?
Not trying to be too flip with my answer. My base advice for any script is "Whatever you can type in a command line, you can code into a bash script."
Hence my points here are:
You didn't fully describe your qualifications as to what constitutes a stale file
You did not show any actions which you currently take to remedy this manually
If you currently do have a manual remediation process which you follow, then it would be good to know what you do, for some/all of the other points.
09-06-2017, 09:37 AM
#4
LQ Guru
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 6,386
find will do it. It will find files based on all sorts of criteria, and creation date is one of them. For example, you can find all files created more than one month ago and either list them for deletion or delete them on the fly, using find 's -delete option. Read the find man page for more detail.
09-06-2017, 09:48 AM
#5
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 5,963
Original Poster
My bad
What I am asking is how would you extract a listing like:
Code:
/var/cache/packages20170115/slackware/l/zlib-1.2.10-i586-1.txz zlib 20170115
/var/cache/packages20170613/slackware/x/xterm-328-i586-1.txz xterm 20170613
/var/cache/packages20170115/slackware/x/xterm-327-i586-1.txz xterm 20170115
/var/cache/packages20161120/slackware/x/xterm-326-i586-1.txz xterm 20161120
/var/cache/packages20161102/slackware/xap/xscreensaver-5.36-i586-1.txz xscreensaver 20161102
/var/cache/packages20170320/slackware/x/xorg-server-xvfb-1.19.3-i586-1.txz xorg-server-xvfb 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xvfb-1.19.2-i586-1.txz xorg-server-xvfb 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xvfb-1.19.1-i586-2.txz xorg-server-xvfb 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xvfb-1.19.1-i586-1.txz xorg-server-xvfb 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xvfb-1.19.0-i586-1.txz xorg-server-xvfb 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xvfb-1.18.4-i586-1.txz xorg-server-xvfb 20160724
/var/cache/packages20170320/slackware/x/xorg-server-xnest-1.19.3-i586-1.txz xorg-server-xnest 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xnest-1.19.2-i586-1.txz xorg-server-xnest 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xnest-1.19.1-i586-2.txz xorg-server-xnest 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xnest-1.19.1-i586-1.txz xorg-server-xnest 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xnest-1.19.0-i586-1.txz xorg-server-xnest 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xnest-1.18.4-i586-1.txz xorg-server-xnest 20160724
/var/cache/packages20170320/slackware/x/xorg-server-xephyr-1.19.3-i586-1.txz xorg-server-xephyr 20170320
/var/cache/packages20170311/slackware/x/xorg-server-xephyr-1.19.2-i586-1.txz xorg-server-xephyr 20170311
/var/cache/packages20170123/slackware/x/xorg-server-xephyr-1.19.1-i586-2.txz xorg-server-xephyr 20170123
/var/cache/packages20170115/slackware/x/xorg-server-xephyr-1.19.1-i586-1.txz xorg-server-xephyr 20170115
/var/cache/packages20161120/slackware/x/xorg-server-xephyr-1.19.0-i586-1.txz xorg-server-xephyr 20161120
/var/cache/packages20160724/slackware/x/xorg-server-xephyr-1.18.4-i586-1.txz xorg-server-xephyr 20160724
/var/cache/packages20170320/slackware/x/xorg-server-1.19.3-i586-1.txz xorg-server 20170320
/var/cache/packages20170311/slackware/x/xorg-server-1.19.2-i586-1.txz xorg-server 20170311
/var/cache/packages20170123/slackware/x/xorg-server-1.19.1-i586-2.txz xorg-server 20170123
/var/cache/packages20170115/slackware/x/xorg-server-1.19.1-i586-1.txz xorg-server 20170115
/var/cache/packages20161120/slackware/x/xorg-server-1.19.0-i586-1.txz xorg-server 20161120
/var/cache/packages20160724/slackware/x/xorg-server-1.18.4-i586-1.txz xorg-server 20160724
/var/cache/packages20170722/slackware/xap/xlockmore-5.54-i586-1.txz xlockmore 20170722
/var/cache/packages20170412/slackware/xap/xlockmore-5.51-i586-2.txz xlockmore 20170412
/var/cache/packages20170115/slackware/xap/xlockmore-5.50-i586-1.txz xlockmore 20170115
/var/cache/packages20160724/slackware/x/xkeyboard-config-2.18-noarch-1.txz xkeyboard-config 20160724
/var/cache/packages20170722/slackware/xap/xine-lib-1.2.8-i586-2.txz xine-lib 20170722
/var/cache/packages20170412/slackware/xap/xine-lib-1.2.8-i586-1.txz xine-lib 20170412
/var/cache/packages20170211/slackware/xap/xine-lib-1.2.6-i586-10.txz xine-lib 20170211
/var/cache/packages20170115/slackware/xap/xine-lib-1.2.6-i586-9.txz xine-lib 20170115
/var/cache/packages20170626/slackware/a/xfsprogs-4.11.0-i586-1.txz xfsprogs 20170626
/var/cache/packages20170429/slackware/a/xfsprogs-4.10.0-i586-1.txz xfsprogs 20170429
from the listing in post #1?
09-06-2017, 09:55 AM
#6
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
What defines stale?
Just use apt-get's autoclean?
Quote:
autoclean (and the auto-clean alias since 1.1)
Like clean, autoclean clears out the local repository of retrieved
package files. The difference is that it only removes package files
that can no longer be downloaded, and are largely usele ss. This
allows a cache to be maintained over a long period without it
growing out of control. The configuration option
APT::Clean-Installed will prevent installed packages from being
erased if it is set to off.
Last edited by Sefyir; 09-06-2017 at 09:56 AM .
1 members found this post helpful.
09-06-2017, 09:58 AM
#7
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,628
Still sorry, but is there a better way to describe this other than asking us to compare two moderately long lists from different posts? The very plain and simple up/down/up on the browser while totally ineffective, tells me that the first entries are different, entirely. I fear that if I take the time to load them up into something like emacs and use ediff to compare I may find 20-30 lines which are just ... different.
09-06-2017, 10:10 AM
#8
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 5,963
Original Poster
Quote:
Hence my points here are:
You didn't fully describe your qualifications as to what constitutes a stale file
You did not show any actions which you currently take to remedy this manually
If you currently do have a manual remediation process which you follow, then it would be good to know what you do, for some/all of the other points.
1. File created before the last date
2. Manual action is what I want to remove.
3. I want to eliminate the manual cut and paste process
09-06-2017, 01:33 PM
#9
Member
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792
Perhaps I'm missing something but awk will produce the second listing from the first:
Code:
awk 'dups[$2]++' input_file
You will need to sort if the first list is not ordered by base package name then by date descending.
1 members found this post helpful.
09-06-2017, 09:08 PM
#10
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 5,963
Original Poster
Thanks! Just what I needed.
All times are GMT -5. The time now is 12:46 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News