Page 1 of 1

[SOLVED] Rename Folder

PostPosted: Jun 1st, '13, 18:27
by laskachien
Hello in bash
I d tried -v rename folder1 folder2 answer -v not found try cnf -v...(often some options give me the same answer!)
can I also try -v mv folder1 folder2? and folder1 is removed?
Must I be out of folder1?Thanks

Re: Rename Folder

PostPosted: Jun 1st, '13, 19:35
by doktor5000
Any reason why you want to do this in a terminal, whereas you complained about linux being only for experts? Why not use a graphical file manager like dolphin or nautilus?

Apart from that, rename only works on files, not on folders. Don't know why you put -v in front, that will not work. And mv works to rename folders, if you use it correctly.
But you need to provide more information, e.g. in which folder you were, and the command you used and the output you got.

Small example how to provide this information:

I'm in my /home folder:

Code: Select all
[doktor5000@Mageia3 ~]$ pwd
/home/doktor5000


I want to rename a folder "testfolder" to "newfoldername", this is what it looks before:
Code: Select all
[doktor5000@Mageia3 ~]$ ls -ald testfolder
drwxrwxr-x 2 doktor5000 doktor5000 4096 Jun  1 19:32 testfolder/

Renaming it:
Code: Select all
[doktor5000@Mageia3 ~]$ mv testfolder/ newfoldername

This is what it looks afterwards:
Code: Select all
[doktor5000@Mageia3 ~]$ ls -ald newfoldername/
drwxrwxr-x 2 doktor5000 doktor5000 4096 Jun  1 19:32 newfoldername/

Re: Rename Folder

PostPosted: Jun 2nd, '13, 10:51
by laskachien
Thanks
I want to use bash to learn it,as I learned 20years ago C and 40 Dos and Basic.But as I m 84old I make more mistakes now!
No notice had tell me that rename work only on files 1st error.I wanted to change ToTo in titi I was in ToTo folder 2d error. -v for verbose.

Re: [SOLVED] Rename Folder

PostPosted: Jun 2nd, '13, 11:08
by doktor5000
You always need to put options like -v behind the command, not in front, otherwise shell thinks this is a separate command.

Re: [SOLVED] Rename Folder

PostPosted: Jun 2nd, '13, 14:19
by laskachien
http://ss64.com is an index of bash cdes it s interesting!
Thanks now I has learned more.

Re: Rename Folder

PostPosted: Jun 3rd, '13, 11:27
by laskachien
Sorry I ts me again I tried your in /home [carl...]$ mv oldf / newf
answer newf not found So I try
$ mkdir newf ok then
$ mv oldf / newf
The result is that newf contains oldf who contains 3files
I want to have newf containing the 3 files,and oldf removed!
Another Q about really I must change a long dir name in french "Téléchargements" for dwnld.Do this change be reconized by the download manager?

Re: Rename Folder

PostPosted: Jun 3rd, '13, 14:04
by Mayavimmer
laskachien wrote:Sorry I ts me again I tried your in /home [carl...]$ mv oldf / newf
answer newf not found So I try
$ mkdir newf ok then
$ mv oldf / newf
The result is that newf contains oldf who contains 3files
I want to have newf containing the 3 files,and oldf removed!

Beware of different behaviors depending on whether the second folder exists or not!
First let's create and work in a new empty folder (directory):
user ~ $ mkdir zzz
user ~ $ cd zzz

Now let's create a small directory containing two files:
user zzz $ mkdir dir1
user zzz $ touch dir1/file1
user zzz $ touch dir1/file2

Let's see what we have:
user zzz $ find *
dir1
dir1/file2
dir1/file1

Now rename dir1 to dir2, where there is NO PREEXISTING dir2:
user zzz $ mv dir1 dir2
user zzz $ find *
dir2
dir2/file2
dir2/file1

Try again, but with a preexisting dir3:
user zzz $ mkdir dir3
user zzz $ mv dir2 dir3
user zzz $ find *
dir3
dir3/dir2
dir3/dir2/file2
dir3/dir2/file1

DIFFERENT BEHAVIOR! Now dir2 is INSIDE dir3!

Finally clean up temporary files:
user zzz $ cd ..
user ~ $ rm -rf zzz

Re: Rename Folder

PostPosted: Jun 3rd, '13, 15:47
by laskachien
Oh what an interesting answer,who explain the subtle of the mv cde!!!No book give such detailed explanations.Thanks for.But why bash do not have a simple "renamedir"for this simple task!

Re: Rename Folder

PostPosted: Jun 3rd, '13, 19:20
by doktor5000
laskachien wrote:Sorry I ts me again I tried your in /home [carl...]$ mv oldf / newf
answer newf not found


Did you copy&paste that command? As there's a blank between oldf and the following /

Re: Rename Folder

PostPosted: Jun 3rd, '13, 19:24
by laskachien
I try your thread OK it s well,and now I think I understant why before it do not work
doktor5000@Mageia3 ~]$ mv testfolder/ newfoldername
in this line there is a / and I think because it I get the answer newf....not found.And therefor I made an error with mkdir
mv testfolder newf... must go

Re: Rename Folder

PostPosted: Jun 3rd, '13, 19:44
by doktor5000
BTW: You may want to have a look at http://steve-parker.org/sh/sh.shtml or, recommended elsewhere already: http://nixsrv.com/llthw

Re: Rename Folder

PostPosted: Jun 4th, '13, 10:41
by laskachien
Yes very interesting just what I need to learn more Thanks

Re: SOLVED Rename Folder

PostPosted: Jun 5th, '13, 16:29
by srtxg
the "mv" comand moves files (or directories).
If you have only two arguments, eg "mv A B", then "A" will be moved to "B":
1. if B doesn't exists then A will be renamed to B
2. if B exists and is a directory then A will be moved *into* B
3. if B is a file and A is file too, then A will *overwrite* B (that is, old B will be deleted, and A renamed to B)
4. if A is a dir and B a file then error

now, if there are three or more parameters, then the last one *MUST* exist and be a directory
the command is them: move everything into that last directory.

You typed: "mv oldf / newf"
There are three parameter there: "oldf", "/" and "newf". So newf *must* be a directory and exist.
Note that "/" is the root directory, that is your WHOLE system; trying to move it won't work; maybe it can lead to a partial move and your system being unworking because of very important thing like ld.so or bash or /dev not being at the expected place anymore.
Not what you wanted to do anyway. I think you wanted to type: "mv oldf newf"

Re: SOLVED Rename Folder

PostPosted: Jun 5th, '13, 21:37
by laskachien
I did not suspect ,that for a simple act to ren a dir it s so subtle.But now I m an expert with mv!!!I try http://nixsrv.com/llthw given by Dr5000,it is very interesting,but you must have a good logic as the exercises has been edited for DEBIAN,so some differences appears.In digging and digging more and more,I face now more questions than solutions!!!