Score:4

How to free up some disk space on my Linux machine?

jo flag

I'm still new to the Linux world, My disk size is 493 G

And when I use the command du -hs * /opt/conda, The total size I use is less than 95g

enter image description here

But when I use the df -h command:

  • Disk Size is 493 G
  • Used 404 G
  • Available 89 G

enter image description here

  • So, (493 - 95) = 398 G available not just only 89 G

What can i do with that ?

I tried to use this command sudo apt-get autoremove to remove any unnecessary packages but it just free about 50 M only.

And when i try this sudo parted -l & lsblk -f This is the output:

enter image description here

The OS & release :

enter image description here

oldfred avatar
cn flag
Did you use LVM? It does not automatically use full space, so user has options to either expand or add volumes. Post this: `sudo parted -l` & `lsblk -f`
Kareem Shehata avatar
jo flag
I've tried them, but I still don't understand what the solution is.
Kareem Shehata avatar
jo flag
It's Ubunto, Sir.
guiverc avatar
cn flag
I'd apply system upgrades asap; 20.04.3 shows you're well behind as an updated system switched to reporting itself as 20.04.4 early in 2022 (*in weeks before ISO release date shown* https://fridge.ubuntu.com/2022/02/25/ubuntu-20-04-4-lts-released/) and a fully upgraded system has reported itself as [20.04.5](https://fridge.ubuntu.com/2022/09/01/ubuntu-20-04-5-lts-released/) for awhile now too, so I hope you keep that box offline.
Kareem Shehata avatar
jo flag
I think i don't have the permission to update the system, plus what does that supposed to do with the disk space !!
oldfred avatar
cn flag
Do you have LVM? You scratched out name of volume? Post `sudo pvs` & `sudo vgs` & `sudo lvs` You may just need lvextend command. example:https://ubuntuforums.org/showthread.php?t=2482037&p=14124677#post14124677
pk flag
why * and /opt/conda specifically? don't you want to see the whole hard drive?
Kareem Shehata avatar
jo flag
@user253751 The rest are very small files and I checked that.
pk flag
One cause of invisible disk space usage on Linux is if a program creates a log file, and writes a lot of log messages, and something else deletes the log file. The file isn't deleted until all programs close it, but now it doesn't have any name so you can't find it. In this case a reboot would free the space. and there's probably a tool somewhere to find these files.
Kareem Shehata avatar
jo flag
@user253751 I think this is one of the reasons because I deleted some environments with this "rm -r" command. Is this a wrong way to clear it ?? And unfortunately i don't have the permission to reboot the system.
Kareem Shehata avatar
jo flag
@oldfred I've really tried everything to install LVM with this command "apt install lvm2" but it always fails.
oldfred avatar
cn flag
You almost never use rm command, too easy to do a typo. If you have LVM, you should not need to reinstall it. But if you deleted something important, the only way to recover is to do a new install & restore from backup. Normal rule is if it takes more than an hour to fix, easier with Ubuntu to just reinstall & restore your backups.
pk flag
@oldfred "almost never use rm command" - wtf? then how do you delete things?
oldfred avatar
cn flag
I forgot you are a command line only user. New users or those with gui should not use rm. I have seen this recommendation: alias rm='mv --target-directory ~/.Trash' Not sure if ~ works correctly if in root.
Score:2
us flag

You can use the Disk Usage Analyzer tool to find files and directories occupying majority of your space.

In case it is not installed, you can install it with the terminal command

sudo apt install baobab
Kareem Shehata avatar
jo flag
I don't have an interface, it's just like a SSH connection.
Score:0
in flag

This command covers the most common tasks I use to create disk space:

sudo apt-get autoremove && sudo apt-get autoclean && sudo journalctl --rotate && sudo journalctl --vacuum-size=100M

This is because the local apt-get repo and the journal logs are a common source of unneeded large files, sometimes taking up many GB of space.

apt-get autoremove removes apt dependencies that are no longer dependencies, apt-get autoclean clears the local cache of package files that can no longer be downloaded, journalctl --rotate marks all journal logs as archived, and sudo journalctl --vacuum-size=100M limits the journal logs to 100MB total.

This may not entirely solve your disk space problem, but it's a good place to start.

A good next step is to install and use the nCurses Disk Usage tool to locate large files:

sudo apt-get install ncdu
sudo ncdu /
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.