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)



How to change HOSTNAME in Linux ( CentOS6 / RHEL6 )

Hostname in Linux helps to identify the computer by name over network. When installing operating system hostname will set to default name. We can change the hostname later by changing configuration files.

We can check the current hostname by a command 


[fedo@localhost ~]$ hostname
localhost.localdomain


By editing "HOSTNAME" field in /etc/sysconfig/network file we can change the hostname.

default configuration 

[fedo@localhost ~]$ cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
NTPSERVERARGS=iburst

To edit this file we need root permission. So change from normal user to root user using su command and open the file using vim or your favourite editor and change the HOSTNAME field.

[root@localhost fedo]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos89
NTPSERVERARGS=iburst

I updated the hostname to centos89

reboot the computer then login and check the hostname.

[fedo@centos89 ~]$ hostname
centos89

Now you can see the hostname changed to centos89.

!!!

Operating System Used : CentOS release 6.5 (Final)