LinuxQuestions.org
Help answer threads with 0 replies.
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 01-20-2017, 01:25 PM   #16
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,062
Blog Entries: 13

Rep: Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505

Please note that nodir posted some links referencing the concepts they introduced and there are examples of those concepts in those links.

Unsure if I had offered this link before in one of your other questions, My Bash script blog this has some useful tips for debugging and various techniques to use when developing bash scripts.

There are some code examples in that blog, but the code is specific to my examples and activity I'm discussing.

For now, the recommendation to stay away from using the output of ls is a good one. Myself I'd find files and use the output of the find command to accomplish my next step actions.

Also, in general I find that file names with special characters, spaces, or added extensions, like .tar.gz, or joes file.xlsx will cause issues with bash scripts or commands unless they are properly coded. I find using double quotes around wildcard or other types of special characters are important.
 
1 members found this post helpful.
Old 01-20-2017, 01:50 PM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
Obviously not tested, but something like:
Code:
current_date=$(date "+_%m%d%Y")
windows_folder="/dir1/dir2/dir3/reports/dir4/dest_folder/$current_date"
# Make folder
mkdir -p "$windows_folder"

# Change permissions of folder
# This line doesn't make sense.  Above creates a directory in current folder
# why are you chmoding the same folder at the end of some random path???
#chmod 777 /dir1/dir2/dir3/reports/${current_folder}

# Append current date to all files
#for file1 in $(ls *[a-z].xlsx)
for file1 in *[a-z].xlsx
do
# basefile1=$(echo $file1 |awk -F. '{print $1}')
# current_time=$(date "+_%m%d%Y.xlsx")

# mv $file1 ${basefile1}${current_time}

  mv "$file1" "$windows_folder/${file1%.*}${current_date}.xlsx"
done

# Create variable
#current_folder=$(date "+%m%d%Y")


# Move files into folder labelled with the current date
#mv *.xlsx "${current_folder}"

# Move whole folder to local shared Windows folder
#mv "${current_folder}" //dir1/dir2/dir3/reports/dir4/dest_folder
I have either commented out your code or left some comments as some parts were confusing. You may need to provide more details, but it should be fairly clear.
Let me know any bits you don't follow?
 
1 members found this post helpful.
Old 01-24-2017, 07:19 AM   #18
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
The code below from Grail solved my issue:
Code:
current_date=$(date "+_%m%d%Y")
windows_folder="/dir1/dir2/dir3/reports/dir4/dest_folder/$current_date"
# Make folder
mkdir -p "$windows_folder"

# Change permissions of folder
# This line doesn't make sense.  Above creates a directory in current folder
# why are you chmoding the same folder at the end of some random path???
#chmod 777 /dir1/dir2/dir3/reports/${current_folder}

# Append current date to all files
#for file1 in $(ls *[a-z].xlsx)
for file1 in *[a-z].xlsx
do
# basefile1=$(echo $file1 |awk -F. '{print $1}')
# current_time=$(date "+_%m%d%Y.xlsx")

# mv $file1 ${basefile1}${current_time}

  mv "$file1" "$windows_folder/${file1%.*}${current_date}.xlsx"
done

# Create variable
#current_folder=$(date "+%m%d%Y")


# Move files into folder labelled with the current date
#mv *.xlsx "${current_folder}"

# Move whole folder to local shared Windows folder
#mv "${current_folder}" //dir1/dir2/dir3/reports/dir4/dest_folder
Thank you everyone for your help!!!
 
  


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
Moving Windows files (user) files to Linux bmrzmr2 Linux - Newbie 3 11-13-2015 04:09 PM
Moving windows files to Linux rgwic Linux - Newbie 11 04-06-2014 02:36 AM
Moving FIles from Windows fileserver to Linux stgiaf Linux - Server 2 11-23-2013 05:31 PM
moving files from windows to linux...urgent samyakm Linux - Newbie 5 01-02-2005 02:56 AM
moving files between windows and linux endezeichen Linux - Software 4 11-19-2003 02:39 AM

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

All times are GMT -5. The time now is 11:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration