I have a process to backup files and folders and restore them back again in the Linux terminal and I was wondering if there was some way to automate the process instead typing in the code, which is always the same anyway. And possibly could lead to zero mistakes by my fat fingers all the time.
-
You could simply just create a script and launch it when you are ready. Pretty simple to do. Without knowing what commands you are running I cannot create it for you.. plus I discourage that as you won't learn without doing. Head over to Linux.com to learn about writing some shell.– Some DudeCommented Sep 11, 2016 at 17:27
-
Programs like Reflections Desktop allow you to record macros. What have you tried?– RamhoundCommented Sep 11, 2016 at 17:50
1 Answer
You probably want to write a bash script.
You start by adding a line that tells your system “Hey, this is a bash script”. This way, your system knows what interpreter to use. For bash, this is typically #!/bin/bash
.
Typically, for a backup script, you want commands to run in a specific order and fail if a previous command fails. The way to do this is to use &&
.
So command1 && command2
would run command2
only if command1
ran.
In other cases, you want to stream the output of a command into another command, in which case you use pipes.
If it’s an interactive application, you can pair this up with expect. Otherwise, it’s good practice to use variables.
Bash is a lot more powerful than this though — it’s got things like conditionals and loops you can abuse to make your life a lot easier. It’s also a handy ‘glue’ for tying together many simple text applications.
-
It should be
#!/bin/bash
with exclamation mark added. Commented Sep 12, 2016 at 1:42 -