how to copy between folders and parent folder without complete path

40,191

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.

Share:
40,191
hamad khan
Author by

hamad khan

I am a student of engineering and willing to go extra mile to learn linux. I am fan of Linux.

Updated on July 05, 2022

Comments

  • hamad khan
    hamad khan almost 2 years

    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.