Visit Our UNIX and Linux User Community

Move all files one directory level up

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Move all files one directory level up
# 1  
Old 02-25-2016
Move all files one directory level up

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

For example:


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


# 2  
Old 02-25-2016
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

# 3  
Old 02-25-2016
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?
# 4  
Old 02-25-2016
man bash:
AND and OR lists are sequences of one of more pipelines separated by the && and || control operators, respectively. AND and OR lists are executed with left associa‐
tivity. An AND list has the form

command1 && command2

command2 is executed if, and only if, command1 returns an exit status of zero.
# 5  
Old 02-25-2016
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?
# 6  
Old 02-25-2016

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.

# 7  
Old 02-25-2016
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.


Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How Create new directory and move files to that directory.?

Hi All, We have main directory called "head" under this we have several sub directories and under these directories we have sub directories. My requirement is I have to find the SQL files which are having the string "procedure" under "head" directory and sub directories as well. And create... (14 Replies)
Discussion started by: ROCK_PLSQL
14 Replies

2. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some some_name_2016-01-17-22-40-30_some some_name_2016-01-17-22-48-50_some and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. UNIX for Dummies Questions & Answers

Zip all files in a directory and move to another directory

Hi, need to zip all files in a directory and move to another directory after the zip.. i am using this one but didnt help me... zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/ i am trying to zip all the files in my_proj... (0 Replies)
Discussion started by: dssyadav
0 Replies

5. UNIX for Dummies Questions & Answers

How to move files between 2 dates from one directory to another

Hi All, I am coding for a requirement where I need to move files (filename.yymmdd) from one directory(A) to another(B) based on 2 date fields in a paramtere file. (Paramfile.txt) For e.g: In Paramfile.txt, BUS_DT =20120612 SUB_DT =20120602 In this case, i need to move all the files... (14 Replies)
Discussion started by: dsfreddie
14 Replies

6. Shell Programming and Scripting

Find and Move Files up One Level

Hi All, So I have another question. I'm trying to search for files with a certain extension and then move all of them up one level in the folder hierarchy. So something like this: original: /path/to/file/test.txt after: /path/to/test.txt I had some great help recently with another... (4 Replies)
Discussion started by: ideal2545
4 Replies

7. Shell Programming and Scripting

Move files to variable directory

Im trying to move my files to a variable folder i've just created. Step 1 is working fine. mkdir /sdcard/DCIM/Photos/`date +%Y%m%d` Step 2 is not working mv /sdcard/DCIM/100ANDRO/*.jpg /sdcard/DCIM/Photos/`date +%Y%m%d` What am i doing wrong? (2 Replies)
Discussion started by: dihavs
2 Replies

8. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies

9. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

Featured Tech Videos