copy some files from users home folders to my folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copy some files from users home folders to my folder
# 1  
Old 08-18-2009
copy some files from users home folders to my folder

i have users home directories in /home
all the users have some files starting with character e

and i want to copy all these files in a folder in my (root) home
using a script

i tried the script
for i in m5[01-48]
do
cd m5[01-48]
cp e1* /home/pc/exam
cd ..
done
but get these errors
./cpex: line 3: cd: m5[01-48]: No such file or directory
cp: cannot stat `e1*': No such file or directory

pls. help
# 2  
Old 08-18-2009
Hi.

The shell isn't able to expand m5[01-48], so the value of i will be exactly m5[01-48].

Even if the shell could expand it, your cd statement is attempting to change into all of the directories at the same time!

Code:
cd /home
for i in m5*; do
  cd $i
  cp e1* /home/pc/exam
  cd ..
done

# 3  
Old 08-18-2009
so you have dir named m501,m502...m548???
Code:
for i in m5* ; do
cd $i
cp e1* /home/pc/exam
cd ..
done

# 4  
Old 08-18-2009
Hi,

Below script can give you directories from m501-m548

Code:
for i in `ls -1d m5[0-4][0-9]|grep -vE "m500|m549"`
do
cd m5[01-48]
cp e1* /home/pc/exam
cd ..
done

Regards,

Ranjith
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. Shell Programming and Scripting

How do you compare two folders and copy the difference to a third folder in a remote server?

How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g. Folder A -- Is in a remote server and it has the following files TEST1.OUT TEST2.OUT TEST3.OUT Folder B --Is in a local server and it has the following files ... (5 Replies)
Discussion started by: cumeh1624
5 Replies

3. Solaris

Under /home there is no files and folders

When I'm logging as a user(i.e., oracle), I don't find any files and folders in /home Attached error message below, while logging... Last login: Fri Sep 7 08:08:09 2012 from ko.domain Could not chdir to home directory /home/oracle: No such file or directory Sun Microsystems Inc. SunOS... (6 Replies)
Discussion started by: karthikn
6 Replies

4. Shell Programming and Scripting

HELP! Need to compare 2 folders on 2 different systems, and copy unmatched filenames to other folder

This has been tearing my hair out. I need to: 1: compare server1:/data/archive/ to server2:/data/archive/ (through rsync, ssh, etc) 2: filenames that don't match, get copied (scp) to server2:/data/ server1 and server2 have ssh, scp, rsync access between eachother. Is there any option in... (3 Replies)
Discussion started by: damang111
3 Replies

5. Red Hat

sftp configuration | to lock users to their home folder.

In generally I use vsftp but I want to improve our security so I decide to use sftp instead of vsftp. We know that ssh,scp and sftp are in openssh server. How can I lock only sftp user to their home folder? And to prevent some users for sftp like root as such in vsftp daemon? (3 Replies)
Discussion started by: getrue
3 Replies

6. Shell Programming and Scripting

Script to copy User home folders to mounted windows share

First of all, let me state that I am a windows admin. I have a windows share mounted to /mnt/server I need a script that will either login as sudo or perform commands with sudo rights. I need the script to copy all of the users /home folders to the mounted windows share. Now If I can... (7 Replies)
Discussion started by: EricM
7 Replies

7. Shell Programming and Scripting

Find files of type within folder copy multiple results to different folders

Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument... (4 Replies)
Discussion started by: DC Slick
4 Replies

8. Shell Programming and Scripting

simple script to mount a folder in all users /home

Go easy on me - first post I need a simple script that will mount a directory in the /home folder of all users. I need to run this on boot and regular intervals as a cron job. I was hoping to achieve this by modifying fstab but it is not possible and I would like to avoid symlinks. I have... (7 Replies)
Discussion started by: barrydocks
7 Replies

9. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

10. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies
Login or Register to Ask a Question