2

I'm having space problems in the root folder and one of the folders that contains many files is /usr/share/doc/texlive-doc, I would like to know, there is a way for me to use a command that goes through the entire folder and deletes only file with .pdf extension?

This is on Ubuntu 16.04.

Eliah Kagan
  • 117,780
  • 1
    Look for find command and -exec or -delete options. But be really careful you might end up removing anything you have. – Ravexina Jun 11 '20 at 18:03
  • 1
    Here is a list of packages that have file in there: https://paste.ubuntu.com/p/G8TShqgwCc/. Found using apt-file search '/usr/share/doc/texlive-doc' | grep pdf | cut -f1 -d: | sort | uniq – Ravexina Jun 11 '20 at 18:07
  • I didn't understand what that last command does... – Marcelo João Jun 11 '20 at 18:29
  • I don't know what this texlive is... I didn't install it. In fact, I have TexStudio, but decide to remove it as a test to find out if it would remove space from the folder and it didn't happen. Removing the .pdf files I believe there are no risks. – Marcelo João Jun 11 '20 at 18:31
  • Incidentally, Ubuntu itself has a solution for problems, but I also didn't understand what the command does... it's in the '' Documentation '' tab... https://wiki.ubuntu.com/ReducingDiskFootprint#Documentation – Marcelo João Jun 11 '20 at 18:33
  • @N0rbert I don't think so, but thanks for the answer. – Marcelo João Jun 11 '20 at 18:34
  • Take a second look at @Norbert's link. Removing packages and program files is rarely the best way to free up space. Something is taking up all your space, and it seems like you're not sure what it is. The link tells you how to find out. – user535733 Jun 11 '20 at 18:40
  • I have a free space of swap memory but I don't know if I should add it to the root directory... I'm afraid this will crash the system! – Marcelo João Jun 11 '20 at 18:42
  • @user535733 but I dont have Ubuntu Server... – Marcelo João Jun 11 '20 at 18:44
  • It's the same process whether you have Desktop, Server, Core, etc. Debating whether or not to use swap for storage is a dead-end - there is no useful solution on that path. – user535733 Jun 11 '20 at 18:47
  • If you don't need texlive (if you don't know what LaTeX or TeX is you probably don't) you can remove that package which should also remove the pdf's – Thorbjørn Ravn Andersen Jun 12 '20 at 08:44

4 Answers4

7

I would not recommend manually deleting from the root directory as it could cause programs to break, and they will just be replaced next time you update.

I would try to find entire packages you no longer need before resorting to this. there are many ways to do this, on Ubuntu I would first run sudo apt-get autoremove. This will find packages which were installed as dependencies for programs, but are no longer needed by anything.

It might be a good idea to look in the Ubuntu Software Centre to get a list of all the programs you have installed. If you're like me, you'll have installed loads of programs you no longer use, or maybe intended to use and never did.

5

I guess the correct way is to tell dpkg you don't want to install documentation. See Ubuntu Wiki.

Is this so much space? Check with:

find /usr/share/doc/texlive-doc/ -iname '*.pdf' | xargs du -sch

If you really wish to do the wrong way, you may as well remove them with the following command:

sudo find /usr/share/doc/texlive-doc/ -iname '*.pdf' -exec rm {} \;

but I guess they will be added again on update.

terdon
  • 100,812
LEo
  • 479
  • I saw this page earlier, I even mentioned it in a comment above ... but I believe that this configuration should be done after installing UBuntu, at the moment I am it will not help. In fact, the Wiki itself recommends a code

    if [ "$1" = "configure" ] && [ -z "$2" ]; then... fi but I didn't feel confident using it.

    – Marcelo João Jun 11 '20 at 18:40
  • I guess you'd have to edit /var/lib/dpkg/info/texlive-base.postinst... but is will not be straightforward... :-/ – LEo Jun 11 '20 at 20:24
  • 3
    Ubuntu uses GNU find, which supports the -delete flag. No reason to fork a separate process. – Jochen Lutz Jun 12 '20 at 07:40
  • @JochenLutz Adding to your comment, even using separate processes, it's better to do find -print0 | xargs-0r rm -f to (drastically) reduce # of processes generated. – iBug Jun 12 '20 at 12:37
  • 1
    @LEo I removed the -f since it isn't needed and it is always better to avoid dangerous flags unless they are necessary. While it would really be better to just use -delete instead of exec rm {} \;, if you want to use -exec, at least make it -exec rm {} + to avoid running one process per file. – terdon Jun 12 '20 at 14:11
4

The files in /usr/share/doc/texlive are all documentation for texlive - a popular TeX distribution for Linux - and were installed when you installed texlive, and its related packages. For files installed by system packages, it's generally better to just uninstall the packages, rather than to attempt to delete the files, since this may cause issues, and the files may be recreated if the package is updated.

If you do still want texlive, but don't want the documentation any more, you can do:

sudo apt remove 'texlive-*-doc'

to remove all documentation-related packages - although some texlive components may not have split documentation into separate packages, so some documentation may remain. If, on the other hand, you simply don't want texlive any more, you can do:

sudo apt purge texlive 'texlive-*'

which will remove all texlive related packages from your system, and all files related to them.

I would also add that whilst texlive is one of the bigger packages, it's unlikely that it's the biggest contributor to your space issues. Ubuntu has a tool "Disk Usage Analyser" that can tell you what is actually taking up space.

James_pic
  • 439
  • 3
  • 6
0

Use crontab .I have done this in ubuntu 18.04

verify with

dpkg -l cron

then

crontab -e

add the line like

@reboot rm /folder/folder/*.pdf

this will remove pdf at time of restarting the system. You can also schedule cronjob which I have not done.

For base start

https://www.liquidweb.com/kb/create-a-cron-task-in-ubuntu-16-04/

https://www.alibabacloud.com/blog/how-to-automate-and-schedule-tasks-with-crontab-on-ubuntu-16-04_594117

Gopipuli
  • 143