关于 bash 中的基本命令(cp、cd、..)
我正在尝试学习终端中的基本命令.我有几个简单的问题.我知道要创建一个文件并将其放置在特定文件夹中,需要创建目录,然后使用 touch
创建一个空文件并通过 mv
将其放置在那里:
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
我们能否以某种方式将这些东西链接在一起并使用 touch
创建一个文件并将其放在特定目录中的一行中?
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?
然后如果我在一个子目录中,为了从那里(比如:文件夹/子)回到我的家,这三个命令中的任何一个都可以工作(cd
,cd -
, cd ..
) 我不确定我是否明白这三者之间的差异.我知道 cd ..
会让你往回走一步,但其他两个似乎完全一样.
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.
假设我的主目录中已经有一个名为 file.txt
的文本文件.如果我在 shell 中编写它,它会覆盖现有文件:
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?
-
您可以将任何文件夹中的相对或绝对路径传递给 and 命令,包括
touch
(尽管文件夹必须存在):-
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 -
切换到您上次所在的文件夹(如返回"按钮) -
cd -
switches to the folder you were last in (like a "Back" button).
表示当前目录..
表示父目录
-