how to copy between folders and parent folder without complete path

hamad khan picture hamad khan · Mar 29, 2012 · Viewed 36.8k times · Source

This is a basic question but I am struggling to find a decent solution. This is hindering my script from automation.

I have the following path.

/home/hassan/Dyna/ProjectSimulation

in project simulation I have 3 folders

friction time force

like

/home/hassan/Dyna/ProjectSimulation/friction

Now I have a file friction1.txt in this friction folder and I want to copy it to ProjectSimulation.

is it possible to avoid complete path and just one step down?

Also if I have to copy this friction1.txt to folder force, is there anyway to avoid the complete path.

I mean I have a subroutine but this is path dependent , whenever I run it , I have to run in the same folder and then copy my results so I can run only one instance of my simulation.

Experts please guide me.

PS: This is part of a 600 lines shell.

Answer

HonkyTonk picture HonkyTonk · Mar 29, 2012

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.