Move all files one directory level up

I want to move all the files in a given directory up one level.

For example:

Dir1
Subdir1

I want to move all the files in Subdir1 up to Dir1 (then I want to ultimately delete Subdir1)

Thanks,

Ted

Making lots of assumption about what shell you might be using, how many files there might be in Subdir1 , and the lengths of the names of the files in Subdir1 , the simple thing to try first would be something like:

cd DIr1/Subdir1 && mv * .. && cd .. && rmdir Subdir1

Thanks so much. I could not find any answer to what "&&" means, but I think it is a way to separate many commands so you can write them all on a single line. Is that correct?

man bash :

Cool. Thanks. I am quite a newbie at this, but I think I understand. So || means OR?

e.g. command1 || command2

Command2 would be executed only if command1 is not executed. Correct?

No.

man bash :

       An OR list has the form

              command1 || command2

       command2 is executed if and only if command1 returns a non-zero exit status.  The return status of AND and OR lists is the exit status of the last command executed  in
       the list.

Given that I don't understand what an exit status is, I was afraid that would be your answer. I just started trying to understand this stuff, and I am sure that one day I will get it. Thanks for your help.

Ted

The exit status reflects success (= 0) or failure (<> 0) of a command. E.g. ls a non-existent file will return 2.

Well, that was easy.

I am using bash. I have been having success working with loops and variables, and what I want to do is get a list of directories in my current directory, and with a DO-WHILE loop get the first name in the list and make it the variable DIRECTORYTOWORKWITH, then work with the directory, the go to the next directory in the list, and start over.

I know I can do it with 'find' and pipes, but I don't fully understand all the options { like -r and print() }, nor to I know how to parse the list one item at a time.

Ted

Start by reading the man pages for your shell ( bash ) and for the find utility:

man find
man bash

Unfortunately both of those are long man pages with lots of words with very detailed meaning that may be foreign to you as a beginner. On the bash man page pay special attention to the sections titled DEFINITIONS, SHELL GRAMMAR (where you'll learn about pipelines, && , || , and a bunch of other shell magic), QUOTING, and EXPANSIONS (especially the subsection titled Pathname Expansion).

Fortunately, both of those pages usually have examples that you can play with to get an idea of how things work. Play with those examples. Try to expand what you learn from those examples to do other things you want to do. And consider the two examples below...

First, if you want to process directories in the current directory, try:

for DIRECTORYTOWORKWITH in */
do	printf 'Now processing directory "%s"\n' "$DIRECTORYTOWORKWITH"
	# Do what ever you want to do to this directory.
done

And second, if you want to process all directories in and under the current directory starting with the directories deepest in the current file hierarchy, try:

find . -depth -type d | while read -r DIRECTORYTOWORKWITH
do	printf 'Now processing directory "%s"\n' "$DIRECTORYTOWORKWITH"
	# Do what ever you want to do to this directory.
done

And then, if you get lost or can't understand what the man pages are saying, come back here and ask questions.

For a very short and very incomplete (but hopefully also very easy to understand) introduction about how the find-command works read here.

Reading the man-pages as Don suggested is still a worthwile effort.

I hope this helps.

bakunin