About basic commands in bash (cp, cd,..) [closed]

梦想与她 提交于 2019-12-13 11:21:57

问题


I am trying to learn basic commands in the terminal. I have a couple of quick questions. I know that to make a file and place it in a specific folder, one needs to create the directory and then use touch to create an empty file and place it there by mv:

mkdir folder/sub

touch file.txt

mv file.txt folder/sub

Could we somehow chain these things together and use touch to create a file and place it in a specific directory in just one line?

and then if I am in a sub-directory, in order to get back from there (say: folder/sub) to my home, either of these three commands would work (cd, cd -, cd ..) I am not sure I get the differences among the three. I get that cd .. takes you back one step up but the other two seem to work exactly the same.

and let's say I have already a text file in my home directory named file.txt. If I write this in shell it overrides that existing file:

cp folder/sub/file.txt ~/

How would I go about this if I wanted to keep both files?


回答1:


  • You can pass a relative or absolute path in any folder to and command, including touch (although the folder must exist):

    touch folder/sub.file.txt
    
  • cd - switches to the folder you were last in (like a "Back" button)

  • . means the current directory

  • .. means the parent directory



来源:https://stackoverflow.com/questions/25107434/about-basic-commands-in-bash-cp-cd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!