LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2017, 09:58 AM   #1
vyash
LQ Newbie
 
Registered: Nov 2016
Distribution: Fedora
Posts: 6

Rep: Reputation: Disabled
Copy in the latest folder created.


Hello,

Im new to bash scripting.
What I currently have is this:
Code:
mkdir /.bak/"VPS.backup.$(date +%F_%R)"
Now what I want is to copy a file/directory into that directory. How do I do it in the script?

Note: This script will repeat itself everyday.

Thank you!
 
Old 03-24-2017, 10:05 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You could use a shell-variable:
Code:
#!/bin/sh
BackupDir="/.bak/"VPS.backup.$(date +%F_%R)"
mkdir -- "$BackupDir"
cp -a a_file_or_directory "$BackupDir/"
 
1 members found this post helpful.
Old 03-24-2017, 10:06 AM   #3
vyash
LQ Newbie
 
Registered: Nov 2016
Distribution: Fedora
Posts: 6

Original Poster
Rep: Reputation: Disabled
Talking

Quote:
Originally Posted by NevemTeve View Post
You could use a shell-variable:
Code:
#!/bin/sh
BackupDir="/.bak/"VPS.backup.$(date +%F_%R)"
mkdir -- "$BackupDir"
cp -a a_file_or_directory "$BackupDir/"
Life saver
 
  


Reply

Tags
bash, programming, script



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
How to limit max. number of folder can be created inside a folder Winanjaya Linux - General 4 08-01-2013 05:47 AM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 02:20 AM
Scripts to list folder contents and copy images from folder and subfolders brunces Linux - Newbie 6 11-03-2011 01:23 PM
[SOLVED] Cant make new folder or copy paste in my newly created partition institopper Linux - Newbie 9 07-13-2011 10:05 PM
want to copy an inode folder from acdrom to a home directory (folder). nhbob Linux - Newbie 8 12-20-2009 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 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