Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

Filter by
Sorted by
Tagged with
0
votes
0answers
29 views

How to recover an overwritten file with cat command?

I made my files by cat -n crib.txt then when I did cat > crib.txt and Ctrl+D it all got overwritten. Can you plz help how to recover the overwritten file? What is the backup file restore command, ...
0
votes
1answer
25 views

Adding and counting input in bash

How do you make a bash script to add and then count how many numbers the user inputted? I cant see how to do variables since the user can potentially enter infinite inputs. If the user enters nothing ...
0
votes
1answer
11 views

Tar each top level directory separately

How can I create tarballs for a series of directories? E.g. if my home directory contains directories called “one” “two” “three” and “four” how can I create one.tar.gz two.tar.gz three.tar.gz and four....
0
votes
1answer
18 views

No such file or directory Error while using find or ls -al in unix directory

I am trying to find reason behind this happening and also a solution . When I try to run below command on Unix directory which has around 16 files and also one of the application process which keeps ...
0
votes
1answer
22 views

Get first line of string with line breaks

I'm trying to improve a bash script to extract a quote from the string generated when you copy something from iBooks (Apple book reading software). I know we can extract the first line of a file via ...
0
votes
0answers
10 views

Script question for BIND entry removal/add

I need to or want to delete BIND DNS entries that are in File1 that match A records in File2. If the DNS entry has multiple records associated to it in File2, those need to remove too. File1 car....
2
votes
0answers
49 views

Possible reasons for redirection to /dev/null suddenly breaking

I am using a Bash loop to monitor a process that I spawned, and after some time (hours/days) it sometimes produces an "operation not permitted" error trying to redirect output to /dev/null: /...
1
vote
2answers
62 views

echo redirect appends a spaces

could someone help me? I am trying to create a lot of files, but when I try to write to it with echo it adds a space and single quotes, for example: ' (here is the space) file.tmp' ' file1.tmp' ' ...
0
votes
1answer
25 views

Calling a function from terminal without export from sources file [duplicate]

Have added a number of functions which I source from my .bashrc. For instance, I use export -f calc I also have another function usage_calc where I comment out the export call # export -f usage_calc ...
-1
votes
1answer
20 views

function validating numeric values used with conditional

I have a function that validates numeric values, and want to use it in if statements. num=3 if numeric -I "$num" then printf '%s\n' "$num is numeric integer" fi Is there a way ...
3
votes
4answers
161 views

Can I Indirect the argument list to a bash script from a text file?

