ManyCodes.com – codes & scripts Get free programming codes and tutorials!

23May/110

How to Copy, move, rename, and remove files in Linux

< Copying >

To copy files, you use the cp command. The following will copy file to file2. Note that if file2 doesn't exist, it'll be created, but if it exists, it'll be overwritten:
$ cp file file2

There aren't any undo commands in the Linux CLI, so accidentally overwriting an important file would probably make you pull your head off. The risk of doing so is smaller if you use the -i option ("interactive") with cp. The following does the same as the above, but if file2 exists, you'll be prompted before overwriting:

$ cp -i file file2
cp: overwrite `file2'? n
$

So it's a good idea to use the -i option whenever you're dealing with important files you don't want to lose!

If you want to copy file into directory dir1:
$ cp file dir1

The following would do the same as the above, copy file into dir1, but under a different name:
$ cp file dir1/file2

You can also copy multiple files into one directory with a single command:
$ cp file1 file2 file3 dir1

Note that if the last argument isn't a directory name, you'll get an error message complaining about it.

 

< Moving and renaming >

The mv command can be used for moving or renaming files. To rename a file, you can use it like this:
$ mv file file2

If file2 doesn't exist, it'll be created, but if it exists, it'll be overwritten. If you want to be prompted before overwriting files, you can use the -i option the same way as with cp:

$ mv -i file file2
mv: overwrite `file2'? y
$

To move the file into another directory:
$ mv file dir1

If you want to rename the file to file2 and move it into another directory, you probably already figured out the command:
$ mv file dir1/file2

 

< Removing files >

The rm command is used for removing files and directories. To remove a file:
$ rm file

If you use the -i option, you'll be prompted before removing the file:
$ rm -i file

You can also delete more files at once:
rm file1 file2

Be careful with the rm command! As I already told you, Linux doesn't have any undo commands, and it doesn't put files into Trash where you can save them later. Once you've deleted a file.

Ubuntu, fedora, centos, linux

5Aug/091

Install the Latest PostgreSQL Yum Repository for CentOS

Keeping PostgreSQL updated via yum should be done via the pgdg yum repository supplied by pgsqlrpms.org.

The latest CentOS PostgreSQL repo can be viewed here.

You will need to download the repo and then install using rpm as shown below.

wget http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-centos-8.4-1.noarch.rpm</span></div>
<div style="width: 506px;">rpm<span> -Uhv</span><span> pgdg-centos-8.4-1.noarch.rpm

wget http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-centos-8.4-1.noarch.rpm
rpm -Uhv pgdg-centos-8.4-1.noarch.rpm

Another helpful postgresql install and management link is located here.

5Aug/090

Install istat On a CentOS Linux to Monitor Server from iPhone or Touch

The istat application is a monitoring application that can be used to obtain basic Linux server information from your iPhone or iPod Touch phone. This application has the ability to monitor CPU Usage, Memory Usage, Disk Usage, CPU Load, and Server  Uptime among many others.

istat: Linux Server Monitor From iPhone

To install istat on CentOS Linux follow the directions below.

  1. Download istat: Download istat for Linux here.
  2. Configure istat: Unpack the istat package you downloaded from Google Code and change the directory into the newly created istat directory. Once in this directory type the below command to configure istat for your server.
    1. ./configure
    ./configure
  3. Install istat: Now issue the make and make install commands to compile and install istat on your server.
    1. make
    2. make install
    make
    make install
  4. Create istat User: Now issue the below command to create a istat user to run istat.
    1. useradd istat
    useradd istat
  5. Create istat Directory: Use the below syntax to create a directory to store the istat.pid file which needs to be readable/writeable by the istat user you just created.
    1. mkdir /var/run/istat
    2. chown istat.istat /var/run/istat
    mkdir /var/run/istat
    chown istat.istat /var/run/istat
  6. Configure istat: Now make necessary configuration changes to the /usr/local/etc/istat.conf configuration file. The typical changes include modifying the server_code which is the access code used by your iDevice to obtain the server information, monitor_net which is the interface istat will listen for incoming connections, and monitor_disk which needs to be changed to the proper mounts such as /dev/hdb1, /dev/hdc1, etc.
  7. Launch istat: Now launch the istat daemon by issuing the below command.
    1. /usr/local/bin/istatd &
    /usr/local/bin/istatd &

    The server will automatically launch with the istat user and listen on port 5109.

  8. Connect From iPhone: Now configure the new server within istat on your iPod Touch or iPhone. Once you do so click on the server, type in the password you set in step 6, and verify you are collecting all of the server statistics properly.

