Hi!,
I'm kinda new to shell scripting, Here's a problem that I have faced and dunno how to solve:
First,
I want my script to rename the files stored in a .txt file line by line(there's no pattern that I can use with mv, so I want mv to deal with a file generated by ls /home/whatever/ > whatever_files.txt). So, Let's that that now mv is dealing with the first line in whatever_files.txt which has a file name /home/whatever/whatever545.jpg, I want the new file to be called file_whatever.jpg. But in order to do that, I figured out that I must store the name of the file in a variable and having a mv command which looks like this:
mv whateverhey.jpg file_$filename

but I dunno how to store that name in a variable and how to make mv deal with files listed in a text file.

Thanks!

I figured out that I can a non C-style loop to work with all the files in directory but when I write this it doesn't work:
for filename in *
do
mv $filename hello_$filename
done

????

Thanks

cd /to/my/directory
find .  -name '*.jpg' | \
while read file
do
    mv $file "new"$file
done

PS: mv works only within a filesystem. Even though you may be
in directories that are close in terms of directory trees does not mean there are no intervening mountpoints. -

I indeed sometimes try to access some directories behind mount points(for example, hdb1 mounted on /home/user/myfolder), while the script is being executed from the user home directory, Do you mean that this can result in some problems?

Thanks!

In that case you have to use cp. mv does not mv over mount points.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.