how to copy between folders and parent folder without complete path how to copy between folders and parent folder without complete path linux linux

how to copy between folders and parent folder without complete path


This comes across as so basic that I must have misunderstood something in your question.

If you want to refer to a parent directory, .. is the way to do that. So, if you want to copy friction1.txt to two places you just do

cp friction1.txt ..cp friction1.txt ../force

All you need to take care of is making sure that CWD is

/home/hassan/Dyna/ProjectSimulation/friction

so that the references point at the right place.


You can temprarily change the current directory to ProjectSimulation, copy the file (cp friction/friction1.txt .), then change the path back to the original (so the rest of the script works as before)

Alternatively, you can use dirname to get he name of the parent directory and use that.


Change to the root dir of your known directory structure. Then do the copy operations with relative paths. Then change back to your dir where you came from.

Your friends are:

cdcd -

or better:

pushdpopd

(see man bash)

I.e.

pushd /home/hassan/Dyna/ProjectSimulationcp friction/friction1.txt .cp friction/friction1.txt forcepopd