Wednesday, 5 March 2014

How to Release Cache Memory In Linux


To check uses of Cache Memory

free -m

rahul@rahul-laptop:~# free -m
             total       used       free     shared    buffers     cached
Mem:           992        898         94          0         14        460
-/+ buffers/cache:        604        388
Swap:         1011        132        879

To Release/ Free  Cache Memory 

rahul@rahul-laptop:~# sync, echo 3 > /proc/sys/vm/drop_caches 

Above command will free used cache memory
 to verify run again free -m

     OR 

rahul@rahul-laptop:~# sync && echo 1 > /proc/sys/vm/drop_caches

Wednesday, 5 February 2014

The Runlevels in Linux



Definition for runlevel : A runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init command/process for each of these runlevels are defined in the /etc/inittab file.
Runlevels control services started by the initialization process. The number of runlevels and services started on those runlevels varies with Linux distributions.
Print print current runlevel using who command:
$ who -r  
Or
$ runlevel

Different linux/unix disterbution’s runlevels


Redhat Linux:

Red Hat as well as most of its derivatives uses runlevels like this.  

# 0 – Halt (Do not set initdefault to this option.)
# 1 – Single User Mode
# 2 – Multi-user, without NFS (The same as 3, if you do not have networking)
# 3 – Full Multi-user Mode
# 4 – Unused
# 5 – X11
# 6 – Reboot (Do not set initdefault to this option.)
  

Debian Linux :
Debian, as well as most of the distributions based on it, like Ubuntu, does not make any distinction between runlevels 2 to 5. See also the Debian FAQ on booting.
0 – Halt
1 – Single
2 – Full multi-user with display manager (GUI)
3 – Full multi-user with display manager (GUI)
4 – Full multi-user with display manager (GUI)
5 – Full multi-user with display manager (GUI)
6 – Reboot


SUSE Linux:
SUSE uses a similar setup as Red Hat :
0 – Halt
1 – Single
2 – Full multi-user with no networking
3 – Full multi-user NO display manager
4 – Not used/User definable
5 – Full multi-user with display manager (GUI)
6 – Reboot


Solaris
0 – operating system halted; (SPARC only) drop to OpenBoot prompt
S – single-user with only root filesystem mounted (as read-only)
1 – single-user mode with all local filesystems mounted (read-write)
2 – multi-user with most daemons started.
3 – multi-user, identical to 2 (runlevel 3 runs both /sbin/rc2 and /sbin/rc3), with filesystems exported, plus some other network services started.
4 – alternative multi-user, user defined
5 – shut down, power-off if hardware supports it
6 – reboot

Wednesday, 8 January 2014

How to find - Size of a directory & Free disk space

Check Size of a directory & Free disk space


          
This article explains 2 simple commands that most people want to know when they start using Linux. They are finding the size of a directory and finding the amount of free disk space that exists on your machine. The command you would use to find the directory size is ' du '. And to find the free disk space you could use ' df '.

All the information present in this article is available in the man pages for du and df. In case you get bored reading the man pages and you want to get your work done quickly, then this article is for you.


'du' - Finding the size of a directory

$ du
Typing the above at the prompt gives you a list of directories that exist in the current directory along with their sizes. The last line of the output gives you the total size of the current directory including its subdirectories. The size given includes the sizes of the files and the directories that exist in the current directory as well as all of its subdirectories. Note that by default the sizes given are in kilobytes.

$ du /home/rahul
The above command would give you the directory size of the directory /home/david


$ du -h
This command gives you a better output than the default one. The option '-h' stands for human readable format. So the sizes of the files / directories are this time suffixed with a 'k' if its kilobytes and 'M' if its Megabytes and 'G' if its Gigabytes.


$ du -ah

This command would display in its output, not only the directories but also all the files that are present in the current directory. Note that 'du' always counts all files and directories while giving the final size in the last line. But the '-a' displays the filenames along with the directory names in the output. '-h' is once again human readable format.

$ du -c
This gives you a grand total as the last line of the output. So if your directory occupies 30MB the last 2 lines of the output would be

300M .
300M total

The first line would be the default last line of the 'du' output indicating the total size of the directory and another line displaying the same size, followed by the string 'total'. This is helpful in case you this command along with the grep command to only display the final total size of a directory as shown below.

$ du -s
This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.

$ du -S
This would display the size of the current directory excluding the size of the subdirectories that exist within that directory. So it basically shows you the total size of all the files that exist in the current directory.
df' - finding the disk free space / disk usage

$ df
Typing the above, outputs a table consisting of 6 columns. All the columns are very easy to understand. Remember that the 'Size', 'Used' and 'Avail' columns use kilobytes as the unit. The 'Use%' column shows the usage as a percentage which is also very useful.


$ df -h
Displays the same output as the previous command but the '-h' indicates human readable format. Hence instead of kilobytes as the unit the output would have 'M' for Megabytes and 'G' for Gigabytes.