Moving files up one level — send everything to ../bin Which command moves all non-hidden files from the current directory into the bin subdirectory of the parent directory?

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:

  • You are in a directory containing files you want to move.
  • The destination is the bin subdirectory of the parent directory, i.e., ../bin.
  • Hidden files (names beginning with a dot) are not included by the 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:

Verify destination exists: 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:

  • mv . /bin/: targets system-wide /bin and matches only names containing a dot; risky and incorrect destination.
  • mv * /bin/: tries to move into files that match /bin/ rather than the directory; incorrect and dangerous.
  • mv * ../bin .: syntactically wrong for a single destination; provides extra arguments without clear intent.
  • None of the above: incorrect because 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

More Questions from Unix

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion