redhat 7 – My Random Tips https://www.myrandomtips.com Useful Tips to Save Time Thu, 04 Jun 2020 14:26:18 +0000 en hourly 1 https://wordpress.org/?v=6.8.1 https://www.myrandomtips.com/wp-content/uploads/2017/10/cropped-light-bulb-icon-42x42.png redhat 7 – My Random Tips https://www.myrandomtips.com 32 32 linux directory size https://www.myrandomtips.com/linux/linux-directory-size/ https://www.myrandomtips.com/linux/linux-directory-size/#respond Sun, 25 Aug 2019 13:47:20 +0000 https://www.myrandomtips.com/?p=765 This guide will teach you several commands I use frequently on how to show the linux directory size in Centos or Redhat and what folders are using the most space all listed in MB. Here is a list of common commands I use that you may find helpful. Search current Centos or RedHat Folder You search the current… Read More »

The post linux directory size appeared first on My Random Tips.

]]>

This guide will teach you several commands I use frequently on how to show the linux directory size in Centos or Redhat and what folders are using the most space all listed in MB.

Here is a list of common commands I use that you may find helpful.

Search current Centos or RedHat Folder

You search the current folder sizes down in the command using this command:

du -h --max-depth=1  |grep -v -e [0-9].[0-9]K -e [0-9][0-9]K -e ^0 | sort -n

Find top 10 largest files in a folder in linux

You search a given folder for the largest top 10 files in a given folder using this command:

find /home/simon/Downloads -xdev -type f -exec du -sk {} \; |sort -rn | head -10

Show drive using high percentage in linux

You can you do a quick search to find which drives are using a higher percentage of used space, can be useful if running a script over ssh keys just change the number on what threshold to show using this command:

df -P | awk ‘0+$5 >= 70 {print}’
Example of changing the limit to 10%

Install a package to check linux directory size

Ncdu is an acronym of NCurses Disk Usage. It is a fast way to see what directories are using the disk space. It is simple and fast disk usage analyzer which is used to find which directories or files are taking up more space.

To install on RHEL, CentOS

yum install ncdu

Once installed, just type ncdu to get going:

ncdu Keyboard Shortcuts

up, down j, k – Cycle through the items
right, enter, l – Open selected directory
left, <, h – Go to parent directory
n – Order by filename (press again for descending order)
s – Order by filesize (press again for descending order)
C – Order by number of items (press again for descending order)
a – Toggle between showing disk usage and showing apparent size.
M – Order by latest child mtime, or modified time. (press again for descending order) Requires the -e flag.
d – Delete the selected file or directory. An error message will be shown when the contents of the directory do not match or do not exist anymore on the filesystem.
g – Toggle between showing percentage, graph, both, or none. Percentage is relative to the size of the current directory, graph is relative to the largest item in the current directory.
c – Toggle display of child item counts.
m – Toggle display of latest child mtime, or modified time. Requires the -e flag.
e – Show/hide ‘hidden’ or ‘excluded’ files and directories. Please note that even though you can’t see the hidden files and directories, they are still there and they are still included in the directory sizes.
i – Show highlighted item info about the usage and size
r – Recalculate the current directory.
b – Spawn bash shell in current directory.
q – Quit ncdu.

NCDU Examples

To scan and browse the directory you’re currently in, all you need is a simple:

ncdu
If you want to scan a full filesystem, your root filesystem, for example, then you’ll want to use -x:

ncdu -x /

Since scanning a large directory may take a while, you can scan a directory and export the results for later viewing:

ncdu -1xo- / | gzip >export.gz

…some time later:

zcat export.gz | ncdu -f-

To export from a cron job, make sure to replace -1 with -0 to suppress any unnecessary output.

You can also export a directory and browse it once scanning is done:

ncdu -o- | tee export.file | ./ncdu -f-


The same is possible with gzip compression, but is a bit kludgey:

ncdu -o- | gzip | tee export.gz | gunzip | ./ncdu -f-

To scan a system remotely, but browse through the files locally:

ssh -C user@system ncdu -o- / | ./ncdu -f-