The istat application is a nifty little application to provide you a quick view of servers on your network or servers that you monitor outside of your network. More information about the iPhone version of istat can be located here.

21Jul/090

Install easy_install Via yum on Linux CentOS Server

To install easy_install on Linux using yum you will need to install the python-setuptools package. Installing this package with yum is easy by following the directions below.

Run this command in your ssh termianl bash:

yum install python-setuptools 

An example of a python-setuptools install is below.

[root@server ~]# yum install python-setuptools
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* base: pubmirrors.reflected.net
* updates: mirrors.serveraxis.net
* addons: mirror.anl.gov
* ruby: repo.premiumhelp.eu
* extras: mirror.sanctuaryhost.com
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package python-setuptools.noarch 0:0.6c5-2.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
python-setuptools noarch 0.6c5-2.el5 base 479 k

Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 479 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): python-setuptools- 100% |=========================| 479 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: python-setuptools ######################### [1/1]

Installed: python-setuptools.noarch 0:0.6c5-2.el5
Complete!
21Jul/090

How to Install dig on a CentOS Linux Server?

Installing dig on a CentOS Linux server is easy with yum. Dig is actually a bind tool so you will be required to install some bind libraries along with the bind utility package.

 [root@server ~]# yum install bind-utils  

Now you can run something like the below using dig to find MX records.

 [root@server ~]# dig @NAMESERVER EXAMPLE.COM MX  

Your install will look something like the below showing how yum looks for dependencies and installs them automatically.


[root@server ~]# yum install bind-utils
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for bind-utils to pack into transaction set.
bind-utils-9.3.4-6.0.2.P1 100% |=========================| 40 kB 00:00
---> Package bind-utils.x86_64 30:9.3.4-6.0.2.P1.el5_2 set to be updated
--> Running transaction check
--> Processing Dependency: libisccc.so.0()(64bit) for package: bind-utils
--> Processing Dependency: bind-libs = 30:9.3.4-6.0.2.P1.el5_2 for package: bind-utils
--> Processing Dependency: libbind9.so.0()(64bit) for package: bind-utils
--> Processing Dependency: libdns.so.22()(64bit) for package: bind-utils
--> Processing Dependency: libisccfg.so.1()(64bit) for package: bind-utils
--> Processing Dependency: liblwres.so.9()(64bit) for package: bind-utils
--> Processing Dependency: libisc.so.11()(64bit) for package: bind-utils
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for bind-libs to pack into transaction set.
bind-libs-9.3.4-6.0.2.P1. 100% |=========================| 41 kB 00:01
---> Package bind-libs.x86_64 30:9.3.4-6.0.2.P1.el5_2 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
bind-utils x86_64 30:9.3.4-6.0.2.P1.el5_2 updates 171 k
Installing for dependencies:
bind-libs x86_64 30:9.3.4-6.0.2.P1.el5_2 updates 874 k

Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): bind-libs-9.3.4-6. 100% |=========================| 874 kB 00:35
(2/2): bind-utils-9.3.4-6 100% |=========================| 171 kB 00:04
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: bind-libs ######################### [1/2]
Installing: bind-utils ######################### [2/2]

Installed: bind-utils.x86_64 30:9.3.4-6.0.2.P1.el5_2
Dependency Installed: bind-libs.x86_64 30:9.3.4-6.0.2.P1.el5_2
Complete!

21Jul/090

How to Verify a CentOS Linux Server is 32 Bit or 64 Bit?

To verify if a system is 32 bit versus 64 bit you can use the uname command. Below are examples of using the uname command from the CLI on a 32 bit system followed by using the uname command on a 64 bit system.

32 Bit CentOS Linux Server
view plaincopy to clipboardprint?

[root@server ~]# uname -a
Linux server1.example.com 2.6.18-92.1.13.el5 #1 SMP Wed Sep 24 19:33:52 EDT 
2008 i686 i686 i386 GNU/Linux

64 Bit CentOS Linux Server
view plaincopy to clipboardprint?

[root@server ~]# uname -a
Linux server.example.com 2.6.18-53.1.21.el5 #1 SMP Tue May 20 09:35:07 EDT 
2008 x86_64 x86_64 x86_64 GNU/Linux

As you can see above the 64 bit server will show x86_64 numerous times after the install date and time. The 32 bit system will show i686 and i386 after the install date and time. So it is very easy to verify if a system is 32 bit versus 64 bit using the “uname -a” command from a shell.