Clean all command in linux

How to check and clean Linux System’s Disk Space

On a Linux system, freeing up disk space may be required if there arises a need to install more software. Another cause could be that the system’s disk space is severely low, as indicated by any relevant warning. Clearing disk space in a Linux system to free up storage space is a certainty that will arise at some point.

This guide outlines the basic steps that can be performed to check the disk space status in a Linux server and also the actions that can be carried out to free up disk space in the Linux system.

Checking disk space status in Linux

There are two commands available for finding available and used disk space in a Linux server, which are namely the df and du commands.

1. Using the df command

The df command can be used to view the available disk space for each drive on the Linux system.

By default, the df output shows the usage in KB. You can use the -h option to make the output easier to read. This option shows the amount of disk space available in kilobytes (K), megabytes (M), and gigabytes (G).

Executing the df command alone will list the disk space usage without any formatting.

linuxdisk1

The -h option can be used along with df command to show the results in a human-readable format.

linuxdisk2

The below command can be executed to list the disk space with file system types.

linuxdisk3

The df command can also be used to target a specific drive, using either its Filesystem or Mounted on description from the disk space results being displayed.

linuxdisk4

linuxdisk5

2. Using the du command

In a Linux system, the du command is used to determine how much disk space is being utilized by files and folders. For this purpose, different switches can be used to retrieve the appropriate output.

The file/folder size is usually displayed in KB while using the du command. The -h switch can be used to display values in human-readable units such as KB, MB, GB and TB. To get the overall directory utilization, the -s and -c switches are used, in which the -c switch is used to get subtotal of the items.

The below set of example commands shows the different uses of the above-specified switches when used along with the du command. The example folder being considered in this context is /boot .

Using the du command alone will show the disk space usage of the folder as well as the files under it.

linuxdisk6

Using the -s switch summarizes and shows the total disk usage by the argument value passed along with the du command.

linuxdisk7

By using the -c switch along with the above command, the grand total disk usage value of the folder can be displayed.

Читайте также:  Linux узнать битность системы

linuxdisk8

The total disk space usage in human-readable format can be displayed by using the -h switch in the above command.

linuxdisk9

Cleaning/clearing disk space on Linux system

Once the disk space in the server is noticed to be running low, it is a requirement that enough disk space is freed up in the server for the services to be running without interruption. Some of the common actions that can be performed in order to free-up disk space in a Linux system are mentioned below:

Autoremove feature

Most package managers come with an autoremove option that can be used to remove any unwanted packages on the server. The autoremove option is used to clean up the unwanted packages and their dependencies along with it.

The autoremove option can be used to clean up unwanted packages as described below depending on the OS distribution installed in the server.

For CentOS, AlmaLinux and Rocky Linux distros, the autoremove option can be used along with yum command.

linuxdisk10

With Debian and Ubuntu distributions, the APT’s version of the autoremove command can be used.

linuxdisk11

For other distributions using dnf , the below command can be used.

linuxdisk12

Clearing the package cache

A clean command is usually included in Linux package managers which can be used to clear the package manager’s cache. It is also a good command to use if package-related issues are being generated because of corrupted metadata.

Use the below command for Debian and Ubuntu.

linuxdisk13

There is also an autoclean option in APT. This command clears the cache for packages that are no longer available in APT’s repositories.

linuxdisk14

For CentOS/Fedora/AlmaLinux/Rocky Linux that uses YUM and DNF , the option related to what is to be cleared from the cache is to be indicated. Metadata, packages, and all are the most useful alternatives.

The below example YUM command deletes all cached data.

linuxdisk15

Removing unused installed packages

If the system is still running on low disk space, any installed packages that are no longer used can also be removed to free up disk space.

For Debian/Ubuntu distros:

Execute either of the below commands to see the list of installed packages:

# sudo apt list --installed OR dpkg -l 

linuxdisk16

linuxdisk17

Remove the package that is no longer needed by using the below command:

linuxdisk18

NOTE: Replace «package name» with the actual package name that needs to be removed. In the above example, the package that is being removed is wget.

For CentOS/Fedora/AlmaLinux/Rocky Linux distros that uses YUM and DNF :

Execute any of the below commands to see the list of installed packages:

# yum list installed OR # rpm -qa 

linuxdisk19

linuxdisk20

Run the below command to remove the package that is no longer needed.

# yum remove -y OR # dnf remove -y 

linuxdisk21

linuxdisk22

NOTE: Replace «package name» with the actual package name that needs to be removed. In the above example, the package that is being removed is wget.

In the case of APT, the purge option can also be used to destroy all associated files with the deleting package. The rpm or dpkg commands can also be used to delete packages without affecting their dependencies.

Читайте также:  Brave browser для linux

Источник

How to clear bash history completely?

I want to clear all previous commands from the history of my server. I used history -c and it seems all things are cleared but when I ssh to the server, all the commands are still there. How can I clear them permanently?

9 Answers 9

The file ~/.bash_history holds the history.

To clear the bash history completely on the server, open terminal and type

cat /dev/null > ~/.bash_history 

Other alternate way is to link ~/.bash_history to /dev/null

However,

One annoying side-effect is that the history entries has a copy in the memory and it will flush back to the file when you log out.

To workaround this, use the following command (worked for me):

cat /dev/null > ~/.bash_history && history -c && exit 

you can also put above command in .bashrc & .bash_logout . what it mean when you login u will have clear history & when you logout out your history will be cleared

I tried to do it on a raspberry box while connected via SSH. I added the above command ( cat /dev/null > ~/.bash_history && history -c && exit ) to both .bashrc & .bash_logout as suggested by @Qasim . Now as soon as I connect via SSH the remote host closes the connection (after printing the motd) . Help :/

Goes to show what happens when you blindly do things without reading properly and without understanding the processing and data flow. It also shows the pitfalls of bad communication. What devav2 did was run it one time, and what Qasim should have written is to remove the exit command before adding it in login script.

In every open bash shell (you may have multiple terminals open):

Why: As noted above, history -c empties the file ~/.bash_history . It is important to note that bash shell does not immediately flush history to the bash_history file. So, it is important to (1) flush the history to the file, and (2) clear the history, in all terminals. That’s what the commands above do.

For some reason this does not work on Ubuntu 14.04, probably others. It should but it doesn’t. If you issue the command «history -cw» you can confirm with the up arrow that the history isn’t there anymore, but if you start another terminal window (in Unity desktop) with shift + click on the terminal icon (I have it pinned in the launcher) the commands history are back, no matters how many times you do «history -cw». «cat /dev/null > ~/.bash_history» is the only way that worked for me.

It’s history -c and then history -w, you first clear the history then write the changes. This is easily confirmed by closing the terminal and opening it again, with -w first the commands are there again, with -w last history is effectively cleared.

execute the following commands to clear history forever

This answer would be even more helpful if it explained what these flags do (and therefore why/when they’re the right commands to use).

There’s another much simpler one: running history -c on the terminal prompt and gone are all entries in the bash_history file.

Читайте также:  Linux file copy with permissions

If you read the OP’s question you would know that using history -c is the exact method that led to this question.

Clear the current shell’s history:

When you log out, your current shell’s history is appended to ~/.bash_history, which is a cache of previous shells’ histories, to a maximum number (see HISTFILESIZE in «man bash»).

If you want to remove the history altogether, then you essentially have to empty out ~/.bash_history which many of the above entries have suggested. Such as:

This clears the current shell’s history and then forces the current shell’s history (empty) to overwrite ~/.bash_history. or to be more accurate, it forces it to overwrite HISTFILE (which defaults to ~/.bash_history).

Источник

15 useful YUM commands for Beginners

yum command in linux with examples

YUM stands for Yellowdog Updater Modified, which is an RPM (RedHat Package Manager) based package management tool for Linux Systems. Yum was introduced in RHEL version 5.10 onward and its deprecated ‘up2date’ command. Yum, command helps all Users and System Administrators to search for information about packages and then install, update, and remove all rpm related files from systems. The advantage of using YUM will be automatically performing the dependency resolution in a single command, even its supports to install the packages from various 3rd party repositories without any issue of dependencies. Yum was developed and released under GPL (General Public License), which means it comes under free software licenses that permit the end-user to modify the source code of the software.

The main configuration file of YUM is located at «/etc/yum.conf» and the .repo extensions are stored at «/etc/yum.repos.d» directory. By using the ‘yum command’ we can install all the packages directly from the internet, also we can set up a local yum repository by using the .iso or DVD. Using the local repository will help us to do a bulk update/patching the systems in the network and it saves a good amount of Internet bandwidth. The yum utility is a big relief on all types of .rpm based software dependency issues and it helps all the installers to speed-up the package management related tasks.

RHEL / CentOS 8 comes with the updated version (v4.0.4) of the YUM package manager, which is named DNF (Dandified Yum). DNF was initially introduced to Fedora 18 and is now the default package manager for Fedora 22 and RHEL 8. For more details about DNF click here

In this article, you will see the most used 15 yum commands, which will help all the newbies and System Administrators with their day-to-day activities. All the below examples of ‘yum’ commands are tested on RHEL and CentOS 7.8.

Prerequisites :

Operating System : CentOS/ RHEL
User account : root user or user account with sudo privileges
Recommended to run all the administrative commands as with sudo privilege instead of root

Difficulties in setting up sudo users? Click here to find the steps.

Global Syntax of yum command in Linux:

The following table provides an overview of the options of ‘yum’ command in RHEL / CentOS

Источник

Оцените статью
Adblock
detector