Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-12-2008, 09:55 PM   #1
Ye Myint
LQ Newbie
Registered: Sep 2008
Posts: 24

Rep: Reputation: 15
Guide me for copy and rename commands

Please guide me for using cp and rename for existing directories. What i want to do is
(1) i like to rename an existing dir. Which command should i use?
(2) i like to copy a directory including its files and sub directories to another place. Pls show me how to do it.
(3) i have a tar.gz file and guide me how to untar it into a directory with name i want to give.
My linux box is installed from LiveCD of Ubuntu 8.04LTS. Is there any command to delete a directory tree such as windows deltree command.
Old 11-12-2008, 10:28 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
1) Use the "mv" command to rename files or directories.
2) Look at the "man cp" manpage. Use the -R option. If you use the -a option, you will retain the original permissions and ownerships.
3) Look in the "info tar" manual. If this is a tarball, then it has a base directory already and you run: tar -xvzf <tarball-name>
The dash is optional if all of the options are together. The f option precedes the filename. There are numerous options for tar. For example, you can save a timestamp when creating an archive and then later create an incremental backup. Also look at the "info find" manpage. Often find is used to locate files with certain criteria and the list is used by tar.
Old 11-12-2008, 10:29 PM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
In general, it will be good for you to get familiar with the man pages. For your questions, you want to look at:
man cp
man mv
man rename
man tar
man rm
man rmdir

Some general answers:

cp (copy) does not copy contents unless you use the -R flag (recursive)

mv (move) IS recursive by default--ie if you "mv" a directory, the contents go with it.

mv can also be thought of as "rename" (I am not familiar with the actual rename command, and I don't use it.
For example, the rename a file, and keep it in the same directory:
mv oldname newname

The way to learn all this is to simply try it. Try some different commands to see what happens, read the man pages, and try some more.
Old 11-12-2008, 10:31 PM   #4
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Deleting a directory tree is a forced recursive removal, so

rm -rf /directory/to/remove
Old 11-12-2008, 10:49 PM   #5
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Give a man a fish and he will be fed for a day.
Teach a man to fish and he will be fed for a lifetime.

Please read the following link.
Old 11-12-2008, 11:28 PM   #6
Ye Myint
LQ Newbie
Registered: Sep 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Guide for copy and rename commands

Thank you to all for yr kind guidance. I've already reading with man cp man rename but i missed mv command. Anyway i will now try to read what you have suggested and try all things you've pointed out. recently our isp has some DNS problems and it is very slow or have no connections. As OKOS has said, i do agree learning to fish is for life. Now i try to get into the link you mentioned, but connection is too slow to get connected. Anyway i try later.
Old 11-13-2008, 10:22 PM   #7
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Glad to be of help

Here at LQ someone could probably help you with the DNS issue also.


Old 11-14-2008, 08:27 AM   #8
Registered: Sep 2008
Location: Calcutta,India
Distribution: Fedora 11, OpenSUSE 11.0
Posts: 116

Rep: Reputation: 17
read this manual


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mulitple copy a existing directory and rename it at the end sequentially in BASH neo2k Linux - Newbie 2 08-20-2008 11:45 AM
copy and rename the existing directory using BASH script neo2k Linux - Software 3 08-20-2008 11:43 AM
What copy commands does Linux have? IonMarais Linux - Newbie 4 10-26-2006 03:40 AM
where to get the commands guide ? shemjaza Linux - Newbie 3 12-26-2003 11:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration