Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
>Did you also notice the different spelling? In the cp -r command, the directory name starts with
>"NO_lo", whereas in the ls commands you used "NE_lo".[/QUOTE]
Sorry, i change the file name.
My problem is that there is space in the file i want to copy, it is an windows file in a samba share.
Is it possible to do an for loop or something to copy the windows file with space in linux?
[ftp]$ ls -ltr *NE*
-rwxr-xr-x 1 root root 210304 Jun 30 2006 NE_lo 01.07.2006
So, please take a look at the posts of that thread.
If you still have questions after that, then post back on this thread.
Edit: during the copy, you might want to change the filenames so that they don't include the
space any more.
Code:
#Let's assume that the original name is stored in the variable $fileName (this can be your
#loop variable, for instance)
newName=`basename ${fileName} | tr -s " " "_"`;
cp ${fileName} /new/path/on/Linux/${newName}
Instead of "tr", you may also use "sed" or "awk".
If you don't want the replacing to spaces, you can added other characters as well, or
use tr's character classes.
So, please take a look at the posts of that thread.
If you still have questions after that, then post back on this thread.
Edit: during the copy, you might want to change the filenames so that they don't include the
space any more.
Code:
#Let's assume that the original name is stored in the variable $fileName (this can be your
#loop variable, for instance)
newName=`basename ${fileName} | tr -s " " "_"`;
cp ${fileName} /new/path/on/Linux/${newName}
Instead of "tr", you may also use "sed" or "awk".
If you don't want the replacing to spaces, you can added other characters as well, or
use tr's character classes.
hi,
I still have some problem with this copy script.
When i try to copy the windows file with spaces, it still dont work:
[root@$ ls -ltr *NE*
-rwxr-xr-x 1 root root 32704 Dec 1 20:22 NE 02.12.2006
[root@$ find /app/disk1/~name/ -iname "*NE*" | \ while read I; do cp "$I" /app/disk2/~name2/in.txt; done;
-bash: syntax error near unexpected token `do'
As you can see, i am trying to copy the content of("*NE*") into this file /app/disk2/~name2/in.txt
For instance, use find's -exec option to execute your cp command on each item found.
Don't forget to terminate the -exec option with \;
As for the error, I think your command is a little screwed up. After the \ line separator, I expected to see a newline. The shell may not see the 'while' command and hence has a problem interpreting the 'do'. But that's just my first impression.
>For instance, use find's -exec option to execute your cp command on each item found.
>Don't forget to terminate the -exec option with \;
>As for the error, I think your command is a little screwed up. After the \ line separator, I expected to see a >newline. The shell may not see the 'while' command and hence has a problem interpreting the 'do'. But that's just my >first impression.
What part of my post isn't clear to you? Or with which part of the command do you need help?
Hi,
When i am trying to take the data from *NE* file and put it into source_inn.txt in the commeand under here.
#find /data/out/ftp/~files/ -iname "*NE*" | while read I; do cp "$I" /data/in/source_inn.txt; done;
Nothing happens when i use this command, can you please help me to get this command or something else so i can get the data from *NE* over in the text file source_inn.txt..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.