Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
Tag: bash
Bash script to delete all but N files when sorted alphabetically
It’s hard to explain in the title. I have a bash script that runs daily to backup one folder into a zip file. The zip files are named worldYYYYMMDD.zip with YYYYMMDD being the date of backup. What I want to do is delete all but the 5 most recent backups. Sorting the files alphabetically will list the oldest ones first,
extracting unique values between 2 sets/files
Working in linux/shell env, how can I accomplish the following: text file 1 contains: text file 2 contains: I need to extract the entries in file 2 which are not in file 1. So ‘6’ and ‘7’ in this example. How do I do this from the command line? many thanks! Answer Explanation of how the code works: If we’re
How can I show the wget progress bar only? [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
How do you find the original user through multiple sudo and su commands?
When running a script via sudo or su I want to get the original user. This should happen regardless of multiple sudo or su runs inside of each other and specifically sudo su -. Answer Results: Use who am i | awk ‘{print $1}’ OR logname as no other methods are guaranteed. Logged in as self: Normal sudo: sudo su
Generate a value to reflect the average brightness of an image
I need to determine if an image is above a certain brightness. Using a scale of 0 – 255 I want to generate a value within this range to reflect the image brightness. i.e. a white image is 255 and a black image is 0. All this needs to take place via a bash script I am building up at
How can I format my grep output to show line numbers at the end of the line, and also the hit count?
I’m using grep to match string in a file. Here is an example file: grep -i null myfile.txt returns How can I return matched lines together with their line numbers like this: I know -c returns total matched lines, but I don’t how to format it properly to add total null count in front, and I don’t know how to
How to sort files into folders by filetype on bash (with ‘file’ command)?
I have thousands of files without extensions after recovery (mostly pictures). I need to sort them into separate folders by filetype (folders must be created during sort process). I can determine filetype in linux using “file” command. Does somebody have bash script for it? For example: Initial dir contains files: 001, 002, 003, 004. After sorting should be 3 dirs:
Using sed to get an env var from /proc/*/environ weirdness with x00
I’m trying to grovel through some other processes environment to get a specific env var. So I’ve been trying a sed command like: sed -n “s/x00ENV_VAR_NAME=([^x00]*)x00/1/p” /proc/pid/environ But I’m getting as output the full environ file. If I replace the 1 with just a static string, I get that string plus the entire environ file: sed -n “s/x00ENV_VAR_NAME=([^x00]*)x00/BLAHBLAH/p” /proc/pid/environ I
Retrieve plain text script from compiled bash script
Some time ago, i wrote some bash scripts for my school. I thought it would be very clever to ‘protect’ them, so i compiled them with shc into a binary file. Some weeks later, i lost the uncompiled scripts and now i have only my binarys left. Is there a way to retrieve the scripts back from the shc generated