Terminal Prompt Warrior - Forget TimeShift and OBS
Two examples of why GUI applications aren't that important - best read while listening to Iron Maiden Aces High.
Back in June of this year, OMG Ubuntu gave us a heads up that the Linux backup tool TimeShift would become a Linux Mint XApp. Linux Mint taking this on is fantastic news for those who like using TimeShift on Linux machines where a GUI tool is the best option.Â
After reading the OMG Ubuntu article, it got me thinking - what if TimeShift, BackInTime, and other similar backup tools were to disappear? Think about it, a world filled with Linux users who cannot locate simple GUI applications to handle their data backups reliably! It would be chaos, would it not?Â
Now let's unleash further madness…what if OBS lost its principal developer?
Poof, OBS is gone! Then shortly after, SimpleScreenRecorder, among other similar GUI applications, disappeared! What would we do? Well, I'm about to tell you. Keep reading.
After reading the rest of this article, you'll realize it's not that big of a deal. Best of all, you will learn to do things using the terminal that may not have occurred to you previously.
Let’s rock and roll.
TimeShift disappears - It's rsync to the rescue
Many people do not realize that many backup tools like TimeShift are powered by a command line tool known as rsync for non-btfs file systems. Let's run man rsync and see what all the fuss is about, shall we?
This is the part I want to call special attention to:
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.
Rsync finds files that need to be transferred using a lqquick checkrq algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file's data does not need to be updated.
Some of the additional features of rsync are:
- support for copying links, devices, owners, groups, and permissions
- exclude and exclude-from options similar to GNU tar
- a CVS exclude mode for ignoring the same files that CVS would ignore
- can use any transparent remote shell, including ssh or rsh
- does not require super-user privileges
- pipelining of file transfers to minimize latency costs
- support for anonymous or authenticated rsync daemons (ideal for mirroring)
Rsync can do far more than what the typical GUI program using rsync lets on. Even better, you can run another fantastic command line tool called cron to automate the whole thing. Now let's run man cron to learn more. Also might want to man crontab as well.
With those two tools working together, the cron daemon reads a crontab file to determine what is scheduled to be automatically run at a specifically given date/time.Â
You can create a crontab entry to do interesting things like:
Run an rsync sequence to backup files to another device.
Clear out old log entries.
Watch for changes to a given file/folder, then take a specific action or other similar operations.
Run a specific program at a scheduled day and time. I want to run a script that renders a video I've created. Then to make this more interesting, what if the video was created using another command line sequence to capture images taken as photos from a webcam? Sure, you could use a bloated GUI program, but you can also do all of this without GUI access whatsoever.
I think you're beginning to get the idea. It can be set up in a crontab if it can be scripted.
Note: In a terminal, you can view your root or regular user crontab by typing this into your terminal.Â
crontab -l
(regular user)
sudo crontab -l
(root)
Since I don't have anything scheduled:
crontab -e
(regular user)
sudo crontab -e
(root)
I'm on Pop OS right now, so my crontab shows some random "commented out" stuff that came by default. Not to worry, running the crontab only lists things if there is anything to display. To make something show up, I'd need to run crontab -e (for edit).
In a future article, I will explain in-depth how to use "cron time," select a specific user/root, providing a run directory and path to a script/program.
Okay, now let's review what you've learned thus far.
Rsync allows Linux users to create incremental backups.
Crontab provides the engine in which to schedule these activities, in addition to scheduling anything else you could possibly imagine. If you can run it from a program from a terminal, you can run it in a crontab.
Pretty cool, right? One of the best rsync tutorials I've seen is provided by Digital Ocean. Follow this guide if you'd like to learn more about it. And of course, I also have a link to a decent crontab tutorial. The article is older, but it's pretty timeless.
OBS is GONE - FFmpeg unleashes the awesome on the CLI
Did you know that you can use FFmpeg from the terminal to create some critical video elements found with OBS? Additionally, it can also capture your audio sources. It's true, and while it's not for the faint of heart, today's FFmpeg documentation is pretty solid.Â
You can use FFmpeg from a terminal to do some pretty amazing stuff.
For example: Record your desktop while narrating.
Doesn't it require OBS or another GUI program? Not for you and I! Let me show you how to do this with this FFmpeg script. In case you haven't guessed, you will need to have installed FFmpeg and v4l-utils from your package manager for this to work.
First of all, let's make sure we identify your screen.
Pro-tip, don't try this with multiple monitors or attached monitors to a laptop. Just keep it simple for now.
Open a terminal and paste:
echo $DISPLAY
This tells me that my display is :1
Okay, awesome. Now that we know which display to use, let's plug it in.
ffmpeg \
     -f x11grab -thread_queue_size 1024 -video_size 1920x1080 -framerate 30 -i :1.0 \
     -f v4l2 -video_size 960x540 -framerate 25 -i /dev/video0   -filter_complex "[0][1]overlay=x=W-w:y=H-h" \
     -f pulse -i default -c:a libx264 \
     -vcodec libx264 test.mkv
See where I changed ":1.0?" It may also be okay with :1 on its own, but I had issues with it, so I added the ".0
."
Now, if you own a computer that efficiently uses OBS or SimpleScreenRecorder, this will work fine.
Run the script. Paste it exactly as it is laid out. Why? Because if you mess with the formatting, the \ elements might break your commands.
So what are these commands doing exactly? Well, this isn't a tutorial, but here is the gist of it.
X11grab is grabbing your screen. It is doing so at a resolution of 1920x1080 at 30fps.
V4l2 is grabbing live video from your webcam at a resolution of 960x540 at 25fps.
Pulse is your Pulseaudio (or Pipewire via pulse-pipewire) providing your audio. Remember, it's grabbing audio from the default (fallback) audio source.
Drop everything above into the "blender," set it to awesome, and toss in some other elements like the overlay. You have yourself ready to produce screen capture tutorials without any GUI. Cool, right?
This is a lot of badassery to soak in all at once. I'll grant you that. But before you wander off, there's more!Â
FFmpeg can also stream to Twitch! You read this correctly. Thanks to the ninjas over at the Arch Wiki, we have ourselves a killer guide to streaming to Twitch using nothing more than a terminal and a can-do attitude!Â
"GUI, we don't need no stinkin' GUI"
This is just a taste of what is possible using the Linux terminal and letting go of relying on the various GUI applications. In the near future, I'll show you how to record and play audio. Plus, I'll show you how to view images using feh and watch YouTube videos….from your terminal.
Stay tuned, true believers! Subscribe and comment. Let’s keep this Linux truck going!
Thanks for the tips, Matt. I'll have to give rsync a try.