New answers tagged

0 votes

Why am I getting an error in my Bash script?

Seems like you are using single quotes in the for command as well as the wrapping quotes. So try this instead: for file in "curl –connect-timeout 10 http://$DASHCAM_IP/blackvue_vod.cgi | sed 's/^...
0 votes

How to truncate the streaming output of a redirect?

Solution At the moment I have genrtr > genrtr.log and with a cron I tried to use > genrtr.log but it doesn't work. This approach can easily be fixed by using genrtr >> … instead of ...
0 votes

Fix powerline-shell bash prompt (mode: 'compatible' or mode: 'patched')

I got this working with mode: patched (ref ~/.config/powerline-shell/config.json below) on my Debian 11 system... Specific commands... sudo apt-get install fonts-powerline fonts-hack powerline pip ...
0 votes

Is there a way to extract subtitles from an MKV while maintaining the original format?

The answer by Rotem inspired me and gave me the technique, so I figured out a simpler way to do this and thought I would share it. with ffprobe using PowerShell, we use ffprobe to get the information ...
0 votes

How to extract specific data from the table?

I've written a bash script to do this, but to work with all sorts of commands as inputs. Here's the script: #!/bin/bash # Flags - to avoid potential conflicts when the labels are numbers # 1st # -n =...
  • 109
0 votes

Remove the lines before and after the exact match - linux

To find and delete the "private = 192.168.1.1" line and the two lines before and one line after it, you can use the following commands: # Set the file path file_path="/etc/test/host....
  • 1
-1 votes

How do I run "yum -y update" from Bash Script?

Change #!/usr/bin/ to #!/bin/bash or #!/bin/sh.
0 votes
Accepted

Changing bash PS1 colors ruins bash command line

As pynexj indicated, you need braces. However, the tput is probably nullifying more than you expect. You should keep it simple with the basic escape sequence. Also you have "[40m" in your ...
0 votes

How can I restart a process only if it fails but not if it exits normally (or with certain return codes)?

Addition to @Nathan.Eilisha Shiraini solution, taking into account Emulating a do-while loop in Bash #!/bin/bash while : ; do myprogram [[ $? -ne 0 ]] || break done
0 votes

How to stop a Bash script with the space bar?

If you don't need the stopwatch, after all, you just want to know the time it took in the end anyway, you can use: time read -r -n 1 it'll give you an output like: time read -r -n 1 real 1m30....
0 votes

Is it possible to `tail -f` the output of `dmesg`?

On macOS, you can use the command log to watch logs on the command line. Use log -? or just log for help. It is a very good command line alternative to the GUI app /Applications/Utilities/Console.app. ...
  • 1
0 votes

How to remove duplicated files in a directory?

There is a beautiful solution on https://stackoverflow.com/questions/57736996/how-to-remove-duplicate-files-in-linux/57737192#57737192: md5sum prime-* | awk 'n[$1]++' | cut -d " " -f 3- | ...
0 votes

Remove duplicate files by comparing them with MD5 RECURSIVELY

There is a beautiful solution on https://stackoverflow.com/questions/57736996/how-to-remove-duplicate-files-in-linux/57737192#57737192: md5sum prime-* | awk 'n[$1]++' | cut -d " " -f 3- | ...
0 votes

PATH env only valid for user creating this entry?

If you put PATH="/opt/poetry/bin:$PATH", it will add /opt/poetry/bin to the beginning of the PATH. Basically, the statement says "set PATH to /opt/poetry/bin:, followed by the content ...
  • 1,973
2 votes

Does htop have a bug in the display of process status and memory consumption?

S means interruptible sleep (waiting for an event to complete). CPU consumption is reported over a time period, and 'S' may be the status at the end of that time. Processes can change between Running ...
  • 424k
1 vote
Accepted

Does htop have a bug in the display of process status and memory consumption?

I noticed that htop showed certain process as consuming CPU, but yet were marked S in the State column (the S column)...which meant that the processes were sleeping or idle, but I know they were not ...
  • 393k
2 votes

Shell script in Mac Automator won't work with folders

Your first problem is the variable assignment in the loop. Let's say I have files. I made it with touch file\ with\ space{001..010}.txt and touch file{001..010}.txt file with space001.txt file with ...
0 votes

Script to Find and Resample Audio via FFMPEG Fails on Files with double quotes

This is because of how GNU parallel parses {} (or {.} etc.) in shell code. Normally it's wrong to embed {} in shell code and no quoting within the shell code can help, one can always find a possible ...
0 votes

How can I watch a windows folder from my Ubuntu VM know which file has changed?

For people like me who can't use inotifywait because it doesn't work when the files are on windows, I just found someone who made another version with polling, and it works! inotifywait-polling by ...
0 votes

Shell script in Mac Automator won't work with folders

By longstanding Unix convention, all options (i.e. command-modifiers that begin with a hyphen or two, like -v or --verbose) are expected to go before all positional arguments (like the list of ...
  • 98.5k
0 votes

bash save history without exit

I have tmux sessions that run for days and I would like their histories saved, but a simple history -a will jumble up different histories together when using multiple terminals simultaneously. An ...
0 votes

Running command in new bash shell with --rcfile and -c

Running an interactive bash -i is not a good solution, it's declaring a terminal TTY when maybe (probably) there's no terminal, as most people want a their bash -c command to run batch processed, ...
  • 101
0 votes

LD_LIBRARY_PATH unset by screen

Another way to keep the LD_LIBRARY_PATH variable is to run a command inside screen as follows: screen -dmLS compile bash -lc "make -j12"
0 votes
Accepted

How to send post request to a discord webhook via CMD

You have to put \ before every ", otherwise the " ends the string and causes a error. For example, the command that I used in the original post would look like this curl -i -H "Accept: ...
1 vote

Startup script for Rock 4 SE running Debian

Have a look at https://www.freedesktop.org/software/systemd/man/user@.service.html A short and simple solution is to add a User=%I After the [Service] Also a script should work without the sh prefix,...
  • 215
10 votes
Accepted

sending print string command to remote machine

You will need to setup SSH key based authentication so that you do not need to enter a password. On the client machine, run the following to copy your current user's publickey to the server's ...
  • 2,682
0 votes
Accepted

How can I create a symbolic link of a file in another directory with relative path?

If I cd into host dir or docker dir and execute ln -s model.epoch<n>.tlt model.tlt, I have a link that's valid inside the docker container and in the host machine The link target has no ...
  • 393k
0 votes

Retain \n as plain text instead of new line in bash script

Two sed's action can help you. $ cat file.txt abc=123 def=456 ghi=789 sed -z 's/\n/\\n/g; s/..$//' file.txt abc=123\ndef=456\nghi=789 First change newline to characters "\n", second remove ...
0 votes

Run bash scripts without typing the file extension the right way

As @uSlacr points out, there are three steps. You may run this .BAT file in an administrative command prompt to do them :: Make .sh and .bash files executable without extension :: Append .sh to ...
  • 139
0 votes

youtube-dl changing the format output of %(upload_date)s

There is no way to change it in youtube-dl, but you can use its more advanced fork yt-dlp and use the following output format: %(upload_date>%Y-%m-%d)s Working example: youtube-dl -f 'bestvideo[...
1 vote

Bash 4.3 Substring Negative Length on OS X

It is possible to cut at the end dynamically by using the length as input to calculate. ${STR:0:${#STR}-2} The -2 is the negative amount.
0 votes
Accepted

What is the difference between “base64 -b0” in macOS versions prior to macOS 13 (Ventura) and “base64 -i” in macOS 13 (Ventura)?

Will answer my own question. Two “gotchas” grabbed me here and hopefully this answer will help someone in a similar position in the future: The -b0 needs to be set to -b 0 nowadays. The -i is now ...
0 votes

Linux: rename file but keep extension?

I did not understand how to use the rename example. However I wrote my own bash script, which takes the original file name with its extension and the new name without extension: # trans_file_extension:...
0 votes

iTerm2: Alt-Dot functionality with Cmd-Dot

iTerm2 > Settings > Profiles > Keys > Left Option key > Esc+
  • 1,719
0 votes

Equivalent to ^D (in bash) for cmd.exe?

Windows Terminal now lets you choose what keyboard shortcut you want for "close tab". I'd recommend switching to that.
  • 139
0 votes
Accepted

how can I convert svg xml code to image, using bash script in linux

Based on this answer you can use inkscape to make svg to png # Inkscape v1.0+ inkscape -w 1024 -h 1024 input.svg -o output.png # Inkscape older than v1.0 inkscape -z -w 1024 -h 1024 input.svg -e ...
  • 3,831
1 vote

When running `rm -rf`, is it possible to exclude certain subdirectories?

Another option: Check the output of env ls -d -1 space/* | grep -E -v 'var_opt|var_log' If that looks like the list of files/folders you want to delete, use env ls -d -1 space/* | grep -E -v 'var_opt|...
  • 216
0 votes

Get output logs of previous command in ZSH

What am I missing here? Checking your code with ShellCheck – shell script analysis tool: $ shellcheck myscript   Line 2: LAST_OUTPUT_LOG_FILE="~/zero.log"                       ^-- SC2088 (...
  • 147k
0 votes

Git mergetool vimdiff diff3 view changed showing only “LOCAL” files

Like @Ingo's answer said, this is a bug in Git 2.37; it is fixed in Git 2.38, so upgrading to that version will solve the issue too.
  • 1
1 vote

Remove the lines before and after the exact match - linux

Solution with sed sed ' : start /\n.*\n.*\n/ b ready N b start : ready s_.*\n.*\nprivate = 192\.168\.1\.1\n.*__ /./ P D ' /etc/test/host.conf Explanation For multi-line operations in sed, a scheme ...
1 vote

Remove the lines before and after the exact match - linux

Attempt with a bash script and a circular buffer (array) of 4 lines: #!/bin/bash lines=() while IFS=$'\n' read -r line ; do # accumulate up to 4 lines in an array lines+=("$line") ...
  • 1,189
1 vote

Why is my git bash (mingw64) running a nonsense command when using the -c option?

Fixed the issue. Not sure if this will ever be of use to anyone else, but I will post my findings. In my windows environment variables I had mistakenly set the BASH_ENV to the path of the bash exe ...
  • 11
2 votes
Accepted

Git Log of a particular file from a particular commit only

According to man git-log, this can be done by specifying the two commits you are comparing between, separated by an ellipsis ... You can specify the commits with HEAD~ notation, or use the commit hash....
0 votes

Setting environment variables in bash script doesn't work?

Background There are few things to explain. Each process has its own environment. The environment contains zero or more environment variables. Each variable is a value (a string) associated to a name (...
2 votes

Setting environment variables in bash script doesn't work?

For setting environment variables, as distinct from local script variables, use the export command like this: export GIT_AUTHOR_DATE=$THE_TIME For more information see : Defining a Bash Variable ...
  • 424k
-1 votes

Bash: Find folder containing two files

comm -12 <(find -name '*.ext1' -printf '%h\n' | sort -u) <(find -name '*.ext2' -printf '%h\n' | sort -u)
1 vote
Accepted

Separate file path from command in Bash under WSL2

The prompt is set through the shell in use. By default, this is Bash in most any WSL distribution. The prompt that you see is also typically configured by the distribution itself. For instance, ...
1 vote
Accepted

Is there a way to extract subtitles from an MKV while maintaining the original format?

We may use FFprobe for getting the subtitles codec name, and apply the extracted subtitles file extension accordingly. The sample batch file is based on the following answer. Assume MKV file name is ...
  • 930
1 vote
Accepted

Starting ssh-agent from a script for use in multiple scripts (invoked by git)

Environment variables are only inherited "down" – the eval $(ssh-agent) has no way to make them persist outside of the /bin/bash process that's running this particular script. So if the ...
  • 393k
0 votes

FFMPEG MultiPlex all video's to all audio's

Ok, so finally remembered what the programming argument/logic was called that i was trying to do here NESTED so i googled nested batch arguments and tested it (it is working) I did have to change ...

Top 50 recent answers are included