LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 02-20-2016, 02:22 PM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Moving to a directory with wildcard


I was really nervous I did something stupid, but think I got lucky (yea, I know it is always a bad idea operating as root, but got lazy.

Did I just move projectx, projectx_2_25_15, and projectx_lib to inside projectx_old?

Why did that happen?

Code:
[root@devserver www]# ls -l
total 716
drwxrwxr-x. 17 Michael Michael   4096 Feb 20 12:05 projectx
drwxrwxr-x. 15 Michael Michael   4096 Feb 24  2015 projectx_2_25_15
drwxrwsr-x.  9 Michael www       4096 May 29  2014 projectx_lib
drwxrwsr-x. 11 root    www       4096 Nov 15  2014 projectx_old
drwxrwxr-x.  3 Michael Michael   4096 Aug 18  2015 cdn
drwxr-xr-x.  2 root    root      4096 Dec 15 07:51 cgi-bin
drwxrwxr-x. 10 Michael Michael   4096 Jan 24 05:46 dashboard
-rw-r--r--.  1 root    root    393037 Feb 20 12:06 diff.txt
drwxr-xr-x.  3 root    root      4096 Dec 28 05:21 error
drwxrwsr-x.  3 phped   www       4096 Jan 22  2015 ezsbt
drwxr-xr-x.  2 root    root      4096 Dec 15 07:51 html
drwxr-xr-x.  3 root    root      4096 Dec 28 05:21 icons
-rwxrwxr-x.  1 phped   phped   281035 Nov 26 07:31 lite_php_browscap.ini
drwxr-xr-x.  3 root    root      4096 Dec  7 05:04 manual
drwxrwxr-x.  3 Michael www       4096 May 23  2015 phpVirtualBox
drwxrwxr-x.  3 Michael Michael   4096 Dec  7 06:16 python
[root@devserver www]# mv diff.txt pro*
[root@devserver www]# ls -l
total 320
drwxrwsr-x. 14 root    www       4096 Feb 20 12:06 projectx_old
drwxrwxr-x.  3 Michael Michael   4096 Aug 18  2015 cdn
drwxr-xr-x.  2 root    root      4096 Dec 15 07:51 cgi-bin
drwxrwxr-x. 10 Michael Michael   4096 Jan 24 05:46 dashboard
drwxr-xr-x.  3 root    root      4096 Dec 28 05:21 error
drwxrwsr-x.  3 phped   www       4096 Jan 22  2015 ezsbt
drwxr-xr-x.  2 root    root      4096 Dec 15 07:51 html
drwxr-xr-x.  3 root    root      4096 Dec 28 05:21 icons
-rwxrwxr-x.  1 phped   phped   281035 Nov 26 07:31 lite_php_browscap.ini
drwxr-xr-x.  3 root    root      4096 Dec  7 05:04 manual
drwxrwxr-x.  3 Michael www       4096 May 23  2015 phpVirtualBox
drwxrwxr-x.  3 Michael Michael   4096 Dec  7 06:16 python
[root@devserver www]# cd pro*
[root@devserver projectx_old]# ls -l
total 1488
drwxrwsr-x.  3 Michael www        4096 Nov 15  2014 application
drwxrwsr-x.  2 phped   www        4096 Jun 12  2014 backup_database
drwxrwsr-x.  8 root    www        4096 May  3  2014 backup_help
drwxrwxr-x. 17 Michael Michael    4096 Feb 20 12:05 projectx
drwxrwxr-x. 15 Michael Michael    4096 Feb 24  2015 projectx_2_25_15
drwxrwsr-x.  9 Michael www        4096 May 29  2014 projectx_lib
drwxrwsr-x.  2 root    www        4096 May 31  2014 cache
-rw-rw-r--.  1 Michael www          54 Sep 20  2014 composer.json
-rw-rw-r--.  1 Michael www        2552 Sep 20  2014 composer.lock
-rwxr-xr-x.  1 Michael www     1018206 Sep 20  2014 composer.phar
-rw-r--r--.  1 root    root     393037 Feb 20 12:06 diff.txt
drwxrwsr-x. 11 root    www        4096 Nov 15  2014 html
-rw-r--r--.  1 root    www       43083 Nov 12  2014 httpd.conf
drwxrwsr-x.  2 root    www        4096 Sep 13  2014 passwords
-rwxrwxr-x.  1 root    www          22 Apr 27  2014 private
drwxrwsr-x.  2 root    www        4096 Nov 14  2014 resources
-rw-r--r--.  1 root    www        2919 Nov  8  2014 rsyslog.php
drwxrwsr-x.  4 Michael www        4096 Sep 20  2014 vendor
-rwxrwxr-x.  1 phped   www          18 Jun  4  2014 XSendFile.txt
[root@devserver projectx_old]#
 
Old 02-20-2016, 05:45 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,138

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
When you give mv more than two args and the last is a directory, it moves all but the last into the directory. Fortunately, you should be able to just mv them back (one-by-one this time!)
 
Old 02-20-2016, 06:00 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by NotionCommotion View Post
Did I just move projectx, projectx_2_25_15, and projectx_lib to inside projectx_old?

Why did that happen?
To elaborate what smallpond said, when you wrote...

Code:
mv diff.txt pro*
The shell expanded it to...

Code:
mv diff.txt projectx projectx_2_25_15 projectx_lib projectx_old
So all the files and directories resulting from the expansion were moved into the last directory, which happened to be projectx_old.
 
Old 02-21-2016, 06:50 PM   #4
lonewolfe
LQ Newbie
 
Registered: Feb 2016
Posts: 2

Rep: Reputation: Disabled
To: NotionCommotion

You have to be very careful with some commands especially when you are root. The shell can be unforgiving at our expense. The mv command has two modes. One, is to move files to another location and second, to rename files. Usually, the wildcard is used on files when moving to another directory.

eg.

mv *.txt projectx_old/

Or in your case, the proper way

mv diff.txt projectx_old/

If you want to move files to multiple directories, you can execute the mv command and change the target directory on each instance, or you can do a for loop with the directories.

Last edited by lonewolfe; 02-21-2016 at 07:46 PM.
 
  


Reply



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
Moving files with wildcard - mv -r doesn't work and cp keeps original copy.. cilbuper Linux - General 6 12-10-2015 04:18 AM
Moving directory preetham.66666 Linux - Server 5 03-16-2015 04:10 PM
[SOLVED] Invoke root directory owner/group while moving file/directory yogesh_attarde Linux - Security 5 04-14-2014 11:36 PM
Moving my directory okayload Linux - Distributions 1 08-11-2007 07:16 AM
Moving A Directory. reesee Linux - Newbie 6 02-04-2004 02:16 AM

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

All times are GMT -5. The time now is 12:09 AM.

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
Open Source Consulting | Domain Registration