I'm thinking of something like ls @files.lst doing what ls [contents of files.lst] would do, globbing included. I think I'm remembering the above syntax, (at-sign, filename) from somewhere (maybe an ...
0
votes
1answer
20 views

how to prevent Syn-flood on a specific port with iptables?

I was Trying Recently to prevent Syn-Flood on a server on port 2421 , only one TCP-Connection is permitted per second , and the Existing Connections should not be stopped ,so i have used the following ...
0
votes
2answers
50 views

Using ls on many files results in error "bash: Argument list too long" [duplicate]

I am trying to populate a txt with all the names of .fits files from a folder with this command: ls *.fits > output_all.txt The number of .fits files in the folder is >330k and I get the error ...
-1
votes
0answers
16 views

Unable to Install mysql-server using dnf in Ansible on CentOS

I need to install mysql-server and the chosen method was using Ansible as it streamlines the process. But while installing it, I have been finding this issue which I have not been able to debug. My ...
1
vote
0answers
11 views

Referencing a time-style definition does not work [duplicate]

For a given file one may issue the bash command: ls -la --full-time --time-style long-iso --time-style=+"%Y-%m-%d %H:%M:%S" file This works of course. I have a larger script in which I ...
0
votes
2answers
35 views

shortcut command for printf with a specific format string

I want to use a shortcut command for printf with a specific format string, and came up with the following. local PF="printf %s\n" $PF "Some Text" It does the job, but wonder if ...
0
votes
1answer
32 views

Why Apache 2.4.41 installed on my system

Three days ago I noticed that my localhost on port 80 was occupied by an Apache server. I uninstalled it and started to find out if it was a sign of some kind of malware. I found out from the logs: I ...
2
votes
3answers
310 views

How to grep full words between spaces

For example, I have a string like this: 1341 5415 fdad. Command grep -E "(^|\s)[1-9]{1,5}($|\s)" -o will give only 1341, but I want to get 1341 and 5415. How can I do this?
1
vote
2answers
25 views

Cleanup script with find - No such file or directory

I am using the following to find and delete a group of sub volumes: find /.snapshots/ -name backup-* -type d -exec btrfs subvolume delete {} \; It works, but I get unexpected output from find: Delete ...
1
vote
1answer
30 views

Problem with utilizing a "while loop" and subsequently processing data in a bash script

I'm trying to create a script, which should read a video folder and create a list of video files to be processed by ffprobe to identify the codec. Videos NOT processed with a specific codec (in this ...
0
votes
1answer
23 views

git-bash window title issue

I started a git-bash window, and type following commands : git-bash ~$ echo $BASH_VERSION 4.4.23(1)-release git-bash ~$ type cd cd is a shell builtin git-bash ~$ cd tmp git-bash ~/tmp$ # Change of ...
0
votes
1answer
16 views

Setting Preferred Applications from the terminal (CentOS 7)

I'm making a script which uses xfconf-query to change various system settings on mass, however I'm unsure how to set my Preferred Applications in the same manner. I looked into the mimeapps.list file ...
5
votes
1answer
99 views

Bash background execution not returning

I am trying to write a script that has the purpose to parallelize an execution (a program that creates some files) running the processes in background and, when all commands in the for loop are done, ...
0
votes
0answers
12 views

How to make "man set" show bash's set instead of set in postgresql? [duplicate]

In my LXTermianl man set PostgreSQL 13.5 Documentation SET(7) NAME SET - change a run-time parameter If i type help set: ...
1
vote
2answers
32 views

How can I remove multi-line (Lua) comments in a bash script?

I'm writing a bash script where I need to strip comments from Lua files, which are formatted: --like this foo="bar" --or like this --[[ or like this ]] --[[ or like this ]] I ...
0
votes
2answers
24 views

How can backup and then modify a file with sed?

I need to overwrite some configs on many servers at once and I want to modify the origianl config file while creating a backup, can all that be done with sed, just for curiosity? Someone was ...
0
votes
1answer
30 views

Linux script to see what packages were not downloaded from a folder

I am trying to figure a way to solve an issue I am facing. I have an offline standalone server at work. It is not connected to the internet and we have to manually patch the server each month. We ...
0
votes
0answers
17 views

Remove Exact Strings From a File [duplicate]

How do I remove exact strings using sed, tr or awk {98406c4acbf0f57b3ccbc923a6d507f422d9bd8656398f53433e}HTTP/1.0 200 OK What I want to remove is HTTP/1.0 200 OK I tried to do sed but there is a ...
0
votes
1answer
16 views

Aligning name/value pairs from a prior command's ouput

The hostnamectl command outputs some nicely formatted info that includes your hostname, but it doesn't include the fully qualified domain name (FQDN), as does hostname -f. As a means of learning more ...
17
votes
2answers
946 views

How do you convert a string to bash echo?

I would like to echo this on completion of my bash script. /\_/\ ( o.o ) > ^ < I have tried the following but all return errors. echo /\\_/\\\n\( o.o \)\n > ^ < echo \/\\_\/\\\r\n( o.o ...
-4
votes
1answer
49 views

ok so im trying to read the output of a command

echo -en "date: " read sdate mdate="date -d '${sdate} 00:00:00' +%s " udate(){ $mdate } udate output root@Xanarchy:/cnc# bash date date: 01-01-2000 date: extra operand ‘+%s’ Try ...
1
vote
1answer
33 views

Don't understand why pgrep doesn't work in a bash script with sudo

I'm trying to detect whether the zoom program is running. I also need sudo privileges in my bash script to install it with dpkg. If I use pgrep -f "zoom" >/dev/null 2>&1, the ...
0
votes
2answers
23 views

Can the list if the variable used in a for loop be made up of variables themselves?

I'm trying to create a script where pretty much things got sorted out earlier in it and I'm left with the booleans I need stored in variables. I just need to run them through one last loop and I'm ...
0
votes
1answer
22 views

Is it alright to add a disk size monitoring script for NAGIOS, using loop?

I have a process that gets sizes for all disks on server, writes it into a file like this # cat disksize DISK# ACTUAL WARNING CRITICAL disk1 12 20 30 disk2 45 60 75 first row of ...
0
votes
0answers
32 views

shell command with unexpected quotes

I am running a script it has: ... echo 3:${WRITE_TIME} WRITE_TIME_QUOTES=\"${WRITE_TIME}\" echo 4:${WRITE_TIME_QUOTES} ${ADDR_BEELINE}/beeline ... --hivevar write_time=${WRITE_TIME_QUOTES} ;...
6
votes
1answer
248 views

Why can't the extended glob */ be negated with !(*/)?

In bash, if we activate the extglob shell option, we can do fancy stuff like negating a glob (from man bash): If the extglob shell option is enabled using the shopt builtin, sev‐ eral extended ...
1
vote
3answers
26 views

Pass special wildcards characters to set command

I would like to set variables with a special sign "*" using the "set" command $ Q='A * B' $ set -- $Q $ echo "$1 $2 $3" I expect "A * B" Of course, it does not ...
0
votes
0answers
39 views

Bash - Can I run a for loop in a one liner? [duplicate]

In PowerShell I can pipe output into a for-each loop like so: C:> ls C:\ | % { $_.Length / 1024 } Note that ls is an alias for Get-ChildItem and % is an alias for ForEach-Object. Is there a ...
-2
votes
2answers
60 views

bash error syntax random number

My assignement is to show a random number (od -vAn -N4 -tu4 < /dev/urandom) between two numbers in read. I don't understand why there are syntax error when I check the min value exception and with ...
1
vote
1answer
27 views

Copy a file from one directory to another while incrementing the filename in bash

I have a script that copies a file from one directory to another indefinitely (until cancelled) as a test. I am trying to write a bash script that takes file.xml, copies it to a directory, but ...
0
votes
1answer
40 views

Creating a file in the Linux home area: can't touch this [duplicate]

I want to write some text to a file in my home area, which doesn't yet exist. I've stored the name of the file I want to create in a variable. I want to use this variable to echo some text and ...
0
votes
0answers
15 views

How to solve spawn bin/zsh ENOENT?

I am installing dependencies for a project using NodeJS, Angular and Node-Sass, all goes ok when installing both Node and Angular, but when installing Node-saas i got an error: npm ERR! code ...
0
votes
0answers
12 views

Hotplug - USB tty device links related to usb port

I have 5 devices with the same Vendor and Product ID (12d1/1c05/102) - GSM modems. Each device generates 3 interfaces ttyUSB0, ttyUSB1, ttyUSB2 in the DEV directory. It needs to create its own ...
-1
votes
2answers
34 views

Gnu Recutils: error while loading shared libraries: librec.so.1

Have installed Gnu Recutils but I am getting recsel -P File /home/hagbard/Opstk/bin/gungadin-1.0/logs/molniya-5978-T08:09:55.669018347.org recsel: error while loading shared libraries: librec.so.1: ...
-2
votes
1answer
48 views

Composing bash conditions utilising both (( )) and [[ ]]

Can one compose a condition utilising both (( )) and [[ ]] ? if (( i == cnt )) && [[ "$invoke" ]]; then
1
vote
1answer
33 views

How to play sound on command?

Every time i write g++ main.cpp, i want to play a sound.mp3. But the problem is if i add alias like this alias g++='play sound.mp3 | g++ -std=c++17' I have to wait till sound.mp3 is over. How to make ...
1
vote
1answer
46 views

Why does `grep` seem to give slightly different results with a plain `ls` command? [duplicate]

I have a directory with some files - mkdir _tmpmm touch a1 b2 c3 d4 ls # a1 b2 c3 d4 When I grep for a on the output of ls, I see only the file a1 - although the ls output is showing 4 files on ...
0
votes
0answers
36 views

How can I replace a word with another word in a whole hierarchy of files

I have a hierarchy of files and two words: word1 and word2. In this hierarchy of files, some of them can contain word1. I want to replace every occurrence of word1 with word2. It is possible using a ...
4
votes
1answer
379 views

Ensure only one instance of script is running?

Code: if [[ "`pidof -x $(basename $0) -o %PPID`" ]]; then exit; fi Original source of the code: https://forum.rclone.org/t/continuous-syncing/12377/2 I don't understand how this code inside ...
0
votes
5answers
44 views

create custom globally accessible directory like the home directory

I would like to create a projects directory which I can access from everywhere like the home directory (~). E.g. the following should work (no matter the cwd) cd projects ls projects/project1 Any ...

1
2 3 4 5
463