The cp command is ideal for copying files and directories on a Linux or Unix distribution. You will likely not need to use additional options for most tasks as the basic command will achieve most requirements.
This tutorial will take you through several use cases for using cp on a Linux distribution. For example, we cover copying single files, copying multiple files and directories, setting backups, copying recursively, and much more.
Category: OS X
How to stop a bash script from being executed too frequently
Every so often something really useful appears on Reddit, and this is such a case. You may encounter a situation where you want to execute the contents of a bash script, but not more frequently than every few seconds. A Reddit user wanted to know How to check if a command in .bashrc has been executed within last 10 seconds if yes don’t execute the command again. The response by Reddit user mdaffin is brilliant in its simplicity, and can be used in any bash script where you don’t want the contents executed too often:
Write a time stamp to some file, check said file before you run the command if now – timestamp > 10s run the command and update the timestamp.
EDIT: Like this (with modification times instead):
TS_FILE="$HOME/.cache/your-app-lock"
if [[ ! -f "$TS_FILE" ]] || [[ "$(expr "$(date +%s)" - "$(stat -c %Y "$TS_FILE")")" -gt 10 ]]; then
touch "$TS_FILE"
echo "running"
fi
You’d replace the echo "running"
line with the part of the bash script you want to run only if it’s been 10 seconds since the last time the script was run, or whatever number of seconds you specify after the -gt
. If the bash script actually outputs a file as part of its normal operation then you could specify that file in the TS_FILE=
line; there would be no need to create a separate timestamp file (unless some other process could also modify that same file).
This doesn’t actually stop the bash script from running; it just prevents it from executing the part of the script that you don’t want executed too frequently. This could be very useful in a situation where without such protection, the too-frequent execution of the script might cause something undesirable to happen (such as getting locked out of an online site for hammering it with requests). Depending on the situation there may be other, perhaps even better ways to avoid this possibility, but in other cases this may indeed be the best approach.
Globbing and Regex: So Similar, So Different
Grepping is awesome, as long as you don’t glob it up! This article covers some grep and regex basics.
Source: Globbing and Regex: So Similar, So Different | Linux Journal
How to Remove Stuck Time Machine Backups from Mac Trash Due to System Integrity Protection Error
If you’re trying to remove a Time Machine backup from a drive and find that it’s stuck in the Mac Trash with a specific error message stating the trash can’t be emptied because “Some items in the Trash cannot be deleted because of System Integrity Protection”, then read on to learn how to resolve this particular Time Machine backup removal problem.
Source: How to Remove Stuck Time Machine Backups from Mac Trash Due to System Integrity Protection Error
How to convert .icns files to .png files in OS X
This brief tutorial will show you how to quickly and easily convert Mac OS X Icon files (.icns) to .png files.
Source: How to convert .icns files to .png files in OS X (Simple Help)
What Is SED and How Do You Use It?
Sed is a powerful command akin to the find and replace feature in most text editors. Find out what sed is and how you can use it to improve your efficiency.
Source: What Is SED and How Do You Use It? – Make Tech Easier
What Is GREP and How Do You Use It?
Grep is a small Unix program for finding matching patterns. Begun as a Unix program, it can be found on Linux as well as Mac and BSD. It can read just about any text, meaning it can read input from another commands, or it can open and look through files directly. Grep is insanely useful, especially for looking through directories from the command line.
Source: What Is GREP and How Do You Use It? – Make Tech Easier
Example syntax for Secure Copy (scp)
What is Secure Copy?
scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.
Source: Example syntax for Secure Copy (scp) (hypexr.org)
Understanding Linux Permissions
Linux is a multiuser operating system. In a multiuser environment, it is necessary to ensure that a user cannot access or modify files or directories that they arent supposed to. File permissions provide a protection mechanism for controlling access to files and directories.
Linux’s file security model is based on that of Unix. Each file or directory can be accessed or modified by the user who created it, or a group of users who have been given permission to do so. Permissions can also be defined for other users that do not belong to either of these two categories.
In this guide, we will go over how file permissions work in Linux for beginners. We’ll cover how you can view the permissions associated with files and directories and also how you can change them.
Source: Understanding Linux Permissions (Linux Academy)
Enpass Is The Free Cross-Platform Password Manager
Previously we covered KeePassXC password manager which is also free application. Here comes another password manager called Enpass, it is free and cross-platform available for Linux, Windows, Mac, Android, Blackberry, Windows Phone and iOS.
Source: Enpass Is The Free Cross-Platform Password Manager (NoobsLab)
Recent Comments