The -C option to ssh enables compression, which will be very useful over slow links. Remote scanning and local viewing has two major advantages when compared to running ncdu directly on the remote system: You can browse through the scanned directory on the local system without any network latency, and ncdu does not keep the entire directory structure in memory when exporting, so you won’t consume much memory on the remote system.

Summary

As you can see linux directory size can be determined with multiple different ways, if you have any that you use frequently please add into the comments below.

For other Linux / Unix related tutorials on my website please click here.

Also please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any advice for others, requests or questions please leave a comment below.

The post linux directory size appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/linux-directory-size/feed/ 0
Linux ate my RAM Script to Check Usage https://www.myrandomtips.com/linux/linux-ate-my-ram/ https://www.myrandomtips.com/linux/linux-ate-my-ram/#respond Sun, 03 Mar 2019 11:39:25 +0000 https://www.myrandomtips.com/?p=665 Linux ate my ram is a worrying thing to look at the first time you check top or free -m as it appears the linux cached memory high and showing the buff/cache too high. Understanding how linux uses disk caching for the speed of your system, and how everything is ok, and how to check if there is… Read More »

The post Linux ate my RAM Script to Check Usage appeared first on My Random Tips.

]]>

Linux ate my ram is a worrying thing to look at the first time you check top or free -m as it appears the linux cached memory high and showing the buff/cache too high.

Understanding how linux uses disk caching for the speed of your system, and how everything is ok, and how to check if there is an issue will help any newcomers to Linux.

(more…)

The post Linux ate my RAM Script to Check Usage appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/linux-ate-my-ram/feed/ 0
Increase swap space in Redhat 7 | Centos 7 https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/ https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/#respond Fri, 22 Feb 2019 16:44:18 +0000 https://www.myrandomtips.com/?p=578 So you would like to add more swap space in Redhat 7 or Centos 7 after installation. Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 512 MB to 1026 MB, but there is only 512 MB of swap space. It might be… Read More »

The post Increase swap space in Redhat 7 | Centos 7 appeared first on My Random Tips.

]]>
So you would like to add more swap space in Redhat 7 or Centos 7 after installation.

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 512 MB to 1026 MB, but there is only 512 MB of swap space. It might be advantageous to increase the amount of swap space to 1026 MB if you perform memory-intense operations or run applications that require a large amount of memory. It is recommended that you extend an existing logical volume.

How To increase swap space in Redhat 7 | Centos 7

How to Increase Swap Space in Redhat 7 or Centos 7

4 Step on extending the logical volume

  1. Check if enough space to extend the swap file
  2. Turn off the swap file
  3. Extend the swap file and format
  4. Turn back on the swap file and check if swap file has increased

Extend swap on an existing LVM2 logical volume

First make sure nothing is using the swap volume and also ensure you have enough space in your volume group.

Commands to Check enough Space

cat /etc/fstab # check name of swap volume group e.g /dev/mapper/centos-swap swap

lvdisplay /dev/mapper/centos-swap # show volume group info for VG Name

vgdisplay centos # show how much space is free in VG e.g. centos

How to Extend the Swap Volume

1. Disable swapping for the associated logical volume:

swapoff -v /dev/mapper/centos-swap

2. Resize the LVM2 logical volume by 256 MB:

lvm lvresize /dev/mapper/centos-swap -L +256M

3. Format the new swap space:

mkswap /dev/mapper/centos-swap

4. Enable the extended logical volume:

swapon -va

5. Test that the logical volume has been extended properly:

cat /proc/swaps free

Summary

I hope this guide is some help on how to add more swap space in Redhat 7 or Centos 7 after installation, it can be very useful when increasing the physical ram on your Redhat 7 or Centos 7 box.

For other Redhat related tutorials on my website please click here.

To Check our More Tips Please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any requests please leave a comment below.

The post Increase swap space in Redhat 7 | Centos 7 appeared first on My Random Tips.

]]>
https://www.myrandomtips.com/linux/increase-swap-space-redhat-7-centos-7/feed/ 0