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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-20-2016, 09:39 AM
|
#1
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Rep: 
|
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.
|
|
|
12-20-2016, 10:38 AM
|
#2
|
Member
Registered: Feb 2012
Location: Germany
Distribution: siduction
Posts: 134
Rep:
|
Boils down to finding the name of the folder. You started this thread, so you already know the answer.
|
|
|
12-20-2016, 10:52 AM
|
#3
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
@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
|
|
|
12-20-2016, 11:56 AM
|
#4
|
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
|
Code:
current_folder="$(date +%Y%m%d)"
mkdir "${current_folder}"
mv files "${current_folder}"
|
|
|
12-20-2016, 12:30 PM
|
#5
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
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?
|
|
|
12-20-2016, 12:34 PM
|
#6
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
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.
|
|
|
12-20-2016, 12:46 PM
|
#7
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
Also tried mv *.xlsx "${current_folder}" with no success
|
|
|
12-20-2016, 01:53 PM
|
#8
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
Got it working, this is the code:
mv *.xlsx "${current_folder}"
Thx to all that have helped!!!
|
|
|
All times are GMT -5. The time now is 04:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|