mv command to include files beginning with "." (like .htaccess)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mv command to include files beginning with "." (like .htaccess)
# 1  
Old 05-24-2011
mv command to include files beginning with "." (like .htaccess)

Hi, how can I get the mv command to include files beginning with . (such as .htaccess)?

Right now when I mv a directory the .htaccess file is missing and I need to do this on a lot of directories, so there's a lot of wordpress permalinks that don't work anymore because the .htaccess file wasn't moved over.



like mv /home/directory1 /home/directory2

mv /home/directory1/* /home/directory2

and if
/home/directory1 contains the file .htaccess
it's not getting moved over to directory2

Thanks!

Last edited by vanessafan99; 05-24-2011 at 12:42 PM..
# 2  
Old 05-24-2011
mv doesn't ignore any files.

Code:
~ $ mkdir a
~ $ touch a/.htaccess
~ $ mkdir b
~ $ mv a b
~ $ ls -l b/a/.htaccess 
-rw-r--r-- 1 monttyle monttyle 0 May 24 09:50 b/a/.htaccess
~ $

* however, which is part of the shell and not part of mv, does ignore hidden files.

Easy enough to fix. Just add .htaccess to the list of stuff you want.

mv /path/to/* /path/to/.[a-z]* destination The [a-z] prevents it from matching ".", the current directory, or "..", the previous directory...

Last edited by Corona688; 05-24-2011 at 12:53 PM..
# 3  
Old 05-24-2011
Quote:
Originally Posted by Corona688
mv doesn't ignore any files.

Code:
~ $ mkdir a
~ $ touch a/.htaccess
~ $ mkdir b
~ $ mv a b
~ $ ls -l b/a/.htaccess 
-rw-r--r-- 1 monttyle monttyle 0 May 24 09:50 b/a/.htaccess
~ $

* however, which is part of the shell and not part of mv, does ignore hidden files.

Easy enough to fix. Just add .htaccess to the list of stuff you want.

mv /path/to/* /path/to/.[a-z]* destination The [a-z] prevents it from matching ".", the current directory, or "..", the previous directory...
I think that works, thanks!
# 4  
Old 05-24-2011
Similar answer (add files starting with period to the list):
Code:
mv /home/directory1/* /home/directory1/.??* /home/directory2

# 5  
Old 05-24-2011
Quote:
Originally Posted by methyl
Similar answer (add files starting with period to the list):
Code:
mv /home/directory1/* /home/directory1/.??* /home/directory2

what's the ??
is that part of the command or do i fill it with something like "ht"?
# 6  
Old 05-24-2011
The ?? is part of the command. It is a wildcard. The pattern ".??*" just finds filenames which start with a period and are at least three characters long.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Add the word "prefix" to beginning of line using sed

SUSE linux bash shell this works test -d /tmpp && echo "directory exists" || echo "directory doesn't exists" |sed -e "s/^/prefix /" prefix directory doesn't exists but why doesn't this work? test -d /tmp && echo "directory exists" || echo "directory doesn't exists" |sed -e... (3 Replies)
Discussion started by: snoman1
3 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

how to include "*" in echo command????

Hi All, I am doing one simple web tool. I have a HTML as my front end and cgi as my backend. Here my pb is when I assign the html form input to a variable in my script, it is not accepting the special char "*" to that varible. say I have a text box(Name : in_query) in html and trying to... (1 Reply)
Discussion started by: askumarece
1 Replies

10. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies
Login or Register to Ask a Question