Visit Our UNIX and Linux User Community

Mv or cp with a . (dot)?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mv or cp with a . (dot)?
# 8  
Old 11-30-2017
I was quite proud of it. It works fast and efficiently. BTW there is no security issue here. I work in visual fx. We use files called cdl (color decision list) ... well if the cdl file is in the parent directory of the files you're viewing it'll load the cdl automatically. If not, you have to go find it and move it in manually. Originally, I put copies of the cdl files where they need to be and next thing I know there's a company wide email about keeping the file structure clean and cdl files don't belong in the ... So, now I just hide them. They're still there and they work just fine with the . prefix but these people can't see them and therefore don't complain. If you heard them go on and on about you'd think I rearranged the living room of a blind person. I have to do the same with any symlinks and aliases as well.
"What is this?"
An alias ...
"Why is it here?"
So you can go to that directory quickly and easily ...
"Who's it for?"
Anyone ...
"Well, we don't use these here!"
It's not hurting anyone ...
"We need to keep things consistent!"
What is the problem?

This is what I'm dealing with.
These 2 Users Gave Thanks to scribling For This Post:
# 9  
Old 11-30-2017
Thank you for cheering me up with that story.. and for reminding me that not everything is black or white.
# 10  
Old 11-30-2017
No, that's not the way WE do it ...

It drives me crazy when I start a new job and they say, "This is how we do ..."
I sit and watch and when they finish I usually say, "You do that every time, with every file?"
"I could easily write a script that'll do all that stuff in about 5 seconds ... and it won't make mistakes."
"THIS IS THE WAY WE HAVE ALWAYS DONE IT HERE! And we want you to do it that way."
"Oh, I'll do it the same as you do but I'm not going through all that ..."

Usually, after a few days the other artists are asking me, "How do you do that so fast?"
"I wrote a script. These are computers! They're made to do repetitive tasks quickly and easily." What is wrong with you people?!

So, back to the original question, is that a dumb way to copy the file and rename it with a . prefix? If there's another way, I'd love to hear it.
# 11  
Old 11-30-2017
I've worked in a bank.. you're preaching to the converted lol.

I'm not sure that the original way we showed you was wrong, so...
# 12  
Old 11-30-2017
Note that the following code:
c=$(cd ../../bla/bla ; find . -name *.xyz) # Set variable c to filename (./
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

won't work if no files match the pattern and won't work if more than one file matches the pattern ../../bla/bla/*.xyz. The following should work no matter how many files in that directory match:
find ../../bla/bla -name '*.xyz' | while read -r c
do	cp "$c" ".${c##*/}"

If you want it to keep you informed about what it's doing, either add a set -x to the start of the script or add an echo "$c" before the copy command in the loop.

P.S. Note however that if there is a hidden file in your source directory that ends in .xyz you'll end up creating a file with two leading <period>s in your current working directory.

Last edited by rbatte1; 12-01-2017 at 10:56 AM.. Reason: Change mv to cp & add PS.; rbatte1 added a spce into set-x
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 11-30-2017
Yes! That's what I'm looking for

Actually, I wanted it to fail if no files matched.

I like the cp "$c" ".${c##*/}" idea. I'll try that.

Thanks for allowing me to vent. My wife can't comprehend. I told her it's as if someone was still using the pony express because "That's the way we've always done it!" I'm still not sure she gets it. I find that after a certain age many people literally refuse to learn anything new.

Last edited by rbatte1; 12-01-2017 at 10:57 AM.. Reason: Added ICODE tags
# 14  
Old 11-30-2017
Even better... Now you can get rid of the find too:
for c in ../../bla/bla/*.xyz
do	cp "$c" ".${c##*/}"

If there aren't any matching files, you'lll get a diagnostic from cp saying something like:
cp: ../../bla/bla/*.xyz: No such file or directory

and a non-zero exit from your script.

P.S.: Note that (as mentioned before) this code won't copy hidden files.

Last edited by Don Cragun; 11-30-2017 at 11:52 PM.. Reason: Add PS.

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

Featured Tech Videos