LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-02-2012, 01:11 AM   #1
bigger_travis
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Rep: Reputation: Disabled
Directory changed to file name


hello, i am new to linux and i dont know what i did.

i had a very important directory called public_html for my website i was moving a file to my /home/user21/public_html/ directory with this command:


mv mybackup.sql /home/user*/pub*/mybackup.sql

so when i cd to the /home/user21/public_html/ it said "no such directory"

so when i do a list it shows the public_html as a file?

Code:
-rw-r--r--   1 root              root                44966003 2012-01-01 17:26 public_html
Notice on the permission, it has -rw-r--r-- where as my other directories have drwxrwxrwx

can anyone help me please. how can i change it back to a directory?

thank you
 
Old 01-02-2012, 02:47 AM   #2
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
You basically just renamed your mybackup.sql to public_html. You probably shouldn't be using wildcards in your mv command.

Just rename back your file with mv.
 
Old 01-02-2012, 04:07 AM   #3
bigger_travis
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
oh i see. ok.
so if i rename public_html to mybackup.sql

Code:
mv public_html mybackup.sql
ill be able to get my mybackup.sql file,

im scared to even ask this.. what happened to the original public_html, directory is it gone? anyway i can get it back?
 
Old 01-02-2012, 08:29 AM   #4
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
Yes. Your mv command will restore mybackup.sql

As for your folder.. I've never used wildcards in a command like this, I'm not sure what it will do.

I'm inclined to believe that the public_html folder did not exist in that location in the 1st place, otherwise it would not have renamed the file like it did.

Last edited by ongte; 01-02-2012 at 08:30 AM.
 
Old 01-02-2012, 08:30 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by bigger_travis View Post
mv mybackup.sql /home/user*/pub*/mybackup.sql
Do not use wildcards to reduce typing for a single filename. It might accidentally match more than one filename that you didn't think of. Use tab completion instead (enter the first few chars of a filename and press Tab. bash will complete it if there is only one file starting with those characters).
 
Old 01-02-2012, 06:24 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
The shell expands wildcards (globs) into the complete list of matching files before it executes the command. So the actual command that the shell ran was something like this:

Code:
mv mybackup.sql /home/user1/pub1/mybackup.sql /home/user1/pub2/mybackup.sql /home/user2/pub1/mybackup.sql ... ... /home/user100/pub100/mybackup.sql
With the whole list depending on how many files and directories are matched with * (Tack echo to the front of the command to see what it looks like expanded).

Depending on how the final command is formatted, you can end up overwriting files of the same name, or moving whole directory trees to other places.

A safer way to use mv in cases like this is to explicitly name the target directory with the -t option.

Code:
mv -t targetdir mybackup.sql
Also consider using the -v (verbal) option, and either the -i (interactive), or -n (no-clobber) options in mv and cp. Set them up as aliases or shell functions so they're always active by default.
 
Old 01-03-2012, 03:10 PM   #7
bigger_travis
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
yes, i agree. i took a gamble using the wild card. i will remember that next time not to be tempted to use it. for the last couple of day i have been on that shell sending command after command trying to see what i did wrong. i prayed that i can get this data back. it was 5.3G worth of files.. i review my history. used the find command and the fgrep command to see where i can find it. FINALLY. i found something strange. i looked for all the public_html files in the whole file system and i found one that caught my eye. i dont know what i did, but i guess i moved the public_html directory to another public_html directory because thats where i found it. it was amazing when i saw all those files back. I kneel down and thanked that Lord Jesus for getting back this data. Thank you "ongte", "MTK358" and "David the H." for your advise. i will use the wild card more carefully next time.

Last edited by bigger_travis; 01-03-2012 at 03:11 PM.
 
  


Reply


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
RSYNC Help - Copy Only Changed Files to New Directory euphoricrhino Linux - Software 1 11-23-2011 04:29 PM
my user's home directory permissions have been changed darin722 Linux - Security 5 11-03-2007 07:24 PM
mtime/ctime changed on directory entries stardot Linux - Security 2 11-29-2004 11:44 PM
we changed permissions on the etc directory and now we can not log in vinces39 Red Hat 1 06-18-2004 11:20 AM
Directory changed to a file cparton Linux - Newbie 0 09-25-2003 01:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:11 PM.

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