3

I want to rename a file (home/Desktop/ali/a/b.txt)

I wrote a bash file

#!/bin/bash

mv a/b.txt a/c.txt

and put it in ali directory,I navigate to ali directory in terminal but when I execute the bash file it can't find a/b.txt

I know mv home/Desktop/ali/a/b.txt home/Desktop/ali/a/c.txt will work fine, but is there any way to use current directory to shorten the addressing?

3 Answers3

0

If you want to mv a local file, just leave the dir blank:

mv a/test.py a/test1.py

Anyway you can use pwd for that, but keep in mind that you need to run the script in the same dir!

mv `pwd`/a/test.py `pwd`/a/test1.py
TheoB
  • 141
  • 7
0

You don't need to provide the location if you are in that directory.

For example you have file A in desktop so you navigate there and do:

mv A B

File A was renamed to B in that directory

But if you want to do so from another location then you do

mv directory/A directory/newfilename

MichaelMMeskhi
  • 659
  • 8
  • 26
0

if you run script from Ali directory then your mv statement seems like

mv `pwd`/a/test.py `pwd`/a/test1.py

or

mv ./a/test.py ./a/test1.py