LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2016, 09:39 AM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Move files into current dated folder


I need to move all files with an extension of .xlsx into a folder that is named the current date. I have the dir automatically created daily:

mkdir $(date '+%Y%m%d')

and I have files in this format:

file_20161220.xlsx
file2_20161220.xlsx etc etc

and I need these files to be moved into the current dated folder daily. This is the format of the current dated folders:

12202016
12212016

Last edited by trickydba; 12-20-2016 at 09:56 AM.
 
Old 12-20-2016, 10:38 AM   #2
Ratamahatta
Member
 
Registered: Feb 2012
Location: Germany
Distribution: siduction
Posts: 134

Rep: Reputation: 17
Boils down to finding the name of the folder. You started this thread, so you already know the answer.
 
Old 12-20-2016, 10:52 AM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Ratamahatta...... I'm not quite sure I follow you. Yes I have the files with the current dates attached but I need these files moved to a folder that is named the current date as such:

12202016

I tried to create a variable: current_folder=mkdir $(date "+%Y%m%d")

Then change the permissions of that folder: chmod 777 /export/home/exg85/$current_folder

so that I can copy these files to the folder named the current date with no success
 
Old 12-20-2016, 11:56 AM   #4
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Code:
current_folder="$(date +%Y%m%d)"
mkdir "${current_folder}"
mv files "${current_folder}"
 
Old 12-20-2016, 12:30 PM   #5
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I tried this code to moves all files with an extension of ".xlsx" to a folder labelled with the current date with no success:

mv *.xlsx "${current_folder}"

What am I doing wrong?
 
Old 12-20-2016, 12:34 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I also tried this:

mv *.xlsx /export/home/eric/reports/${current_folder}

with no success. The files and the folder are in the same folder

I tried putting double quotes in too: mv /export/home/eric/reports/*.xlsx /export/home/eric/reports/"${current_folder}"

I get the error:

mv: '/export/home/exg85/reports/file_20161220.xlsx' ande '/export/home/exg85/reports/file_20161220.xlsx' are the same file.

But I specified to move the file to a folder labelled with the current date

Last edited by trickydba; 12-20-2016 at 12:44 PM.
 
Old 12-20-2016, 12:46 PM   #7
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Also tried mv *.xlsx "${current_folder}" with no success
 
Old 12-20-2016, 01:53 PM   #8
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Got it working, this is the code:

mv *.xlsx "${current_folder}"

Thx to all that have helped!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Copy files into current dated folder trickydba Linux - Newbie 2 12-14-2016 08:07 AM
how to move all files to home folder sadikemre Linux - Newbie 5 03-09-2013 08:31 PM
Used mv to move folder, but where are the files? kmacphail Linux - Software 13 01-11-2010 06:06 AM
How to automatically move files from one folder into another folder? xmrkite Linux - Software 6 11-05-2006 10:39 AM
How to move a folder and replace files RAdams Linux - Newbie 2 06-24-2006 12:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration