Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม BASH

คำสั่ง Linux cd:เปลี่ยนไดเรกทอรี

บทช่วยสอนนี้จะอธิบายวิธีใช้คำสั่ง cd ใน Linux เพื่อเปลี่ยนไดเร็กทอรีที่คุณอยู่ในปัจจุบันภายในเชลล์

ก่อนหน้านี้เราได้กล่าวถึงวิธีการมองไปรอบๆ ในไดเร็กทอรีด้วย ls แต่ตอนนี้ คุณต้องเริ่มการนำทางรอบๆ ไดเร็กทอรี เราจะทำได้อย่างง่ายดายด้วย cd , เปลี่ยนไดเร็กทอรี มาเริ่มกันด้วยอะไรง่ายๆ เราจะเรียนรู้เพิ่มเติมเกี่ยวกับการอบแบบง่ายใน utils อย่าง cd ได้อย่างไร ? หากคุณลอง:

man cd

มันจะรายงานว่า "ไม่มีการป้อนซีดีด้วยตนเอง" เป็นไปได้มากที่สุด ให้ใช้ตัวช่วยแทนการอบได้

help cd

ไวยากรณ์ซีดี

ตอนนี้เราได้เรียกใช้ยูทิลิตีความช่วยเหลือที่เป็นประโยชน์แล้ว เราได้ผลลัพธ์ดังต่อไปนี้

cd: cd [-L|[-P [-e]] [admin@wsxdn.com]] [dir]
Change the shell working directory.


Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.


The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.


If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.


Options:
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of `..'
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
-e if the -P option is supplied, and the current working
directory cannot be determined successfully, exit with
a non-zero status
admin@wsxdn.com on systems that support it, present a file with extended
attributes as a directory containing the file attributes


The default is to follow symbolic links, as if `-L' were specified.
`..' is processed by removing the immediately previous pathname component
back to a slash or the beginning of DIR.


Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.

อย่างจริงใจ? นั่นเป็นครั้งแรกที่ฉันได้ดูงานพิมพ์ความช่วยเหลือเกี่ยวกับซีดี มาดูการใช้งานพื้นฐานกัน

cd ~

ตัวหนอนเป็นอักขระพิเศษที่อ้างอิงถึงโฮมไดเร็กตอรี่ปัจจุบันของคุณ เมื่อคุณใช้ cd ~ มันจะส่งคุณไปที่บ้านของคุณ ถ้าอยากรู้ว่ามันคืออะไร:

echo $HOME

จะพิมพ์โฮมไดเร็กตอรี่ของคุณ

cd ..

.. ยังเป็นข้อมูลอ้างอิงพิเศษอีกด้วย หมายถึงไดเร็กทอรีพาเรนต์ของไดเร็กทอรีการทำงานปัจจุบันของคุณ กำลังพิมพ์ cd .. จะพาคุณไปที่ไดเร็กทอรีด้านบน คุณสามารถเพิ่มระดับที่สูงขึ้นได้โดยพิมพ์:

cd ../..

ที่จะเพิ่มขึ้นสองครั้ง

cd /

/ แสดงถึงรากของระบบของคุณ พิมพ์ “cd /” จะพาคุณไปที่รูทหากคุณมีสิทธิ์ไปที่นั่น

บทสรุป

แค่นั้นแหละ! เคล็ดลับการทำงานที่ดีและเรียบง่ายสำหรับการใช้เชลล์