Automatically upload files to usb when usb is plugged in
Wondering if there is a way so that when we plug in a USB it takes files from a certain directory and automatically uploads them to the USB? Does anyone have any ideas? Thank you!
https://redd.it/14wto8h
@r_bash
Wondering if there is a way so that when we plug in a USB it takes files from a certain directory and automatically uploads them to the USB? Does anyone have any ideas? Thank you!
https://redd.it/14wto8h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to repeat a command with parameters swapped?
If I run a command like:
to become #536 in the command history and later I want to run the same again with parameters swapped I can do:
Is there a way to say combine the word designators without repeating the command number?
I did not find a viable delimiter or any documentation going that deep.
​
​
​
https://redd.it/14iqv5q
@r_bash
If I run a command like:
specialcmd -ab Parm1 Parm2to become #536 in the command history and later I want to run the same again with parameters swapped I can do:
!536:0-1 !536:3 !536:2Is there a way to say combine the word designators without repeating the command number?
I did not find a viable delimiter or any documentation going that deep.
​
​
​
https://redd.it/14iqv5q
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Compile noscript for GCC 11.4.0, 12.3.0, & 13.1.0 Debian + Ubuntu
So I couldn't take waiting on gcc-13 on Debian Bookworm and Ubuntu Jammy so I went all out and made a noscript to compile the latest GCC 11, 12, and 13 versions.
I have tested it on Debian 12 and Ubuntu Jammy and it seems to work well for me.
Thought someone might appreciate this and want to give it a try as a strictly personal use or testing environment.
Be sure to read the build info and notes at the top of the noscript.
Also, there is a "debug" variable you can toggle "ON" or "OFF" to help troubleshoot any issues you might be having.
bash <(curl -sSL https://gcc.optimizethis.net)
GitHub Script
Cheers
https://redd.it/14iqn4z
@r_bash
So I couldn't take waiting on gcc-13 on Debian Bookworm and Ubuntu Jammy so I went all out and made a noscript to compile the latest GCC 11, 12, and 13 versions.
I have tested it on Debian 12 and Ubuntu Jammy and it seems to work well for me.
Thought someone might appreciate this and want to give it a try as a strictly personal use or testing environment.
Be sure to read the build info and notes at the top of the noscript.
Also, there is a "debug" variable you can toggle "ON" or "OFF" to help troubleshoot any issues you might be having.
bash <(curl -sSL https://gcc.optimizethis.net)
GitHub Script
Cheers
https://redd.it/14iqn4z
@r_bash
Can someone help me understand why I'm getting this 'invalid bytes error"?
I have a noscript:
#!/bin/bash
echo FLASK_SECRET_KEY=\""$(< /dev/random tr -dc _A-Z-a-z-0-9 | head -c${1:-25}; echo;)"\" > .env
if [ "$1" = "rebuild" ]
then
if [ "$2" = "all" ]
then
docker compose down
docker image rm app1
docker image rm app2
docker image rm app3
else
for image in "${@:2}"
do
docker compose down
docker image rm "$image"
done
fi
else
echo Invalid argument.
exit
fi
docker compose up -d
Everytime i run it, it runs perfectly but it always shows this error at the start:
head: invalid number of bytes: ‘rebuild’
​
https://redd.it/14i9196
@r_bash
I have a noscript:
#!/bin/bash
echo FLASK_SECRET_KEY=\""$(< /dev/random tr -dc _A-Z-a-z-0-9 | head -c${1:-25}; echo;)"\" > .env
if [ "$1" = "rebuild" ]
then
if [ "$2" = "all" ]
then
docker compose down
docker image rm app1
docker image rm app2
docker image rm app3
else
for image in "${@:2}"
do
docker compose down
docker image rm "$image"
done
fi
else
echo Invalid argument.
exit
fi
docker compose up -d
Everytime i run it, it runs perfectly but it always shows this error at the start:
head: invalid number of bytes: ‘rebuild’
​
https://redd.it/14i9196
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Set PS1 variable information as a bar.
I was curious if there was a way to move all the usual information from the prompt to a line at the top of the terminal.
I have seen some wonderful and amazing terminal prompts but I’m at the point where just having a status line with the information I need seems more appealing.
Thanks for the help.
https://redd.it/14hdd49
@r_bash
I was curious if there was a way to move all the usual information from the prompt to a line at the top of the terminal.
I have seen some wonderful and amazing terminal prompts but I’m at the point where just having a status line with the information I need seems more appealing.
Thanks for the help.
https://redd.it/14hdd49
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Remove combinatorial match from a two column file
I've been running into a brick wall with a particular issue - there's a two column tsv file roughly in format of:
A B
A C
A H
B A
B C
B E
C B
C H
And I'm trying to remove duplicates regardless of order - so the outcome would be:
A C
A H
B E
C H
Since 'A B' = 'B A', 'B C' = 'C B' and so forth. I've tried shuffling the orders with awk, but of course it didn't work. Any lead would be appreciated.
Thank you!
https://redd.it/14gsupf
@r_bash
I've been running into a brick wall with a particular issue - there's a two column tsv file roughly in format of:
A B
A C
A H
B A
B C
B E
C B
C H
And I'm trying to remove duplicates regardless of order - so the outcome would be:
A C
A H
B E
C H
Since 'A B' = 'B A', 'B C' = 'C B' and so forth. I've tried shuffling the orders with awk, but of course it didn't work. Any lead would be appreciated.
Thank you!
https://redd.it/14gsupf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Combine values from a list
I am trying to use jq to put a list on one array of values.
​
my input is this a newline separated inputs
name1
name2
name3
namex
​
I would like to have this output
names : [name1, name2, name3, namex\]
Thanks for any guidance on how to tackle this, I am new to jq
​
https://redd.it/14fkb6x
@r_bash
I am trying to use jq to put a list on one array of values.
​
my input is this a newline separated inputs
name1
name2
name3
namex
​
I would like to have this output
names : [name1, name2, name3, namex\]
Thanks for any guidance on how to tackle this, I am new to jq
​
https://redd.it/14fkb6x
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to rsync to directory underneath mountpoint?
I have a normal directory: \~/.mozilla/firefox
I then mount something to \~/.mozilla/firefox
How can I rsync data to the original \~/.mozilla/firefox directory found underneath the mountpoint?
I'm using a tmpfs to reduce disk writes from firefox but would like the option to rsync the data while the tmpfs is mounted.
No, I don't want to use profile-sync-daemon
https://redd.it/14xbr7r
@r_bash
I have a normal directory: \~/.mozilla/firefox
I then mount something to \~/.mozilla/firefox
How can I rsync data to the original \~/.mozilla/firefox directory found underneath the mountpoint?
I'm using a tmpfs to reduce disk writes from firefox but would like the option to rsync the data while the tmpfs is mounted.
No, I don't want to use profile-sync-daemon
https://redd.it/14xbr7r
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to substring a variable using another variable as length?
Hi, I have this piece of code:
length_seq=${#sequence}
fold_without_mfe=${#fold_result:0:$length_seq}
​
Where length_seq is the length of a genomic sequence, for example, 30. The fold_without_mfe variable is a simulation result, but it has a few more characters than I need, so I want to take only the firt 30 of this variable to match my sequence. I tried this but it throws me a bad substitution error, how can I approach this problem?
https://redd.it/14xlrwr
@r_bash
Hi, I have this piece of code:
length_seq=${#sequence}
fold_without_mfe=${#fold_result:0:$length_seq}
​
Where length_seq is the length of a genomic sequence, for example, 30. The fold_without_mfe variable is a simulation result, but it has a few more characters than I need, so I want to take only the firt 30 of this variable to match my sequence. I tried this but it throws me a bad substitution error, how can I approach this problem?
https://redd.it/14xlrwr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I get just part of the line in my text file?
I am running this command, trying to gather some data
grep -e "PROJECT" $(sudo find /path/to/dir/ -iname config) > projects.txt
and get a lot of output like this:
/path/to/dir/config/config-server.address:PROJECT="xyz";
All i want is the information between : and ;
I have tried using awk, but this gives me the same as no awk
grep -e "PROJECT" $(sudo find /path/to/dir/ -iname config | awk '{print $1}') > projects.txt
​
https://redd.it/14xriut
@r_bash
I am running this command, trying to gather some data
grep -e "PROJECT" $(sudo find /path/to/dir/ -iname config) > projects.txt
and get a lot of output like this:
/path/to/dir/config/config-server.address:PROJECT="xyz";
All i want is the information between : and ;
I have tried using awk, but this gives me the same as no awk
grep -e "PROJECT" $(sudo find /path/to/dir/ -iname config | awk '{print $1}') > projects.txt
​
https://redd.it/14xriut
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash grievances
At this moment I have a love/hate relationship with Bash. I write in it for years and I can say that I write it, with modesty, well.
I understand that Bash isn’t like modern programming language like Golang.
But from time to time when I want to refractor code or more structured setup I felt more and more that the language is in the way.
Trying to translate something like the composite design pattern to Bash was not possible because it is so simple as it can be. That it doesn’t have support like inheritance. Return a type from a function and not by declaring or print it. Passing a function as a argument to a function is not possible.
All the things that could make life/noscripting a little bit easier, it doesn’t have any support for it.
And Bash has made progress in the last ten years. Arrays is something that I frequently use. But the speed of developments is way too irritating slow. Just as the speed of the shell it’s self.
And yes. I acknowledge the existence Python and others. But as someone who comes to different companies where there is no knowledge of these modern languages (even in 2023), I have to do it with Bash.
https://redd.it/14xwui5
@r_bash
At this moment I have a love/hate relationship with Bash. I write in it for years and I can say that I write it, with modesty, well.
I understand that Bash isn’t like modern programming language like Golang.
But from time to time when I want to refractor code or more structured setup I felt more and more that the language is in the way.
Trying to translate something like the composite design pattern to Bash was not possible because it is so simple as it can be. That it doesn’t have support like inheritance. Return a type from a function and not by declaring or print it. Passing a function as a argument to a function is not possible.
All the things that could make life/noscripting a little bit easier, it doesn’t have any support for it.
And Bash has made progress in the last ten years. Arrays is something that I frequently use. But the speed of developments is way too irritating slow. Just as the speed of the shell it’s self.
And yes. I acknowledge the existence Python and others. But as someone who comes to different companies where there is no knowledge of these modern languages (even in 2023), I have to do it with Bash.
https://redd.it/14xwui5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I find files from a list without the extension?
I'm working on a personal project. I have 2 folders:
/JPG
/RAW
Each folder should contain files with identical filenames but with different extensions (they will always be either .jpg or .rw2)
For example:
/JPG/image1.jpg
/JPG/image2.jpg
/RAW/image1.rw2
/RAW/image2.rw2
Now there are some instances where a file only exists in one folder, but not the other.
I have identified these files and placed them into a list within a .txt file using the below command:
comm -3 <(print -lr JPG/*(:t:r)) <(print -lr RAW/*(:t:r)) > differences.txt
When I cat this file, I can see all the files which only belong to one of the folders. For example:
cat differences.txt
image7
image36
image49
​
My next goal is to move these files into a new folder. But I'm not sure how. As you can see, the extensions were removed/excluded when they were outputted to "difference.txt"
I was thinking maybe I should use the find command and input a list but that doesn't seem to be possible. I've tried a few noscripts I found on stack overflow but to no avail.
Please could somebody point me in the right direction?
https://redd.it/14y0v6i
@r_bash
I'm working on a personal project. I have 2 folders:
/JPG
/RAW
Each folder should contain files with identical filenames but with different extensions (they will always be either .jpg or .rw2)
For example:
/JPG/image1.jpg
/JPG/image2.jpg
/RAW/image1.rw2
/RAW/image2.rw2
Now there are some instances where a file only exists in one folder, but not the other.
I have identified these files and placed them into a list within a .txt file using the below command:
comm -3 <(print -lr JPG/*(:t:r)) <(print -lr RAW/*(:t:r)) > differences.txt
When I cat this file, I can see all the files which only belong to one of the folders. For example:
cat differences.txt
image7
image36
image49
​
My next goal is to move these files into a new folder. But I'm not sure how. As you can see, the extensions were removed/excluded when they were outputted to "difference.txt"
I was thinking maybe I should use the find command and input a list but that doesn't seem to be possible. I've tried a few noscripts I found on stack overflow but to no avail.
Please could somebody point me in the right direction?
https://redd.it/14y0v6i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Need help with a one-liner for renaming files.
I have folders of files that start with a year, but need the year on the end in parentheses.
main/folder1/1999 - file1.txt
main/folder2/2000 - file02.log
rename to:
main/folder1/file1 (1999).txt
main/folder2/file02 (2000).log
I don't know enough to knock this out quickly, anybody give me a hand?
Obviously doesn't need to be a one-liner, just seems like it should be pretty simple with the right knowledge.
https://redd.it/14yjick
@r_bash
I have folders of files that start with a year, but need the year on the end in parentheses.
main/folder1/1999 - file1.txt
main/folder2/2000 - file02.log
rename to:
main/folder1/file1 (1999).txt
main/folder2/file02 (2000).log
I don't know enough to knock this out quickly, anybody give me a hand?
Obviously doesn't need to be a one-liner, just seems like it should be pretty simple with the right knowledge.
https://redd.it/14yjick
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Searching for multiple strings within a list
Hello - I have the following noscript
>\# Get list of images with specified tag for downloading
tags=$(aws ecr --region ${SOURCE_REGION} list-images --registry-id ${SOURCE_AWS_ACCOUNT_ID} --repository-name ${REPOSITORY_NAME} | jq -r 'map(.[\] | .imageTag) | join(" ")')
list=$(for tag in $tags; do
if [[ $tag == "release"* \]\]; then
echo "$tag"
fi
done)
is it possible to add more filters and add them to the $tag variable? So what if I had something like
> if [[ $tag == "release"* \]\] && [[ $tag == "testing"* \]\] ; then
basically, I'm trying to match and extract multiple strings from a list and then pass those filtered results further down the noscript. Help much appreciated!
https://redd.it/14yna3b
@r_bash
Hello - I have the following noscript
>\# Get list of images with specified tag for downloading
tags=$(aws ecr --region ${SOURCE_REGION} list-images --registry-id ${SOURCE_AWS_ACCOUNT_ID} --repository-name ${REPOSITORY_NAME} | jq -r 'map(.[\] | .imageTag) | join(" ")')
list=$(for tag in $tags; do
if [[ $tag == "release"* \]\]; then
echo "$tag"
fi
done)
is it possible to add more filters and add them to the $tag variable? So what if I had something like
> if [[ $tag == "release"* \]\] && [[ $tag == "testing"* \]\] ; then
basically, I'm trying to match and extract multiple strings from a list and then pass those filtered results further down the noscript. Help much appreciated!
https://redd.it/14yna3b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How does bash, and other shells, figure out the correct environment variables?
If I use the env command I see that bash and zsh both have figured out the correct TERM, HOME, LANG and XDG... variables. Where does the shell look to find the value of this variables?
https://redd.it/14zbo8z
@r_bash
If I use the env command I see that bash and zsh both have figured out the correct TERM, HOME, LANG and XDG... variables. Where does the shell look to find the value of this variables?
https://redd.it/14zbo8z
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
C++ Build Error Handling
Hi, I wrote a .sh that catches an error if the
https://redd.it/14zpptp
@r_bash
Hi, I wrote a .sh that catches an error if the
make command fail, but it happens only when the make execution ends. So I just look at the return. I was wondering if it is possible to catch error during the compilation time. I hope to be clearhttps://redd.it/14zpptp
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
su into account, from root, and get password prompt
Realize this is a weird situation, but far as I can tell, this is the only way out of the problem.
Alright, I have an extremely odd situation. I need to su to a user account but have it ask for the password, and I need to do it from root. lol.
So what I found was, I can be root, su to the user account (no password prompt), then I can su from the user into itself, and a password is prompted.
I tried something like
sudo -u account echo "password" | sudo -S -u account echo ""
but it didn't seem to work. it appears I can't just sudo, I have to actually su.
So I'm wondering if I can use expect, but it's not working either (likely my ignorance as to how expect works)
As root:
sudo -u account expect -c 'spawn su account;expect Password:;send "sekritPassword\\n";send "whoami\\n";send "exit\\n"'
Doesn't seem to do what I would _expect_. Har har.
Anyone think of a way to do this?
https://redd.it/14zsqp8
@r_bash
Realize this is a weird situation, but far as I can tell, this is the only way out of the problem.
Alright, I have an extremely odd situation. I need to su to a user account but have it ask for the password, and I need to do it from root. lol.
So what I found was, I can be root, su to the user account (no password prompt), then I can su from the user into itself, and a password is prompted.
I tried something like
sudo -u account echo "password" | sudo -S -u account echo ""
but it didn't seem to work. it appears I can't just sudo, I have to actually su.
So I'm wondering if I can use expect, but it's not working either (likely my ignorance as to how expect works)
As root:
sudo -u account expect -c 'spawn su account;expect Password:;send "sekritPassword\\n";send "whoami\\n";send "exit\\n"'
Doesn't seem to do what I would _expect_. Har har.
Anyone think of a way to do this?
https://redd.it/14zsqp8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why printf over echo? (noob question)
I regularly come across comments in which it's recommended to rather use printf than echo in shell noscripts. I wonder why that is.
And in this regard: would it be worth the time and energy to replace all the echos in a working noscript with printf?
And last question: do people usually get annoyed when you use both, echo and printf in one noscripts (a published noscript that is)?
https://redd.it/1519wby
@r_bash
I regularly come across comments in which it's recommended to rather use printf than echo in shell noscripts. I wonder why that is.
And in this regard: would it be worth the time and energy to replace all the echos in a working noscript with printf?
And last question: do people usually get annoyed when you use both, echo and printf in one noscripts (a published noscript that is)?
https://redd.it/1519wby
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash Script To Retrieve Saved Wi-Fi Passwords On Rooted Android Devices
https://github.com/oxou/android-get-saved-wifi-passwords
https://redd.it/151b189
@r_bash
https://github.com/oxou/android-get-saved-wifi-passwords
https://redd.it/151b189
@r_bash
GitHub
GitHub - oxou/android-get-saved-wifi-passwords: Bash Script To Retrieve Saved Wi-Fi Passwords On Rooted Android Devices
Bash Script To Retrieve Saved Wi-Fi Passwords On Rooted Android Devices - GitHub - oxou/android-get-saved-wifi-passwords: Bash Script To Retrieve Saved Wi-Fi Passwords On Rooted Android Devices
Kali Linux Can some one help me with these command? i am studying for isaca cybersecurity fundamentals and i can not find out how did the instructor find out "The nefarious file was being executed at server boot time and re-spawning if shutdown".
​
https://preview.redd.it/woidolmv7kcb1.png?width=613&format=png&auto=webp&s=e58040e9c76b4964bed35d8e452caa15b20ce572
​
https://preview.redd.it/7hverdnw7kcb1.png?width=1920&format=png&auto=webp&s=cf6acaa7457ee399b8036a2fe68be82096ed1825
​
on the third page it says \\" The nefarious file was being executed at server boot time and respawning if shutdown\\". How did he come to that conclusion?
​
https://preview.redd.it/5jhjpocy7kcb1.png?width=1236&format=png&auto=webp&s=53b58246ef4863a870d7b65a421f9790a0c12110
https://redd.it/15288qj
@r_bash
​
https://preview.redd.it/woidolmv7kcb1.png?width=613&format=png&auto=webp&s=e58040e9c76b4964bed35d8e452caa15b20ce572
​
https://preview.redd.it/7hverdnw7kcb1.png?width=1920&format=png&auto=webp&s=cf6acaa7457ee399b8036a2fe68be82096ed1825
​
on the third page it says \\" The nefarious file was being executed at server boot time and respawning if shutdown\\". How did he come to that conclusion?
​
https://preview.redd.it/5jhjpocy7kcb1.png?width=1236&format=png&auto=webp&s=53b58246ef4863a870d7b65a421f9790a0c12110
https://redd.it/15288qj
@r_bash