Difficulty: Easy
Correct Answer: mv * ../bin
Explanation:
Introduction / Context:
Unix file operations often involve reorganizing directories. Moving a collection of files one level up into a specific subdirectory is a common task. Using shell globs correctly avoids mistakes like overwriting or targeting the wrong path.
Given Data / Assumptions:
bin
subdirectory of the parent directory, i.e., ../bin
.
glob unless explicitly specified.
Concept / Approach:
The command mv * ../bin
expands to all non-hidden entries in the current directory and moves them into
../bin
. This is the minimal, portable form. You should ensure that ../bin
exists and that the shell's glob does not expand to an empty list (some shells handle empty globs differently).
Step-by-Step Solution:
ls -ld ../bin
.Preview the expansion: echo
to see which files will move.Execute: mv * ../bin
.Confirm by listing ../bin
and the now-empty current directory (except hidden files).
Verification / Alternative check:
Use a dry run approach by testing in a temporary directory. For including dotfiles, use constructs like shopt -s dotglob
in bash or explicit patterns (.
) with care.
Why Other Options Are Wrong:
/bin
and matches only names containing a dot; risky and incorrect destination./bin/
rather than the directory; incorrect and dangerous.mv * ../bin
is correct.
Common Pitfalls:
Overwriting files with the same name at the destination; forgetting that *
excludes dotfiles; accidentally targeting /bin
instead of ../bin
; moving directories you did not intend to move.
Final Answer:
mv * ../bin
Discussion & Comments