How to create log of all file modifications with timestamps?
Hi,
Bash newbie here. I'm trying to create a noscript that will create a log of all file modification operations done across my mac for a set time period (year ish). So it'll look something like
[01/02/23\] - fileA.txt OPENED
[01/02/23\] - fileA.txt MODIFIED
[01/06/23\] - fileB.txt DELETED
[01/15/23\] - fileA.txt DELETED
etc...
Not looking to be handed the answers. Just some guidance on where to look. An idea I had was to use the bash noscript to access the mac logs and filter by file operations, and then output those. But I can't find logs that have that file modification info.
https://redd.it/12i5v16
@r_bash
Hi,
Bash newbie here. I'm trying to create a noscript that will create a log of all file modification operations done across my mac for a set time period (year ish). So it'll look something like
[01/02/23\] - fileA.txt OPENED
[01/02/23\] - fileA.txt MODIFIED
[01/06/23\] - fileB.txt DELETED
[01/15/23\] - fileA.txt DELETED
etc...
Not looking to be handed the answers. Just some guidance on where to look. An idea I had was to use the bash noscript to access the mac logs and filter by file operations, and then output those. But I can't find logs that have that file modification info.
https://redd.it/12i5v16
@r_bash
Reddit
r/bash on Reddit: How to create log of all file modifications with timestamps?
Posted by u/hummus_k - 1 vote and 2 comments
How to add progress bar and log to this noscript?
https://raw.githubusercontent.com/mfn77/Post-Install/main/Post-Install.sh
I wrote a bash noscript for my post install configuration. I am definetely not an expert and this code probably is garbage but it works for me, at least it looks like it 's working. But I am wondering that can I add progress bar between user interactions and write a log file instead for normal terminal output? If I can how?
https://redd.it/12iizna
@r_bash
https://raw.githubusercontent.com/mfn77/Post-Install/main/Post-Install.sh
I wrote a bash noscript for my post install configuration. I am definetely not an expert and this code probably is garbage but it works for me, at least it looks like it 's working. But I am wondering that can I add progress bar between user interactions and write a log file instead for normal terminal output? If I can how?
https://redd.it/12iizna
@r_bash
rclone copy (or sync) with fzfI'm not sure if I've ever posted any of my code like this; it's usually only in some comment responding to someone that I do that
but this little bash noscript, barely 35 lines if you leave out the comments and the "help" text, seems interesting enough that someone might care to try it
the use case is when you want to run
rclone copy (or sync) but you'd like to (a) select what to copy using fzf, and (b) just as importantly, you want to copy multiple directories (or multiple files)this ability to select is especially useful if you're copying from a remote to a local directory
code is at https://github.com/xkcd386at/noscripts/blob/master/fclone if you want to take a look
https://redd.it/12ijnqh
@r_bash
GitHub
noscripts/fclone at master · xkcd386at/noscripts
various noscripts and tools. Contribute to xkcd386at/noscripts development by creating an account on GitHub.
Adding portions of strings in tab delimited file to another column
Hi,
I have a tab separated file (it's an .ALE file exported from Avid Media Composer). I am trying to add portions of one column's data into other columns on the same row. The second column in this file is a list of filenames. Each filename has specific information about the file which I'd like to add in the same row but under another column.
For example, I have the following columns: Name, Scene, Camera, Take
Name Scene Camera Take
302012_0017_2-33f_1b_b026.mov
302012_0016_2-33f_1a_a026.mov
302012_0019_2-33f_2a_a026.mov
302012_0024_2-33f_3c_c021.mov
302012_0020_2-33f_2b_b026.mov
302012_0018_2-33f_1c_c021.mov
302012_0022_2-33f_3a_a026.mov
302012_0023_2-33f_3b_b026.mov
302012_0021_2-33f_2c_c021.mov
In the first filename, 33f would be the Scene, 1b would be the Camera, and b026 would be the Take. On the command line, I can use the following to get each section one-by-one, changing the field of the last cut command for each section, but I'm also not sure how to iterate through the filename to get each part.
echo {302012_0017_2-33f_1b_b026.mov%.*} | cut -d - -f2 | cut -d _ -f1
Any help or pointers would be appreciated.
Thank you!
https://redd.it/12jcjug
@r_bash
Hi,
I have a tab separated file (it's an .ALE file exported from Avid Media Composer). I am trying to add portions of one column's data into other columns on the same row. The second column in this file is a list of filenames. Each filename has specific information about the file which I'd like to add in the same row but under another column.
For example, I have the following columns: Name, Scene, Camera, Take
Name Scene Camera Take
302012_0017_2-33f_1b_b026.mov
302012_0016_2-33f_1a_a026.mov
302012_0019_2-33f_2a_a026.mov
302012_0024_2-33f_3c_c021.mov
302012_0020_2-33f_2b_b026.mov
302012_0018_2-33f_1c_c021.mov
302012_0022_2-33f_3a_a026.mov
302012_0023_2-33f_3b_b026.mov
302012_0021_2-33f_2c_c021.mov
In the first filename, 33f would be the Scene, 1b would be the Camera, and b026 would be the Take. On the command line, I can use the following to get each section one-by-one, changing the field of the last cut command for each section, but I'm also not sure how to iterate through the filename to get each part.
echo {302012_0017_2-33f_1b_b026.mov%.*} | cut -d - -f2 | cut -d _ -f1
Any help or pointers would be appreciated.
Thank you!
https://redd.it/12jcjug
@r_bash
Reddit
r/bash on Reddit: Adding portions of strings in tab delimited file to another column
Posted by u/_aidsburger - No votes and 2 comments
I can't fathom what's wrong with this noscript. Feel like I'm missing something small but can't see what. Can anyone spot something?
Hello. I have the following noscript that scans recursively within directories for .mkv files and shows me those without subnoscripts. Everything about this seems to me that it *should* work, but when I run it I get
I first thought it could be a permissions issue, but even when running as root I get the same error. The noscript is of course executable and mkvmerge is indeed in my PATH. I'm a bit stumped! Thanks
​
https://redd.it/12jexov
@r_bash
Hello. I have the following noscript that scans recursively within directories for .mkv files and shows me those without subnoscripts. Everything about this seems to me that it *should* work, but when I run it I get
sh: line 5: : No such file or directory errors, regardless of which directory I use as $dir. There is also never any ouput file generated. Despite the warnings, I can hear the disk scanning the directories for some time, so it's doing *something*, just not what I wanted :DI first thought it could be a permissions issue, but even when running as root I get the same error. The noscript is of course executable and mkvmerge is indeed in my PATH. I'm a bit stumped! Thanks
​
#!/bin/bash# Set the directory to search for .mkv filesdir="/path/to/directory"# Set the output fileoutput_file="output.txt"# Find all .mkv files recursively in the directory and check if they have subnoscriptsfind "$dir" -type f -name "*.mkv" -exec sh -c 'for file do# Check if the file has subnoscriptsif ! mkvmerge -i "$file" | grep -q "subnoscripts"; then# Output the file name to the output fileecho "$file" >> "$output_file"fidone' sh {} +echo "Done. Output saved to $output_file."https://redd.it/12jexov
@r_bash
Reddit
r/bash on Reddit: I can't fathom what's wrong with this noscript. Feel like I'm missing something small but can't see what. Can anyone…
Posted by u/CheekyYoghurts - No votes and 7 comments
"what" -- A tool to get info about commands. I wrote it after I got fed up with how uninformative the standard tools like "type" and "which" can be, and how much digging you have to do to figure out problems.
https://github.com/wjandrea/what-bash
https://redd.it/12jqk01
@r_bash
https://github.com/wjandrea/what-bash
https://redd.it/12jqk01
@r_bash
GitHub
GitHub - wjandrea/what-bash: Get more info about a Bash command
Get more info about a Bash command. Contribute to wjandrea/what-bash development by creating an account on GitHub.
Why is trap handler not invoked immediately in this noscript
#!/bin/bash
cleanup() {
echo "Received SIGTERM signal. Cleaning up..."
exit 1
}
echo "Spawning child process..."
trap cleanup SIGTERM
sleep 10
echo $?
When I issue a SIGTERM after 2-3 seconds after invoking this process the cleanup is called AFTER 10 seconds. Shoulnd't the trap handler invoke immediately?
https://redd.it/12jqard
@r_bash
#!/bin/bash
cleanup() {
echo "Received SIGTERM signal. Cleaning up..."
exit 1
}
echo "Spawning child process..."
trap cleanup SIGTERM
sleep 10
echo $?
When I issue a SIGTERM after 2-3 seconds after invoking this process the cleanup is called AFTER 10 seconds. Shoulnd't the trap handler invoke immediately?
https://redd.it/12jqard
@r_bash
Reddit
r/bash on Reddit: Why is trap handler not invoked immediately in this noscript
Posted by u/ForeignCabinet2916 - No votes and 2 comments
bashelim collates a noscript with its sources (nested), and sends the result to stdout
Sometimes it is nice to collate all the noscripts that is at play,
in order to make it easier to inspect, or to share with someone
maybe after some final editing.
This noscript, is an adaption of the `soelim` noscript for collating
`troff` sources, for bash, it understands `.` and `source`, and also
nested files, and that cycles of nested files are bad!
This version doesn't read the path and looks for sources any other
place than in the current folder, tildes are expanded into the home-
folder however.
#!/bin/awk -f
# McUsr 2023 Mostly stolen from Jon Bently's m1.awk
# Vim licence
# bashelim instead of soelim V.0.0.0
# Collates the bashcript presented on the command line
# with all sourced files, for debugging purposes.
# Tildexpands any paths.but doesn't look through the path
# to find files without pathname besides the current folder.
BEGIN {
RS="\n"
hp=ENVIRON["HOME"]
}
function error(s) {
print "m1 error: " s | "cat 1>&2"; exit 1
}
function dofile(fname, savefile, savebuffer, newstring) {
if (fname in activefiles)
error("recursively reading file: " fname)
activefiles[fname] = 1
savefile = file; file = fname
savebuffer = buffer; buffer = ""
while (readline() != EOF) {
if (/^[ \t]*source[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else if (/^[ \t]*\.[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else
print $0
}
close(fname)
delete activefiles[fname]
file = savefile
buffer = savebuffer
}
# readline
#Put next input line into global string "buffer".
#Return "EOF" or "" (null string).
function readline( i, status) {
status = ""
if (buffer != "") {
i = index(buffer, "\n")
$0 = substr(buffer, 1, i-1)
buffer = substr(buffer, i+1)
} else {
# Hume: special case for non v10: if (file == "/dev/stdin")
if (getline <file <= 0)
status = EOF
}
# Hack: allow @Mname at start of line w/o closing @
if ($0 ~ /^@[A-Z][a-zA-Z0-9]*[ \t]*$/)
sub(/[ \t]*$/, "@")
return status
}
function dosubs(s, l, r, i, m) {
if (index(s, "@") == 0)
return s
l = "" # Left of current pos; ready for output
r = s # Right of current; unexamined at this time
while ((i = index(r, "@")) != 0) {
l = l substr(r, 1, i-1)
r = substr(r, i+1) # Currently scanning @
i = index(r, "@")
if (i == 0) {
l = l "@"
break
}
m = substr(r, 1, i-1)
r = substr(r, i+1)
if (m in symtab) {
r = symtab[m] r
} else {
l = l "@" m
r = "@" r
}
}
return l r
}
BEGIN {
EOF = "EOF"
if (ARGC == 1)
dofile("/dev/stdin")
else if (ARGC >= 2) {
for (i = 1; i < ARGC; i++)
dofile(ARGV[i])
} else
error("usage: m1 [fname...]")
}
# This noscript is excavated out of the M1.awk macro processor by Jon L. Bentley.
#M1 was documented in the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
#but may have been written earlier.
#.P
# This noscript was adapted from the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
# 131.191.66.141:8181/UNIX_BS/sedawk/examples/ch13/m1.pdf (download from
#<a href="http://lawker.googlecode.com/svn/fridge/share/pdf/m1.pdf">LAWKER</a>).
# Author Jon L. Bentley. (Of "Programming Pearls" fame.)
https://redd.it/12jv83a
@r_bash
Sometimes it is nice to collate all the noscripts that is at play,
in order to make it easier to inspect, or to share with someone
maybe after some final editing.
This noscript, is an adaption of the `soelim` noscript for collating
`troff` sources, for bash, it understands `.` and `source`, and also
nested files, and that cycles of nested files are bad!
This version doesn't read the path and looks for sources any other
place than in the current folder, tildes are expanded into the home-
folder however.
#!/bin/awk -f
# McUsr 2023 Mostly stolen from Jon Bently's m1.awk
# Vim licence
# bashelim instead of soelim V.0.0.0
# Collates the bashcript presented on the command line
# with all sourced files, for debugging purposes.
# Tildexpands any paths.but doesn't look through the path
# to find files without pathname besides the current folder.
BEGIN {
RS="\n"
hp=ENVIRON["HOME"]
}
function error(s) {
print "m1 error: " s | "cat 1>&2"; exit 1
}
function dofile(fname, savefile, savebuffer, newstring) {
if (fname in activefiles)
error("recursively reading file: " fname)
activefiles[fname] = 1
savefile = file; file = fname
savebuffer = buffer; buffer = ""
while (readline() != EOF) {
if (/^[ \t]*source[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else if (/^[ \t]*\.[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else
print $0
}
close(fname)
delete activefiles[fname]
file = savefile
buffer = savebuffer
}
# readline
#Put next input line into global string "buffer".
#Return "EOF" or "" (null string).
function readline( i, status) {
status = ""
if (buffer != "") {
i = index(buffer, "\n")
$0 = substr(buffer, 1, i-1)
buffer = substr(buffer, i+1)
} else {
# Hume: special case for non v10: if (file == "/dev/stdin")
if (getline <file <= 0)
status = EOF
}
# Hack: allow @Mname at start of line w/o closing @
if ($0 ~ /^@[A-Z][a-zA-Z0-9]*[ \t]*$/)
sub(/[ \t]*$/, "@")
return status
}
function dosubs(s, l, r, i, m) {
if (index(s, "@") == 0)
return s
l = "" # Left of current pos; ready for output
r = s # Right of current; unexamined at this time
while ((i = index(r, "@")) != 0) {
l = l substr(r, 1, i-1)
r = substr(r, i+1) # Currently scanning @
i = index(r, "@")
if (i == 0) {
l = l "@"
break
}
m = substr(r, 1, i-1)
r = substr(r, i+1)
if (m in symtab) {
r = symtab[m] r
} else {
l = l "@" m
r = "@" r
}
}
return l r
}
BEGIN {
EOF = "EOF"
if (ARGC == 1)
dofile("/dev/stdin")
else if (ARGC >= 2) {
for (i = 1; i < ARGC; i++)
dofile(ARGV[i])
} else
error("usage: m1 [fname...]")
}
# This noscript is excavated out of the M1.awk macro processor by Jon L. Bentley.
#M1 was documented in the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
#but may have been written earlier.
#.P
# This noscript was adapted from the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
# 131.191.66.141:8181/UNIX_BS/sedawk/examples/ch13/m1.pdf (download from
#<a href="http://lawker.googlecode.com/svn/fridge/share/pdf/m1.pdf">LAWKER</a>).
# Author Jon L. Bentley. (Of "Programming Pearls" fame.)
https://redd.it/12jv83a
@r_bash
New release of bkt, a subprocess caching utility
Hi all, I recently cut a new release of `bkt` with some additional functionality. Notably, it's now possible to include a file's last-modified time in the cache key, thereby invalidating the cache if the file changes.
Wait, what is
Another way I use
$ curl http://some.api/data/a | jq '.foo'
$ curl http://some.api/data/a | jq '.foo.bar'
$ curl http://some.api/data/b | jq '.foo.bar.baz'
Which is obviously wasteful and slow. You could write the output to a file and then pipe that to
Instead, using `bkt` ensures each request is only sent once and all subsequent calls return locally cached results:
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo'
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo.bar'
$ bkt --ttl=1d -- curl http://some.api/data/b | jq '.foo.bar.baz'
If you haven't used it before give it a spin! If you find it useful please share how you're using `bkt` so others can benefit :)
https://redd.it/12ke9i3
@r_bash
Hi all, I recently cut a new release of `bkt` with some additional functionality. Notably, it's now possible to include a file's last-modified time in the cache key, thereby invalidating the cache if the file changes.
Wait, what is
bkt?bkt is a subprocess caching utility you can use to persist a command's output so that subsequent invocations are fast. As an example, I use bkt heavily in my shell prompt to speed up the information it displays.Another way I use
bkt often is to simplify and speed up iterating on command pipelines that are slow to run. For example, if you're using jq to play around with a JSON response you might do something like this:$ curl http://some.api/data/a | jq '.foo'
$ curl http://some.api/data/a | jq '.foo.bar'
$ curl http://some.api/data/b | jq '.foo.bar.baz'
Which is obviously wasteful and slow. You could write the output to a file and then pipe that to
jq, but you often end up juggling multiple response files and it get's tedious quickly.Instead, using `bkt` ensures each request is only sent once and all subsequent calls return locally cached results:
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo'
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo.bar'
$ bkt --ttl=1d -- curl http://some.api/data/b | jq '.foo.bar.baz'
If you haven't used it before give it a spin! If you find it useful please share how you're using `bkt` so others can benefit :)
https://redd.it/12ke9i3
@r_bash
GitHub
Release 0.6.0 · dimo414/bkt
What's Changed
Support environment variables BKT_TTL, BKT_SCOPE, and BKT_CACHE_DIR as alternatives for flags --ttl, --scope, and --cache-dir, respectively (#15).
Added support for keying the c...
Support environment variables BKT_TTL, BKT_SCOPE, and BKT_CACHE_DIR as alternatives for flags --ttl, --scope, and --cache-dir, respectively (#15).
Added support for keying the c...
bash-hackers.org is now a parking domain
Hi,
i have just noticed bash-hackers.org is now a parking domain, narf. Does anybody have some insights what happened and if there is some new place for this very much appreciated resource?
> whois bash-hackers.org
Domain Name: bash-hackers.org
Registry Domain ID: 660cea3369e54dbe9ca037d2d1925eaa-LROR
Registrar WHOIS Server: http://whois.ionos.com
Registrar URL: https://www.ionos.com
Updated Date: 2023-04-13T05:09:00Z
Creation Date: 2007-04-13T04:46:21Z
Registry Expiry Date: 2024-04-13T04:46:21Z
Registrar: IONOS SE
https://redd.it/12klulf
@r_bash
Hi,
i have just noticed bash-hackers.org is now a parking domain, narf. Does anybody have some insights what happened and if there is some new place for this very much appreciated resource?
> whois bash-hackers.org
Domain Name: bash-hackers.org
Registry Domain ID: 660cea3369e54dbe9ca037d2d1925eaa-LROR
Registrar WHOIS Server: http://whois.ionos.com
Registrar URL: https://www.ionos.com
Updated Date: 2023-04-13T05:09:00Z
Creation Date: 2007-04-13T04:46:21Z
Registry Expiry Date: 2024-04-13T04:46:21Z
Registrar: IONOS SE
https://redd.it/12klulf
@r_bash
Passing a command with double quotes to a function
Hi, I'm writing a noscript to create thumbnails and see them as preview for different types of files.
The problematic part is with passing to
Does somebody knows if I'm passing those commands to
https://redd.it/12kwbq8
@r_bash
Hi, I'm writing a noscript to create thumbnails and see them as preview for different types of files.
#!/bin/sh
file="$1"
w="$2"
h="$3"
x="$4"
y="$5"
mkdir -p '/tmp/lf'
cache() {
cache="/tmp/lf/$(echo "$file" | tr '/' '%')"
[ ! -f "$cache" ] && "$@" && echo '[SUCCESS]'
kitten icat --silent --transfer-mode file --stdin no --place "${w}x${h}@${x}x${y}" "$cache" < /dev/null > /dev/tty
}
case "$(file -Lb --mime-type "$file")" in
application/json) jq -C "$file" ;;
application/octet-stream|video/*)
cache ffmpegthumbnailer -i "$file" -o "$cache.jpg" -s 0 -q 4 ;;
application/pdf)
cache pdftoppm -singlefile -jpeg "$file" "$cache" ;;
application/x-7z-compressed) 7z l -p "$file" ;;
application/x-tar) tar rf "$1" ;;
application/x-rar) unrar lt -p- "$file" ;;
application/zip) unzip -l "$file" ;;
image/*) kitten icat --silent --transfer-mode file --stdin no --place "${w}x${h}@${x}x${y}" "$file" < /dev/null > /dev/tty ;;
text/*) cat "$file" ;;
*) echo '----- File Type Classification -----' && file -Lb "$file" ;;
esac
exit 1
The problematic part is with passing to
cache the command to create a thumbnail like in the case of application/pdf. I see the message [SUCCESS] on screen but the files doesn't get created at all. In the case of video/* I don't even see the message on screen.Does somebody knows if I'm passing those commands to
cache the wrong way? (Also if there is any other suggestion on style please tell me)https://redd.it/12kwbq8
@r_bash
Reddit
r/bash on Reddit: Passing a command with double quotes to a function
Posted by u/sicr0 - No votes and 4 comments
Brackets in sh noscript.
Hi!
I can't understand the code some noscript added to my rc.local when setting up vpn.
what are the "()" brackets for and why adding "&" at the end of the block? Wouldn't sh go line by line anyway? Rest of the code are clear to me. Could you clarify it for me? googling bash/sh brackets is like looking for a needle in the haystack.
https://redd.it/12kyyqt
@r_bash
Hi!
I can't understand the code some noscript added to my rc.local when setting up vpn.
(sleep 15service ipsec restartservice xl2tpd restartecho 1 > /proc/sys/net/ipv4/ip_forward)&what are the "()" brackets for and why adding "&" at the end of the block? Wouldn't sh go line by line anyway? Rest of the code are clear to me. Could you clarify it for me? googling bash/sh brackets is like looking for a needle in the haystack.
https://redd.it/12kyyqt
@r_bash
Reddit
r/bash on Reddit: Brackets in sh noscript.
Posted by u/arturkwiatkowski - No votes and 2 comments
What happened with wiki.bash-hackers.org?
This site was a great guide for me, does anyone know what happened?, today I tried to check the page and it seems to be dead 😢
https://redd.it/12lmqoy
@r_bash
This site was a great guide for me, does anyone know what happened?, today I tried to check the page and it seems to be dead 😢
https://redd.it/12lmqoy
@r_bash
Reddit
r/bash on Reddit: What happened with wiki.bash-hackers.org?
Posted by u/urely - No votes and 2 comments
Need help as an absolute beginner on directories and files
Hi everyone. I have a class this semester which requires me to work with bash. We have a homework and unfortunately my course does not provide any helpful infos on how bash works. Here is my homework
Consider the following output from /usr/bin/tree -p | sed -E "s/(\\[d?)([rxw-\]+)/\\1/g":
.
|- [d\] bars
| |- [d\] baz
| | |- [\] corge
| |- [\] quuz
|- [d\] corge
| |- [d\] grault
| |- [d\] garply
| | |- [\] version
| |- [\] partitions
|- [d\] foo
| |- [\] quux
|- [\] fstab
|- [\]qux
|- [\] rumo
6 directories, 8 files
Create the same structure consisting of 6 directories and 8 files using only shell commands. Give all the commands to solve this task in the correct order. For the version, partitions, and fstab files, use the appropriate /proc/version, /proc/partitions, and /etc/fstab files. All other files should be empty.
From all the research i have done on the internet i came up with something like
mkdir root_.
mkdir root_./bar
mkdir root_./bar/baz
mkdir root_./corge
mkdir root_./corge/grault
mkdir root_./corge/grault/graply
mkdir root_./foo
touch root_./baz/corge.txt
touch root_./bar/quuz.txt
... and so on
Am I on the right path here? It could be compeletly different than what they are asking. Would be amazing if i could learn what am i supposed to do and maybe what to study.
All helps are appreciated thank you!
https://redd.it/12lrj2o
@r_bash
Hi everyone. I have a class this semester which requires me to work with bash. We have a homework and unfortunately my course does not provide any helpful infos on how bash works. Here is my homework
Consider the following output from /usr/bin/tree -p | sed -E "s/(\\[d?)([rxw-\]+)/\\1/g":
.
|- [d\] bars
| |- [d\] baz
| | |- [\] corge
| |- [\] quuz
|- [d\] corge
| |- [d\] grault
| |- [d\] garply
| | |- [\] version
| |- [\] partitions
|- [d\] foo
| |- [\] quux
|- [\] fstab
|- [\]qux
|- [\] rumo
6 directories, 8 files
Create the same structure consisting of 6 directories and 8 files using only shell commands. Give all the commands to solve this task in the correct order. For the version, partitions, and fstab files, use the appropriate /proc/version, /proc/partitions, and /etc/fstab files. All other files should be empty.
From all the research i have done on the internet i came up with something like
mkdir root_.
mkdir root_./bar
mkdir root_./bar/baz
mkdir root_./corge
mkdir root_./corge/grault
mkdir root_./corge/grault/graply
mkdir root_./foo
touch root_./baz/corge.txt
touch root_./bar/quuz.txt
... and so on
Am I on the right path here? It could be compeletly different than what they are asking. Would be amazing if i could learn what am i supposed to do and maybe what to study.
All helps are appreciated thank you!
https://redd.it/12lrj2o
@r_bash
Reddit
r/bash on Reddit: Need help as an absolute beginner on directories and files
Posted by u/StarsAreCute - No votes and no comments
Keyboard Shortcut won't execute noscripts and commands which are easily executable on terminal.
So, I installed a package called pix2tex. I wrote a noscript to run it and there also was a pre-written noscript which would launch a window as you can see here in this video
However, though the noscripts and commands run perfectly fine on terminal, they won't run when they are called with a custom shortcut that I assigned them in keyboard settings.
I recorded another video to demonstrate this issue. The noscript which is being executed is
Pix2tex, takes the screenshot, a.png and converts into latex. It's saved in a.tex and then it's copied. Unfortunately, when I try it with keyboard shortcut, it won't even be saved in a.tex (but it will be for terminal executed noscript).
~Edit: I do want to know the answer for future purposes, but for now anyway to run
https://redd.it/12lv6hs
@r_bash
So, I installed a package called pix2tex. I wrote a noscript to run it and there also was a pre-written noscript which would launch a window as you can see here in this video
However, though the noscripts and commands run perfectly fine on terminal, they won't run when they are called with a custom shortcut that I assigned them in keyboard settings.
I recorded another video to demonstrate this issue. The noscript which is being executed is
#!/bin/bash
xfce4-screenshooter --region --save /home/bob/Pictures/Screenshots/a.png
#only the xfce4-screenshooter command would be executed
pix2tex /home/bob/Pictures/Screenshots/a.png | sed 's/.*: //' > /home/bob/Pictures/Screenshots/a.tex
xclip -selection clipboard /home/bob/Pictures/Screenshots/a.tex
exit 0
Pix2tex, takes the screenshot, a.png and converts into latex. It's saved in a.tex and then it's copied. Unfortunately, when I try it with keyboard shortcut, it won't even be saved in a.tex (but it will be for terminal executed noscript).
~Edit: I do want to know the answer for future purposes, but for now anyway to run
latexocr gui without actually having to open the terminal would suffice, is there a way to use a shortcut to do the same job as I am doing in the first video?~https://redd.it/12lv6hs
@r_bash
Imgur
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users.
Is it possible to make zsh look like GitBash without appealing to OhMyZsh?
Hi everyone!
Nothing to add to the noscript, it speaks by itself, but to give you as much informations as possible I tell you what I did!
So, I recently switched to Mac. I'm studying web development and until now I used GitBash for windows. I immediately realized that zsh style was pretty different so I tried to modify it to make it look as close as possible like GitBash. I created a .zshrc file in my home directory and with vscode I did the following modifications PS1="%F{green}%n@%m%f %F{yellow}%1\~%f $ "
The problem is that there is a lot of stuff that I'd like to modify but I wasn't still able to figure out how yet. These are the main things that I'd like to achieve:
\-When I do 'ls' the directories are not listed in blue with the '/' symbol. I have to 'ls -F' to identify them as a directories (and of course they still miss the color).
\-I didn't do anything regarding git yet but I'd like to have the branch names between brackets and coloured in blue
\-In git bash I had the whole paths listed. For example I had \~/one/two/current-directory. Now I just have the current-directory listed. I have to 'pwd' to see the whole path.
\-Finally, in GitBash the prompt $ started in a new line.
I looked online and some people suggest ohmyzsh. I'd like to achieve these results with out it. I also did 'man ls' to see what it says about colours. It talks about CLICOLOR and LSCOLORS but I wasn't able to understand how to apply them to get the result yet.
Could you guys help me?
Thank you!
https://redd.it/12lz3kb
@r_bash
Hi everyone!
Nothing to add to the noscript, it speaks by itself, but to give you as much informations as possible I tell you what I did!
So, I recently switched to Mac. I'm studying web development and until now I used GitBash for windows. I immediately realized that zsh style was pretty different so I tried to modify it to make it look as close as possible like GitBash. I created a .zshrc file in my home directory and with vscode I did the following modifications PS1="%F{green}%n@%m%f %F{yellow}%1\~%f $ "
The problem is that there is a lot of stuff that I'd like to modify but I wasn't still able to figure out how yet. These are the main things that I'd like to achieve:
\-When I do 'ls' the directories are not listed in blue with the '/' symbol. I have to 'ls -F' to identify them as a directories (and of course they still miss the color).
\-I didn't do anything regarding git yet but I'd like to have the branch names between brackets and coloured in blue
\-In git bash I had the whole paths listed. For example I had \~/one/two/current-directory. Now I just have the current-directory listed. I have to 'pwd' to see the whole path.
\-Finally, in GitBash the prompt $ started in a new line.
I looked online and some people suggest ohmyzsh. I'd like to achieve these results with out it. I also did 'man ls' to see what it says about colours. It talks about CLICOLOR and LSCOLORS but I wasn't able to understand how to apply them to get the result yet.
Could you guys help me?
Thank you!
https://redd.it/12lz3kb
@r_bash
Reddit
r/bash on Reddit: Is it possible to make zsh look like GitBash without appealing to OhMyZsh?
Posted by u/91Flavio91 - No votes and 4 comments
a Bash noscript to eliminate lines in a delimited text file
Hello !
I have a file in a format like this, but bigger:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.02 33333 ddddd G 33333 ddddddd
0.01 44444 eeeee S 44444 eeeeeee
0.01 55555 fffff S1 55555 fffffff
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
I want to write a Bash noscript, that enters the file, and looks for a line that has G in the fourth column, if it's the case, it returns to the first column of that line and compares it to 0,04. If it's lower, the line should be deleted.
If a line that contains G is deleted, the noscript should look for the lines under, if they contain S or S1, or S2 they should be deleted also if they contain anything except that, no deletion is needed.
For that input, I should have an output like this:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
Thanks in advance! Have a good day.
https://redd.it/12lzfos
@r_bash
Hello !
I have a file in a format like this, but bigger:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.02 33333 ddddd G 33333 ddddddd
0.01 44444 eeeee S 44444 eeeeeee
0.01 55555 fffff S1 55555 fffffff
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
I want to write a Bash noscript, that enters the file, and looks for a line that has G in the fourth column, if it's the case, it returns to the first column of that line and compares it to 0,04. If it's lower, the line should be deleted.
If a line that contains G is deleted, the noscript should look for the lines under, if they contain S or S1, or S2 they should be deleted also if they contain anything except that, no deletion is needed.
For that input, I should have an output like this:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
Thanks in advance! Have a good day.
https://redd.it/12lzfos
@r_bash
Reddit
r/bash on Reddit: a Bash noscript to eliminate lines in a delimited text file
Posted by u/Quick_Repeat7033 - No votes and 3 comments
A new, unprecedented approach to the command line
https://asciinema.org/a/577630
https://redd.it/12m6fan
@r_bash
https://asciinema.org/a/577630
https://redd.it/12m6fan
@r_bash
asciinema.org
A novel approach to a merged mc/pure-shell like command line
A new approach to the command line: - it's a merge of Midnight Commander and command line, - … because everything is panelized, greppable and remembered, - you enter commands like ls, mv, cp, cat a...
How do I use double quotes in a remote ssh this way?
Normally I would set the today variable like this:
today="$(date +'%m-%d-%Y %H:%M:%S')"
Since I'm doing it on a remote server I am doing it this way:
ssh -T root@192.168.1.4 << EOL
today=\$(date +'%m-%d-%Y %H:%M:%S')
echo "\$today"
EOL
But what if I wanted to use the double quotes like normal? How would I do that remotely?
https://redd.it/12m9e3x
@r_bash
Normally I would set the today variable like this:
today="$(date +'%m-%d-%Y %H:%M:%S')"
Since I'm doing it on a remote server I am doing it this way:
ssh -T root@192.168.1.4 << EOL
today=\$(date +'%m-%d-%Y %H:%M:%S')
echo "\$today"
EOL
But what if I wanted to use the double quotes like normal? How would I do that remotely?
https://redd.it/12m9e3x
@r_bash
Reddit
r/bash on Reddit: How do I use double quotes in a remote ssh this way?
Posted by u/ztrz55 - No votes and no comments