How to rename a file in a directory using the current directory
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 go to ali directory in terminal, but when I run bash file it cannot find /b.txt file
I know this mv home/Desktop/ali/a/b.txt home/Desktop/ali/a/c.txt
will work fine, but is there a way to use the current directory to shorten the addressing?
If you want a mv
local file, just leave an empty line:
mv a/test.py a/test1.py
You can use anyway pwd
to do this, but keep in mind that you need to run your script in the same directory!
mv `pwd`/a/test.py `pwd`/a/test1.py
You don't need to provide a location if you are in that directory.
For example, you have a file A
on your desktop, so you navigate there and do:
mv A B
The file has A
been renamed to B
in this directory
But if you want to do it from somewhere else, you do
mv directory/A directory/newfilename
if you run the script from Ali directory then your mv statement looks like
mv `pwd`/a/test.py `pwd`/a/test1.py
or
mv ./a/test.py ./a/test1.py