All Questions
1,570 questions
3
votes
7
answers
918
views
How to list only the last name.partXXX.rar file?
In Linux in a folder, without subfolders, there are many files like this scheme.
I list them with ls -1.
1yBWVnZCx8CoPrGIG.part01.rar
1yBWVnZCx8CoPrGIG.part02.rar
1yBWVnZCx8CoPrGIG.part03.rar
...
0
votes
7
answers
2k
views
Is it possible to protect a bash script against a hostile environment?
Bash allows to export read-only variables and functions to the environment.
Also, when a bash script is run, Bash sources the file BASH_ENV was set to, unless invoked with -p.
How do you protect ...
9
votes
7
answers
969
views
Check if multiple files exist on a remote server
I am writing a script that locates a special type of file on my system and i want to check if those files are also present on a remote machine.
So to test a single file I use:
ssh -T user@host [[ -f /...
0
votes
3
answers
244
views
What are the secure ways to use credentials in bash scripts?
I have a third-party service. Its API and credentials let me scrape service data on my local Linux machine. I want to use this API inside a bash script and launch it via cron, but I don't want to ...
-1
votes
3
answers
171
views
How do I test the existence of a directory accessible only as root?
if [ -d directory ]; then
echo "directory exists";
else
echo "does not exist";
fi
tests for the existence of directory by virtue of the -d test.
Does the -d test return the ...
0
votes
0
answers
58
views
Why are quotation marks and backslashes not working as expected in variables? [duplicate]
I'm trying to pass a command through to ffmpeg, but I'm struggling to get it to work with spaces in the name.
I've tried this:
filters="-vf subtitles='$filename.$format':force_style=Fontsize=24&...
4
votes
2
answers
575
views
Bash script: performance comparison of file reading methods
I'm trying to find the "right" way to read files line-by-line.
I have been using for for line in $(cat "$FILE"); do for a while, and I really enjoy its clearness.
I know that while ...
0
votes
1
answer
207
views
SLURM error and output files with custom variable name
I'd like my log files to be named after a variable. Since this isn't possible:
#SBATCH --output some_software.${var}.out
#SBATCH --error some_software.${var}.err
I came across this work around but ...
0
votes
0
answers
94
views
Opening Vim under script(1) breaks output. Can Vim detect script?
Opening vim while recording with script causes script to go wild (my screen starts filling up with a bunch of crap, some of which says "script", and I also believe it is colored neon green).
...
-3
votes
1
answer
133
views
Creating in Linux files in GB or MB range by various size by read a file [closed]
In Linux with Bash, there is the File numbers_in_one_line.
In this file there is only one line with several numbers, all separated by spaces.
These numbers are the value in bytes for creating files ...
0
votes
1
answer
97
views
How to create splittet random files and join them with dmsetup
In Linux in Bash, there is a script, a part of the script is this
while true ; do
echo
awk -v x=$(<"$TEMPDIR"size_container_in_byte) -v n=$(<"$TEMPDIR"parts) 'BEGIN{...
-7
votes
2
answers
138
views
How can I pick random items from a list, but some more often than others, in a Bash config file? [closed]
In Linux, using Bash, I have two scripts:
script.sh is the main script, and
script_config.sh is the configuration for script.sh.
In script.sh, I do source script_config.sh to load all the config ...
1
vote
1
answer
87
views
How can a bash script determine how it was started? [duplicate]
I am running various scripts on Debian 12.X currently with the following bash:
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
I have the following methods/options to execute the script.
...
0
votes
2
answers
142
views
Bash script, execute while command isnt outputting value
I'm trying to write a bash script (very new to writing them btw) on a Linux system, and I basically want it to execute a command every say 5 seconds while another command isn't outputting a value.
So ...
-3
votes
1
answer
57
views
Rename files, remove the first four signs [duplicate]
There are many files in this format:
IMG_20240717_191421.jpg
IMG_20240620_165358_BURST001_COVER.jpg
IMG_20240624_173513_2.jpg
how can they renamed in Linux in Bash to:
20240717_191421.jpg
...