Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Linux Command To Rename The Multiple Files

[sujin@localhost blog]$ ls -l
total 0
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos6file1
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos6file2
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos6file3
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos6file4
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos6file5
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos6file6
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos6file7
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos6file8


From the above  list of files i want change all the filename  starting with centos6 to centos7. I mean file centos6file2 changed to centos7file2. 

It is bit time consuming using mv command to change it one by one. Persong who using mv command for do this not a good linux user. 

By using a linux command called rename we can achieve this.


         rename centos6 centos7 centos6*


After applying above command file name list would be like below.

[sujin@localhost blog]$ rename centos6 centos7 centos6*
[sujin@localhost blog]$ 
[sujin@localhost blog]$ ls -l
total 0
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos7file1
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos7file2
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos7file3
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos7file4
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:12 centos7file5
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos7file6
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos7file7
-rw-rw-r--. 1 sujin sujin 0 Oct 19 13:14 centos7file8


!!!

Operating System Used : Fedora release 20 (Heisenbug)



Linux command to get page size


By using getconf command we can get the size of Virtual Memory page in bytes.


[root@host-7-41 fedo]# getconf  PAGESIZE
4096


Here PAGESIZE is the argument passed to the getconf to get virtual memory page size. It gives the output as 4096 bytes.

!!!

Operating System Used : CentOS release 6.5 (Final)


Linux Command to Check OS Architecture is 32 or 64 bit

Recent days all the major Linux operating system support two type of  architecture. Those are 32 bit architecture and 64 bit architecture. There is no explicit option available to know which type of architecture you are working. Operating System GUI has option to see this facility even in LINUX knowing everything from Command line has the advantage. Below commands help you to find the Linux operating system architecture. Here i used CentOS release 6.3  to make this article.

1. uname -a  -- This command will display the kernel architecture whether it 32 bit or 64 bit. Output of this command vary depends on the hardware architecture.
    For Intel 32 bit - i686 or x86
    For Intel 64 bit - x86-64

[fedo@localhost ~]$ uname -m 
x86_64


2. getconf LONG_BIT -- We can use this command also to get the architecture

[fedo@localhost ~]$ getconf LONG_BIT 
64


3. arch -- This command also help to find the architecture

[fedo@localhost workspace]$ arch 
x86_64


4. lscpu -- you can get the all the details about OS and CPU support using this command

[fedo@localhost ~]$ lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
CPU socket(s):         1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 58
Stepping:              9
CPU MHz:               3192.839
BogoMIPS:              6385.67
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0


5. If you want to get OS architecture through C/C++ program you can use below code

Program:

#include <stdio.h>
int main()
{
    printf("%d bit \n", __WORDSIZE);
    return 0;
}

Output:

64 bit

Check disk space in linux using df command


Linux Version & distribution used for this article
[root@localhost workspace]# uname -sr
Linux 2.6.32-279.el6.x86_64

[root@localhost workspace]# cat /etc/redhat-release
CentOS release 6.3 (Final)



1. df  -- It display available file system details like device name, total size, used space and available space

[root@localhost workspace]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                      18133780   3579124  14370472  20% /
tmpfs                   247288       420    246868   1% /dev/shm
/dev/sda1               495844     33920    436324   8% /boot


2. a  -- include dummy filesystem

[root@localhost workspace]# df -a
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                      18133780   3591168  14358428  21% /
proc                         0         0         0   -  /proc
sysfs                        0         0         0   -  /sys
devpts                       0         0         0   -  /dev/pts
tmpfs                   247288       420    246868   1% /dev/shm
/dev/sda1               495844     33920    436324   8% /boot
none                         0         0         0   -  /proc/sys/fs/binfmt_misc
vmware-vmblock               0         0         0   -  /var/run/vmblock-fuse
sunrpc                       0         0         0   -  /var/lib/nfs/rpc_pipefs


3. h  -- human readable format. It will display size format as GB, MB, KB

[root@localhost workspace]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                       18G  3.5G   14G  21% /
tmpfs                 242M  420K  242M   1% /dev/shm
/dev/sda1             485M   34M  427M   8% /boot


4. df -h /  -- Display only certain mount point

[root@localhost workspace]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                       18G  3.7G   14G  22% /

[root@localhost workspace]# df -h /boot
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             485M   34M  427M   8% /boot


5. df -B 512  -- we can change the size of block its displaying. Below example each block has 512 bytes

[root@localhost workspace]# df -B 512
Filesystem         512B-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                      36267560   7636832  28262360  22% /
tmpfs                   494576       864    493712   1% /dev/shm
/dev/sda1               991688     67840    872648   8% /boot


6. df --block-size=512k  -- display block in KB format. here it will show each block is 512kb

[root@localhost workspace]# df --block-size=512k
Filesystem         512K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                         35418      7458     27600  22% /
tmpfs                      483         1       483   1% /dev/shm
/dev/sda1                  969        67       853   8% /boot


7. m  -- display block size in MB

[root@localhost workspace]# df -m
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                         17709      3729     13800  22% /
tmpfs                      242         1       242   1% /dev/shm
/dev/sda1                  485        34       427   8% /boot


8. --total -- display the grand total

[root@localhost workspace]# df --total
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
                      18133780   3818416  14131180  22% /
tmpfs                   247288       432    246856   1% /dev/shm
/dev/sda1               495844     33920    436324   8% /boot
total                 18876912   3852768  14814360  21%


9. i  --  list inode information instead of block usage

[root@localhost workspace]# df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/mapper/vg_fedo-lv_root
                     1155072  138135 1016937   12% /
tmpfs                  61822       7   61815    1% /dev/shm
/dev/sda1             128016      40  127976    1% /boot


10. T  -- It will display additionaly filesystem type like ext3, ext4.

[root@localhost workspace]# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
              ext4    18133780   3818420  14131176  22% /
tmpfs        tmpfs      247288       432    246856   1% /dev/shm
/dev/sda1     ext4      495844     33920    436324   8% /boot


11. t  --  helps to display specific type of file system

[root@localhost workspace]# df -Tt ext4
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_fedo-lv_root
              ext4    18133780   3818412  14131184  22% /
/dev/sda1     ext4      495844     33920    436324   8% /boot


12. x  -- exclude specific type of file system

[root@localhost workspace]# df -Tx ext4
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
tmpfs        tmpfs      247288       432    246856   1% /dev/shm


13. df --help  -- to get df command help information


ENJOY & HAVE FUN WITH LINUX!!!!