Hi!
Please log-in using your User Name / ID as you would usually and then change your log-in to that of root:
Code:
[demo@localhost bin]$ su - root
Password:
[root@localhost ~]#
Please, note that hyphen "-" in between "su" and "root" separated by a space.
A simple note on the hyphen: Using a hyphen (-) before the user name when you use "su" command to take on the privileges of some other user, you effectively use a "Log-in Shell". Without the hyphen, the Log-in environment would be called "No Log-in Shell".
cd to any directory such /tmp:
and then run this command:
Code:
[root@localhost tmp]# du -ah . | sort -nr | grep -v ^0 | head
924K ./localhost-2012011502501326576035/proc/sys/net/ipv6
768K ./localhost-2012011502501326576035/sos_commands/process
724K ./localhost-2012011502501326576035/etc/sysconfig
684K ./localhost-2012011502501326576035/sos_commands/process/lsof_-b_M_-n_-l
584K ./localhost-2012011502501326576035/proc/sys/net/ipv6/conf
584K ./localhost-2012011502501326576035/etc/rc.d
524K ./localhost-2012011502501326576035/etc/rc.d/init.d
484K ./localhost-2012011502501326576035/proc/sys/net/ipv4/conf
388K ./localhost-2012011502501326576035/proc/sys/kernel
332K ./localhost-2012011502501326576035/var/log/messages-20111212
[root@localhost tmp]#
"du -ah ." = This part tells you the counts of each file and directory (-a). You get to know their sizes in KB/MB/GB (-h) as shown above. But I would not recommend "-h" as "sort" would not give us a realistic sorted list. For example, lines containing "M" in the first column may appear after "K". So, it is better to leave out "-h" and use only "du -a".
Examples:
Code:
[root@localhost ~]# du -ah /var/log | sort -nr | grep -v ^0 | tail -n 5
4.0K /var/log/boot.log-20111212
4.0K /var/log/boot.log-20111204
4.0K /var/log/boot.log
3.9M /var/log/audit/audit.log
3.9M /var/log/audit
[root@localhost ~]#
So, using only "du -a" is what we want:
Code:
[root@localhost ~]# du -a /var/log | sort -nr | grep -v ^0 | tail -n 5
4 /var/log/boot.log-20120115
4 /var/log/boot.log-20120113
4 /var/log/boot.log-20111212
4 /var/log/boot.log-20111204
4 /var/log/boot.log
[root@localhost ~]# du -a /var/log | sort -nr | grep -v ^0 | head -n 5
7984 /var/log
3984 /var/log/audit
3980 /var/log/audit/audit.log
620 /var/log/wtmp
376 /var/log/gdm
"sort -nr" = We give the output of "du" to "sort" by piping "|". "sort -nr" sort the fist column that is the size field and gives a Descending List of the Size. So, the big sized files/directories appear at the top and the lowest ones at the bottom.
"grep -v ^0" = We are removing those entries that have "zero" sized files.
"head" = Top 10 lines are displayed.
You can replace "head" with "more" to navigate the entire output.
Or you can write the output to a file with the help of redirection operator ">" and then giving it a file name:
Code:
[root@localhost tmp]# du -a . | sort -nr | grep -v ^0 > files_list
[root@localhost tmp]# ls -l files_list
-rw-r--r--. 1 root root 137849 Jan 16 01:16 files_list
[root@localhost tmp]# less files_list
[root@localhost tmp]#
You can use "less", "more", or "vi", or "vim" or any other editor to view the file's contents.
You can then decide which files/directories you may want to delete.
"du -a ." = . (dot) means the current directory. You can replace the dot with any other directory's path:
Code:
[root@localhost tmp]# du -a /var/log | sort -nr | grep -v ^0 | head
You can alternately and more effectively use "find" command to list large files and delete them at the same time if you wish to:
Code:
[root@localhost tmp]# find /boot/ -type f -size +1M | xargs ls -lh
-rw-r--r--. 1 root root 13M Aug 12 16:12 /boot/initramfs-2.6.32-71.el6.i686.img
-rw-r--r--. 1 root root 1.7M Nov 12 2010 /boot/System.map-2.6.32-71.el6.i686
-rwxr-xr-x. 1 root root 3.5M Nov 12 2010 /boot/vmlinuz-2.6.32-71.el6.i686
[root@localhost tmp]#
You can replace "+1M" to any other value such as "+10M" or "+1G" meaning size greater than 10 MB or 1 GB respectively.
"xargs ls -lh" = We are long-listing each line processed by the find command. We can replace this command with "rm" to remove the file instead. Or "rm -rf" to remove forcefully and "r" for recursively if it is a directory. But we have already specified "-type f" to mean that only file names will appear. So, "rm -f" would be enough.
Example:
Code:
[root@localhost tmp]# find /boot/ -type f -size +1M | xargs echo "rm"
rm /boot/System.map-2.6.32-71.el6.i686 /boot/initramfs-2.6.32-71.el6.i686.img /boot/vmlinuz-2.6.32-71.el6.i686
[root@localhost tmp]#
You got it now? Remove "echo" and quotes of "rm" and simply make it look like as follows:
Code:
find /boot/ -type f -size +1M | xargs rm -f
or
find /boot/ -type f -size +1M | xargs rm
Please, be warned that "rm" or "rm -f" or "rm -r" is a destructive command and we cannot retrieve deleted files (unless some expert technique is used).
That is why I have used "echo" to see what is going to happen. It is good to save the output in a file:
Code:
[root@localhost tmp]# find /boot/ -type f -size +1M | xargs echo "rm" > output
[root@localhost tmp]# cat output
rm /boot/System.map-2.6.32-71.el6.i686 /boot/initramfs-2.6.32-71.el6.i686.img /boot/vmlinuz-2.6.32-71.el6.i686
[root@localhost tmp]#
You can directly delete them if you are sure that you would not need those files:
The "output" file contains "rm" command and hence it acts as a script and you can run it easily.
See it in action:
Code:
[root@localhost tmp]# find /tmp/ -type f -size +1M | xargs echo "rm"
rm /tmp/localhost-2012011502501326576035/var/log/audit/audit.log
[root@localhost tmp]# find /tmp/ -type f -size +1M | xargs echo "rm" > output
[root@localhost tmp]# cat output
rm /tmp/localhost-2012011502501326576035/var/log/audit/audit.log
[root@localhost tmp]# ls -lh /tmp/localhost-2012011502501326576035/var/log/audit/audit.log
-rw-r--r--. 1 root root 3.8M Jan 15 02:51 /tmp/localhost-2012011502501326576035/var/log/audit/audit.log
[root@localhost tmp]# /bin/bash output
[root@localhost tmp]# ls -lh /tmp/localhost-2012011502501326576035/var/log/audit/audit.log
ls: cannot access /tmp/localhost-2012011502501326576035/var/log/audit/audit.log: No such file or directory
[root@localhost tmp]#
So, I have deleted the above file that I would not need any longer.
One more example for you:
Code:
[root@localhost tmp]# find /tmp/ -type f -size +1k | xargs echo "rm" > output
[root@localhost tmp]# ls -lh output
-rw-r--r--. 1 root root 18K Jan 16 01:39 output
[root@localhost tmp]#
Oh! The output file itself is of 18K now that contains only the file names whose size is greater than 1KB!
How can we delete them all in one go?
Yes, executing the "output" file that contains the command "rm":
Code:
[root@localhost tmp]# /bin/bash output
[root@localhost tmp]# find /tmp/ -type f -size +1k | xargs echo "rm" > output
[root@localhost tmp]# cat output
rm
[root@localhost tmp]#
The file contains only the command name and no file names now because there is no file whose size would be greater than 1KB.
Notice "k" is small in the find command. "M" and "G" will be in capital letters.
Please Note: Do not use "/" after "find" because it will search the entire file system / Hard Disk that is visible to Linux/Unix on your system. Just try these areas/partitions/directories:
Code:
find /tmp -type f -size +1k | xargs ls -lh
find /var/log -type f -size +1k | xargs ls -lh
find /home -type f -size +1k | xargs ls -lh
As I said earlier, instead of "ls -lh" you can use '| xargs echo "rm" > files.txt'
Since, you are 61. I thought it would be nice to explain every piece of the commands I have given here. Please, excuse me if you were already familiar with them.
Do let me/us know if you need more help. You would not need to check "/boot" partition if never installed any other kernel. That is, you have had only one Linux Kernel that was there at the time of a fresh installation of your Linux Distro.
Just list the output of this command here so that we can tell you if you need to delete any file in "/boot" directory:
Command:
Output on my System:
Code:
total 18M
-rw-r--r--. 1 root root 1.7M Nov 12 2010 System.map-2.6.32-71.el6.i686
-rw-r--r--. 1 root root 101K Nov 12 2010 config-2.6.32-71.el6.i686
-rwxr-xr-x. 1 root root 3.5M Nov 12 2010 vmlinuz-2.6.32-71.el6.i686
-rw-r--r--. 1 root root 155K Nov 12 2010 symvers-2.6.32-71.el6.i686.gz
drwx------. 2 root root 16K Aug 12 15:25 lost+found
drwxr-xr-x. 3 root root 4.0K Aug 12 15:49 efi
-rw-r--r--. 1 root root 13M Aug 12 16:12 initramfs-2.6.32-71.el6.i686.img
drwxr-xr-x. 2 root root 4.0K Aug 12 16:13 grub
I am using CentOS 6.0 and I do not have any huge files in "/boot" that I would consider deleting them.
So, do post what your "/boot" directory holds so that we can help you better. Remember, any messing up with /boot may result in a unusable system. You may not even be able to log-in to or even boot your system.
Cheers!