อย่างที่คนอื่นพูดคุณอาจใช้คำสั่งของคุณในไดเรกทอรีว่าง อีกวิธีหนึ่งในการทำเช่นนี้ (ที่ก็จะล้มเหลวอย่างเงียบ ๆ ใน directory ว่าง) คือการใช้find's -execดำเนินการ:
find . -exec mv '{}' ../ \;
สิ่งนี้จะทำให้คุณมีข้อผิดพลาด:
mv: cannot move `./' to `../.': Device or resource busy
นี่เป็นเพราะฉันไม่ได้ จำกัดfindประเภทไฟล์ดังนั้นมันจะพยายามย้ายไดเรกทอรีปัจจุบัน ( .) และล้มเหลว คุณสามารถละเว้นข้อผิดพลาดนี้ได้อย่างปลอดภัยหรือคุณสามารถระบุว่าคุณต้องการไฟล์และโฟลเดอร์ทุกประเภท:
find . \( -type f -o -type d \) -exec echo '{}' ../ \;
จากman find:
-exec command ;
Execute command; true if 0 status is returned.
All following arguments to find are taken to
be arguments to the command until an argument
consisting of `;' is encountered. The string
`{}' is replaced by the current file name
being processed everywhere it occurs in the
arguments to the command, not just in argu‐
ments where it is alone, as in some versions
of find. Both of these constructions might
need to be escaped (with a `\') or quoted to
protect them from expansion by the shell.