Wednesday 24 August 2011

Basic Commands - 2.0

Copying files and Directories

[root@localhost ~]# cp <option> <source> <destination>


Example :- To copy a file

[root@localhost ~]# cp completereport /opt

To check if the file has been copied

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport


Example :- To copy a directory

[root@localhost ~]# cp -r directory1/ /opt/

To check if the directory has been copied

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport directory1

Moving files and directories

Syntax :-

[root@localhost ~]# mv <option> <source> <destination>


Example :- To Move a file

[root@localhost ~]# salesreport /opt

To check if the file has been moved


completereport directory1 salesreport


Example :- To move a directory

[root@localhost ~]# mv dir1 /opt


To check if the directory has been moved

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport directory1 dir1 salesreport

Renaming files and directories

Syntax :- 

[root@localhost ~]# mv <old name> <new name>

Example :- To rename a file

[root@localhost ~]# mv completereport fullreport


To check if the file has been Renamed

[root@localhost ~]# ls

anaconda-ks.cfg  file1       install.log         savap-install.log
Desktop          file2       install.log.syslog  sav-install.log
directory1       file3       mktgreport          savjlu-install.log
directory2       file4       POOL.log            savui-install.log
directory3       fullreport  POOL.logpid
directory4       glassfish3  salesreport

Deleting an empty directory

Syntax :- 

 [root@localhost ~]# rmdir <directory name>

Example :- To delete an empty directory

[root@localhost ~]# rmdir directory2

To check if the directory has been deleted
anaconda-ks.cfg  file2        install.log.syslog  sav-install.log
Desktop          file3        mktgreport          savjlu-install.log
directory1       file4        POOL.log            savui-install.log
directory3       fullreport   POOL.logpid
directory4       glassfish3   salesreport
file1            install.log  savap-install.log

Deleting a file or directory

Syntax :-

 [root@localhost ~]# rm <option> <file or directory>

Options :

-r -- recursive
-f -- forcefully

Example :- To delete a file

[root@localhost ~]# rm file4

rm: remove regular empty file `file4'? y


To check if the file has been deleted

[root@localhost ~]# ls

anaconda-ks.cfg  file1       install.log         salesreport
Desktop          file2       install.log.syslog  savap-install.log
directory1       file3       mktgreport          sav-install.log
directory3       fullreport  POOL.log            savjlu-install.log
directory4       glassfish3  POOL.logpid         savui-install.log

To delete a file forcefully

[root@localhost ~]# rm -f mktgreport

To check if the file has been deleted

[root@localhost ~]# ls
anaconda-ks.cfg  file1       install.log         savap-install.log
Desktop          file2       install.log.syslog  sav-install.log
directory1       file3       POOL.log            savjlu-install.log
directory3       fullreport  POOL.logpid         savui-install.log
directory4       glassfish3  salesreport

Example :- To delete a directory

[root@localhost ~]# cd /opt

 [root@localhost ~]# rm -rf dir1


To check if the directory has been deleted

[root@localhost ~]# ls

completereport directory1 salesreport

To view the system date and time

[root@localhost ~]# date

Wed Aug 24 20:34:34 IST 2011

To change the system date and time

Syntax :-

[root@localhost ~]# date -s "MM/DD/YYYY hh:mm:ss"

Example:

[root@localhost ~]#date -s "07/15/2009 00:06:00"

Wed Jul 15 00:06:00 IST 2009

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews