Skip to main content

Questions tagged [bash]

Bash is a free shell for Unix-like operating systems from the GNU Project.

Filter by
Sorted by
Tagged with
1 vote
2 answers
4k views

Script to auto execute creation of ssh tunnel

I'm a CS student, and still learning a lot of these things, and so please bear with me if I don't have a full grasp on what I'm trying here. I'm on a Mac, connecting to a linux machine. I can set up ...
0 votes
1 answer
54 views

How to transfer a file to a remote host using parallel + ssh?

I am writing scripts to poll a large number of remote hosts over ssh using gnu parallel. I copy the script to them, run it and get the results. Right now I'm using two bundles parallel + scp to ...
1 vote
1 answer
30 views

SSH from A through B to C, using private key on B

Schematic: ssh ssh A ------> B ------> C ^ ^ using A's using B's ssh key ssh key Preconditions: A is running ssh-agent A can access B B can access C A can't ...
0 votes
1 answer
24 views

How to detect even or odd minutes in bash script

I need to detect whether the current minutes are even or odd regardless of the time zone ! I tried this according to answers from several sites: #!/bin/bash n=$(date +"%M") r=`expr$n%2` if [...
1 vote
1 answer
5k views

How do I create an environment variable "openssl"

I know my question may sound stupid but there's some problem I've been fighting with for the last 2 days. I have a few versions of OpenSSL installed on Ubuntu server. The one which is desired is ...
0 votes
1 answer
34 views

exit code segment causes Bash prompt to freak out

