LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2021, 01:47 PM   #1
nelson1387
LQ Newbie
 
Registered: Oct 2021
Posts: 1

Rep: Reputation: Disabled
bash script generates error "No such file or directory".


Hello:

I have a script that renames files in the current directory.

#!/bin/bash

mv file01.jpg newfile01.jpg
mv file02.jpg newfile02.jpg
.
.
.
mv filenn.jpg newfilenn.jpg

When I run the mv command from terminal, the command works. When I run a script, it comes back with No such file or directory. When I execute from Finder the error is No such file or directory for each command. Have I missed a step in creating the script?
 
Old 10-20-2021, 02:03 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by nelson1387 View Post
When I execute from Finder
macOS?

How do you execute the script?
Code:
bash your_script_name
Quote:
Originally Posted by nelson1387 View Post
mv filenn.jpg newfilenn.jpg
Do you really have a file named filenn.jpg or does nn stand for a number? Then show us the real script.

BTW, does you system have the command rename?

Last edited by shruggy; 10-20-2021 at 02:07 PM.
 
Old 10-20-2021, 02:07 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,322
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Welcome. Which distro?

Double check the working directory which the script is using, it sounds like it may be different. Use cd and pwd for that.

If you are doing a bulk rename, you might see if the prename version of rename is on your system.

Code:
prename -n 's/^file([0-9]{2}).jpg/newfile$1.jpg/' file*.jpg
man prename
It is the perl variant of that utility and can take any perl expression, not just regular expressions. So you can count or add or whatever as part of the renaming.

Last edited by Turbocapitalist; 10-21-2021 at 02:05 AM. Reason: grammar
 
Old 10-20-2021, 07:02 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
make sure you have execute perms on the script
Code:
chmod +x /path/to/your/script
 
Old 10-20-2021, 11:06 PM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Try running it again from the command line and see what happens.
 
Old 10-21-2021, 02:01 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
just a note: the current directory is local, all the apps/programs have their own current directories. Therefore you may need to put a cd <required dir> in that script before those mv lines.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"bash: /usr/bin/git: No such file or directory " - why does bash look in /usr/bin babu198649 Linux - Newbie 9 04-24-2023 01:32 PM
[SOLVED] error: asm/ppc_asm.h: No such file or directory and error: asm/processor.h: No such f Thirupathip Linux - Newbie 3 01-25-2013 03:02 AM
Bash says "No such file or directory" but directory exists Fm3m Linux - General 7 10-28-2011 12:33 AM
Simple bash script generates error hal8000b Programming 2 07-01-2010 06:43 AM
Grep in bash script returns "No such file or directory", works manually gizza23 Programming 7 02-25-2010 04:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration