Mv or cp with a . (dot)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mv or cp with a . (dot)?
# 1  
Old 11-30-2017
Mv or cp with a . (dot)?

How can I rename a file with a . prefix?
I actually need to copy the file but the . seems to be very tough to do.

mv ./bla ../fa/la/.bla - doesn't work. I've tried all sorts of bracketing and that doesn't work.

Maybe the only way to do it would be to name the file _.bla then rename it again immediately afterward to .bla?

Thanks.

Last edited by Scott; 11-30-2017 at 03:47 PM.. Reason: ICODE tags
# 2  
Old 11-30-2017
Those names, dots included, are literal names. Do all the things involved exist (the source file and the target directories)?

./bla is a file named bla in the current directory (./)... not a file name .bla in the current directory. That would be .bla, or ./.bla.

There's nothing particularly special about files that begin with a dot (.).

When saying "it doesn't work", be specific about what you mean. e.g. the error you get from the mv command.
This User Gave Thanks to Scott For This Post:
# 3  
Old 11-30-2017
In addition to what Scott has already said...

There are two things that are special about a filename starting with a period.

The ls command (without the -a option and without a filename pattern given as an operand that explicitly names the file) will not include those files in its output. (That is why files with names whose first character is a period are sometimes called hidden files.)

And, in the shell, filename matching patterns that do not begin with a period will not match a filename that has a first character that is a period. For example, if I am in a directory that contains the files ., .., .hidden, abc, and xyz, then the command ls will produce the output:
Code:
abc	xyz

the command ls -a will produce the output:
Code:
.	..	.hidden	abc	xyz

the command echo * will produce the output:
Code:
abc xyz

the command echo .* will produce the output:
Code:
. .. .hidden

and the command echo * .* will produce the output:
Code:
abc xyz . .. .hidden

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 11-30-2017
That's all good information, but there's nothing special about files beginning with a dot when they're referenced directly - I should have made that distinction, as it was my point, in the context of the question.
# 5  
Old 11-30-2017
Quote:
Originally Posted by Scott
That's all good information, but there's nothing special about files beginning with a dot when they're referenced directly - I should have made that distinction, as it was my point, in the context of the question.
I agree. I made a different assumption. My guess was that scribling didn't think that the command:
Code:
mv ./bla ../fa/la/.bla

succeeded because after running that command, a subsequent command:
Code:
ls ../fa/la

and didn't include .bla in the output.

Of course, all of this discussion is just guessing about what "doesn't work" meant in post #1 in this thread.
# 6  
Old 11-30-2017
I figured it out. It may be convoluted but it works.

Code:
c=$(cd ../../bla/bla ; find . -name *.xyz) # Set variable c to filename (./filename.xyz)
c=$(c:3:23) # Remove "./" from c variable's filename
c=.$(c:0:26) # Add a "." to the variable filename

cp ../..bla/bla/*.zyz ./$c # Copy the file and rename it with c variable's name

The reason I need to do it this way is because I need the filename to retain it's original name but still add the . as a prefix.

---------- Post updated at 01:48 PM ---------- Previous update was at 01:43 PM ----------

The only reason I'm naming the files with a . is under mac OSX .files are invisible to the average user. I'm working at a place and the mgt here gets all pissy if they see a file somewhere they don't expect it to be, but for things to load automatically they need to be in a certain place ... So, I'm copying the files with the . prefix so I don't have to listen to, "Why is this here?"

Come to think of it I don't know why they ask that question. They don't care why they're there and only want me to delete them regardless of the reason.
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 11-30-2017 at 08:36 PM.. Reason: Add CODE tags.
# 7  
Old 11-30-2017
That's a terrible solution, if you can consider it a "solution" at all (I got tired reading it half way through).

And "security by obscurity" thinking, as it would appear you intend, by hiding files (with a dot, that only an idiot wouldn't see, who'd magically think 'that's nice and clean') is no "security" at all.

Having said that, a company I used to work for once shipped a CD of production software to a big client with core dumps in many directories, albeit old ones, so your caution is understandable!

Files that begin with a dot are typically configuration-related. If you generate temporary files along the way, simply remove them when you're done. I, too, might ask 'what is this file' if I saw one that shouldn't be there, but I wouldn't get "pissy" about it until the next time I did a df, or got an alert, and saw a potential issue.

I'll get my coat.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List the file with a dot

I am on hp-ux and not able to catch the file with dot using a wild card. $ touch .test $ ls -l .test -rw-r--r-- 1 oracle dba 0 Mar 21 05:20 .test $ ls -l *test *test not found $ ls -la *test *test not found Why i am not able to list the file startign with .... (7 Replies)
Discussion started by: bang_dba
7 Replies

2. Shell Programming and Scripting

How to Removing a dot from a file name?

I need a script that will allow me to rename all of my files in subdir /FilesIn as follows: From kumc_835_111200.RMT.dat to kumc_835_111200RMT.dat kumc_835_111200.KMR.dat to kumc_835_111200KMR.dat .................etc How do I do that whithout doing a sed ... (10 Replies)
Discussion started by: mrn6430
10 Replies

3. Shell Programming and Scripting

removing DOT by using perl

Hi Friends, I have a variable which has a number (e.g. 12.1234). I want to remove "." (dot) from that number i.e. 121234 I want to do this using perl. Can you please guide me Thank you Anushree (2 Replies)
Discussion started by: anushree.a
2 Replies

4. Shell Programming and Scripting

Greping numbers with dot in it

Hi, I wanted to create a script what would take two numbers out of two files and add them together, but I got stuck with greping numbers what have a dot in it. So far I have grepped the two lines what include the numbers I need (from both files) to a third file and from that file I try to... (7 Replies)
Discussion started by: mario8eren
7 Replies

5. Shell Programming and Scripting

How to type a dot(.) instead of character?

Hi, I want to connect a Oracle databse through unix shell script. When I will execute a shell script it will ask for user name and password to connect the databsae. At the time of entering the password field value, it willl display the characters like star(*), dot(.) instead of exact... (2 Replies)
Discussion started by: rajesh08
2 Replies

6. UNIX for Dummies Questions & Answers

variable name with dot(.)

Hi, Is it possible to declare variable with name having dot(.) in it ? something like gs.test='HELLO' Thanks in advance :) (1 Reply)
Discussion started by: gopalss
1 Replies

7. Shell Programming and Scripting

Replacing dot for comma

I wanted to change 34.66 to 34,66. I tried the command: sed 's/./,/' $NUM Where $NUM is a variable with 34.66 value. The output is ,4.66 (2 Replies)
Discussion started by: bdalmeida
2 Replies

8. Shell Programming and Scripting

splitting on dot in perl

I am trying to split input that looks like ,2005-09-12 01:45:00.000000,2005-09-12 01:48:18.000000, I want to split on the dot . What I am using is ($ev_time,$rol)=split(/\./),$inputfile; This does not recognize the dot as what I want to split on. (2 Replies)
Discussion started by: reggiej
2 Replies

9. Shell Programming and Scripting

dot files

Hi, everyone. I'm now using rsync command, and please tell me what is the wildcard for below looks like. I want to chose dotfiles, such as .ipod .apple but i don't want to chose . and .. ------------------ .* doesn't work, of course. Thanks, Euler04 (2 Replies)
Discussion started by: Euler04
2 Replies
Login or Register to Ask a Question