Latest LQ Deal: Linux Power User 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 02-22-2008, 04:39 AM   #1
Registered: Sep 2005
Posts: 172

Rep: Reputation: 15
rename a directory

I have a directory test1

this is a empty directory

i want to rename it to test.

whats the command ?
Old 02-22-2008, 04:45 AM   #2
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled

*lame spam filter avoidance text*
Old 02-22-2008, 04:57 AM   #3
Registered: Sep 2005
Posts: 172

Original Poster
Rep: Reputation: 15
did you mean mv test1 test

(i)does it rename the directory ?

(ii)And is not mv works for files ? these are directory.
Old 02-22-2008, 05:31 AM   #4
Registered: Sep 2006
Location: Nagpur, Maharashtra, India
Distribution: Debian, Ubuntu, Redhat, Fedora, SLES, OpenSUSE, FreeBSD, Mac OS X
Posts: 221

Rep: Reputation: 31
did you mean mv test1 test

(i)does it rename the directory ?
Yes, it will rename the directory

(ii)And is not mv works for files ? these are directory.
mv works for both directories and files.
Old 02-22-2008, 06:44 AM   #5
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
There is usually also 'rename' command available, but mv is shorter to type and works on files (directories are one sort of files too on Unix systems - remember that) so why not. It might sound odd that you rename files/directories with 'mv', which usually is used for moving stuff, but if you think about the thing closely, you notice that moving a file (or a directory) into the same directory where it originally was but under a different name means effectively just renaming it.

Not sure about the deep ways of work how rename and mv work when renaming files, but the result stays same.
Old 02-22-2008, 07:03 AM   #6
Registered: Sep 2004
Location: India
Distribution: Kubuntu, Archlinux, Suse, Gentoo, Mandrake
Posts: 370

Rep: Reputation: 30
The general command I have always encountered is: rename pattern1 pattern2 where_to_apply

But I know that there is another version of rename which I never bothered to learn.

"mv" is easy but rudimentary. If you were using rename, you would use something like this:
rename test1 test test1
You could also say
rename 1 "" test1
Once you get it, it is lot more fun


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
Bash - rename directory to overwrite existing LarsWestergren Linux - Newbie 18 04-04-2013 02:07 PM
Bash script to traverse directory tree and rename files intramaweb Programming 3 10-08-2006 12:51 PM
How to recursively rename files using their directory name pattern ceg4048 Linux - General 2 09-28-2005 01:16 PM
rename all files in a directory merlin23 Linux - Newbie 4 03-24-2005 11:02 AM
rename all files in my directory BabaKali Linux - Newbie 2 11-10-2004 04:27 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 PM.

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