My Bash prompt (based on mike kasberg's) generally works fine. But when I get an error code, and then write over to the next line, no newline is generated, so the text goes back over my previous ...
2 votes
2 answers
5k views

Alias CMD command from WSL2 shell

I'm running WSL2 on Windows 10, and I want to be able to run a CMD command from it without exiting the Linux shell. Specifically, I want to do: wmic diskdrive get Model,Manufacturer,Size,DeviceID,...
402 votes
21 answers
562k views

How do I detach a process from Terminal, entirely?

I use Tilda (drop-down terminal) on Ubuntu as my "command central" - pretty much the way others might use GNOME Do, Quicksilver or Launchy. However, I'm struggling with how to completely detach a ...
0 votes
2 answers
3k views

Delete pattern matching regex from sed capture group

I'm trying to remove all instances of '_(one number)' from certain strings in a file. So tig00000003_1 should become tig00000003 This is what my test file looks like: ##sequence-region tig00000001_732 ...
1 vote
0 answers
23 views

How to Identify and Terminate Idle tmux Sessions on a Debian Server

I have a Debian server with multiple tmux sessions running. Some of these sessions are idle and not running any active processes. How can I identify and terminate all tmux sessions that are not ...
1 vote
1 answer
18 views

Does bash support variable substitution in return statement?

Does bash support variable substitution in return statement? From man bash: return [n] Causes a function to stop executing and return the value specified by n to its caller. Is n allowed to be ...
0 votes
1 answer
3k views

Specify passphrase when invoking ssh?

I'm trying to run a remote command using SSH in a script. Host1 is connecting to Host2 to run a command. I've setup the public keys between the two hosts so I don't need to use a password to make the ...
2 votes
1 answer
58 views

Provide argument while starting a service using systemctl

I have a service installed on an old server and it is started using; service load-simulator start medium The value medium acts as a profile of sorts. It can have values like low, medium, high, and ...
6 votes
1 answer
4k views

Ignore certain changes in git diff

Is it possible to get a report from git diff or related commands that excludes a certain category of change? I've been asked to review a change where a huge number of files have undergone the ...
0 votes
1 answer
18 views

Font size issue with xterms started through icewm's hotkeys

Recently got a new laptop with 1920x1080 monitor instead of 1366x768 on old laptop. All my many xterms suddenly smaller and text illegible. After investigation, decided easiest solution was an alias ...
0 votes
1 answer
3k views

removing old BTRFS snapshots with bash

I'm trying to build my own little backup script, I want to use BTRFS snapshots and keep them for a while. Meanwhile, creating the snapshots is no longer a problem for me, but now I would like to ...
1 vote
1 answer
4k views

How do I run multiple scripts within a script, even if one script fails

I have a simple bash script that executes a number of other scripts … #/bin/bash … ./update_artifact1.sh $ARTIFACT_VERSION ./update_artifact2.sh $ARTIFACT_VERSION ./update_artifact3.sh $...
179 votes
23 answers
67k views

Add directory to $PATH if it's not already there

Has anybody written a bash function to add a directory to $PATH only if it's not already there? I typically add to PATH using something like: export PATH=/usr/local/mysql/bin:$PATH If I construct ...
489 votes
7 answers
260k views

What is the difference between executing a Bash script vs sourcing it?

What is the difference between executing a Bash script like A and sourcing a Bash script like B? A > ./myscript B > source myscript
1 vote
2 answers
5k views

How do I install ImageMagick for MinGW on Windows 7?

Well... I have already installed MinGW32 (I don't know the version - installed in a folder named Git 2.4.4.2) on Windows 7, and I want to install ImageMagick to run some scripts like the follow: echo &...
1 vote
1 answer
36 views

ssh -t host1 ssh host2 "cat < /tmp/test.txt" – file not found

I'm trying to run cat < /tmp/test.txt on remote host host2 through host1. The file /tmp/test.txt exists on host2. I try: # locally ssh -t host1 ssh host2 "cat < /tmp/test.txt" The ...
0 votes
2 answers
4k views

Copy shell configuration from one machine to another?

I've got login to another server where shell configurations are not like I would want. For example I don't see my username and CWD on prompt, and when I press arrow key, instead of giving last entered ...
6 votes
1 answer
949 views

cd <nonexistent_directory> in bash causes cd to different directory?

Ok, so I've been using Linux for 18 years and have never seen or heard of anything like this: starting-forth$ ls ch01/ ch02/ ch04/ ch05/ ch06/ text/ starting-forth$ cd ch07 # A directory I ...
1 vote
0 answers
77 views

How could I have VScode on Windows 10 with the default terminal changed to WSL2 Ubuntu-24.04 like a native linux distro?

I'm trying to have inside VScode for Windows 10 (Microsoft Windows [versão 10.0.19045.4474]) options to change the terminal from default to another one such WSL2 Ubuntu 24.04. I have installed ...
18 votes
6 answers
19k views

bash: execute command given in commandline and don't exit

how do I specifiy a command on the commmandline of bash which shall be executed once inside the new bash after reading ~/.bashrc -- But all this without letting bash exit after the command is finished?...
3 votes
2 answers
5k views

Monitor folder size

Is there a way to monitor and log folder size in Bash/Ubuntu? I'm running some computations and I need to know how much disk space they need. They may create some temporary folders for a few minutes/...
3 votes
2 answers
426 views

bash see if element inside array is inside a different array

I am trying to test to see if an element inside an array exists. A test case is array1=(a b c) array2=(c d e) for ((i=0; i < ${#array1[@]}; i++)); do if [[ ${array1[$i]} == "...
0 votes
2 answers
423 views

awk string replacement - properly escape '&' character

I am working on one of our applications to update the docker image from using static configs for each environment to a single template using dynamic variable insertion with awk. Our Dockerfile calls a ...
218 votes
9 answers
312k views

How can I find only the executable files under a certain directory in Linux?

How can I find only the executable files under a certain directory in Linux?
3 votes
2 answers
5k views

tcpdump output to file not working

I'm trying to write the results of tcpdump to a text file. I am not interested in saving a pcap file to use later, I just need exactly what tcpdump returns in plain text (the ips and timestamps of ...
0 votes
1 answer
25 views

Dealing with whitespaces in file names after git grep -l

I'm trying to run the script below and I'm struggling with pathspec error when the filename has whitespaces. I have already read some other posts around here, but since I am not an expert I was not ...
225 votes
26 answers
292k views

Bash scripting: test for empty directory

I want to test if a directory doesn't contain any files. If so, I will skip some processing. I tried the following: if [ ./* == "./*" ]; then echo "No new file" exit 1 fi That gives the ...
1 vote
2 answers
6k views

select columns on cat command

I use a file as a little db table. The content is like this: client1 john doe engineer cal client2 jane doe nurse ny client3 ali veli doctor ny I want to find ...
3 votes
2 answers
3k views

Is it possible to have dropdown autocomplete select options in ZSH or Bash?

Is it possible to have dropdown autocomplete select options in the terminal with ZSH or Bash as shown in the image below? Here the regions(i.e. ap-northeast-1, ap-northeast-1 etc) are predefined
17 votes
3 answers
22k views

How to force ls terminal command to show results in Bytes while I have set the default to ls -h in bash profile?

I am following the snippet here to improve my terminal command in Mac OSX. It sets the default value of ls results to human-readable by exporting alias ls='ls -GFh' to bash profile file. This is very ...
-1 votes
1 answer
44 views

Hide files and folders with same name

I ran into an issue where I had to restart my computer during a large extraction process involving many zip files :(. All the zip files contain a folder that has the name of the zip file (minus .zip) ...
149 votes
6 answers
258k views

How to prevent SSH from disconnecting if it's been idle for a while

I have a ssh connection to a machine which gets disconnected by that machine after 30 minutes of no user input. However, if I start something like top, the connection stays alive. Since this is a ...
0 votes
1 answer
4k views

Resolve "permission denied" when executing .sh files on WSL 2 via windows explorer

I'm using this method to have .sh files in Windows Explorer execute using bash.exe: "C:\Windows\System32\bash.exe" -c " \"./$(grep -oE '[^\\]+$' <<< '%L')\"; cd ~; bash;" This works fine ...
1 vote
1 answer
66 views

How to merge all mp3 files located in the same directory?

The command below used to work but stopped around ubuntu/kubuntu 20.04. ls *.mp3 | sed -e "s/\(.*\)/file '\1'/" | ffmpeg -protocol_whitelist 'file,pipe' -f concat -i - -c copy output.mp3 ...
798 votes
13 answers
855k views

What does 'source' do?

$ whatis source source: nothing appropriate. $ man source No manual entry for source $ source bash: source: filename argument required source: usage: source filename [arguments] It exists, and it is ...
2 votes
2 answers
5k views

Send JSON using curl from bash script when JSON path supplied as variable

I just cannot understand why all my attempts failing. I try to use curl to send POST request with json to specific url when a path to JSON defined as variable: #!/bin/sh JSON_TMP=/home/aaa/jsons/...
1 vote
1 answer
974 views

Loop record RTSP stream with VLC

I am able to save an RTSP stream to a .mp4 file using the following command: /usr/bin/vlc -vvv rtsp://stream_address --sout=file/mp4:/home/test-$(date +"%Y%m%d%H%M%S").mp4 --intf dummy --...
1 vote
0 answers
32 views

Why can’t I assign a requested address InspIRCd? “Reason: Cannot assign requested address”

I want to make an IRC server but when I run ./inspircd start it I get this. I turned off UFW and set up port forwarding, but nothing changes: Inspire Internet Relay Chat Server, compiled on Jun 8 ...
162 votes
10 answers
226k views

How can I do a recursive find and replace from the command line?

Using a shell like bash or zshell, how can I do a recursive 'find and replace'? In other words, I want to replace every occurrence of 'foo' with 'bar' in all files in this directory and its ...
76 votes
9 answers
209k views

How can I use a Bash-like shell on Windows?

I use Linux and a Mac, and I'll be teaching some command line stuff soon. What can I install on Windows to give me a terminal window most similar to a basic Mac/Linux Bash shell? I would like to ...
0 votes
1 answer
687 views

Change the color of the Intel NUC 11 Power LED from a running process

On an Intel NUC (model Intel NUC11TNHi7), Ubuntu 20 LTS is installed. I want to be able to use a process (such as a bash script, python, library, etc.) to control the button LED such as from systemd ...
0 votes
0 answers
31 views

Need Clang version at least 16

I am tried to compile the Apache Doris on macOS 13.3.1 follow by this document: https://doris.apache.org/docs/install/source-install/compilation-mac/. When I run the bash build.sh command, shows error ...
1 vote
1 answer
53 views

Bash prevent word splitting in array from command

I am using bash to get all of my directories with find . -maxdepth 1 -type d. I am then storing it in an array called selections. The issue is if a file has a space in it then i get some issues. When ...
0 votes
1 answer
68 views

How to do a Proximity text search, 2 + words?

What is a Linux terminal command to do a Proximity text search? Search a directory, recursively, for files that contain : 2 words or more within 99 characters of each other any order of above words. ...
4 votes
1 answer
4k views

Tab Auto-Completion in Mac OS X when using sftp in terminal

i have been getting very frustrated lately since the readline functionality has been removed from MacOSX and Tab Auto-Completion doesn't work anymore. So i was wondering if anyone knew a good ...

1
2 3 4 5
236