New answers tagged

2

You would need to use sudo, because you are trying to modify the root file system / and your user isn't the owner of those files. Now, either you are joking around or you've been tricked / taken by someone online. -- This command would recursively delete all files in /, meaning you would wipe your OS and all files along with it. -- Not a command you should ...


2

When you ran find . -name '*.sh' you were in /home, but ~ is your home directory, /home/administrateur, not /home. So find ~ ... will only find files under /home/administrateur, not files under /home outside /home/administrateur.


-2

var1=$(awk '{a[++i]=$0}/#/{for(x=NR-1;x<NR;x++)print a[x]}' file.txt | awk '{print $NF}') var2=$(awk '/#/{x=NR+1}(NR==x){print $NF}' file.txt) sed -i "s/#/$var3/g" file.txt sed -i "s/\*/Cindy:Ed/g" file.txt output cat file.txt line person age 1 Adam 45 2 Bob 50 3 Cindy 47 4 Cindy:Ed 48 5 ...


1

On MacOS, cp --attributes-only or chmod --reference won't work. A solution for MacOS is to first install coreutils using brew install coreutils then use the coreutils's version of cp command, that is gcp: gcp --attributes-only --archive sourcefile destfile This will copy the ownership and attributes while preserving destfile's content and filename.


0

No need for big 3rd-party packages, or kooky new languages, and no need to fork an entire shell and interpreter for every line of stdout that comes your way. I'm an adult -- my interpreter is the CPU: /* * Redirect stdin to stdout, prepending a millisecond-precision * Unix timestamp to each line. */ #include <stdio.h> #include <sys/time.h> ...


3

$ cat tst.awk $2 == "*" { buf[++bufSz] = $0 next } bufSz > 0 { split(prev,p) rng = p[2] ":" $2 val = ($3 + p[3]) / 2 for (i=1; i<=bufSz; i++) { split(buf[i],flds) print (prev == "" ? buf[i] : flds[1] OFS rng OFS val) } bufSz = 0 } { print prev = $0 } END { for (i=...


3

With awk: #if a previous line with proper IP has been read oldip != "" { #i is counter for consecutive invalid lines i=0 #if IP is set, just print and go to next record if ($2!="*") { print ; oldip=$2 ; oldlat=$3 ; next } #otherwise get following line and increase counter else { #getline exit status => fails for ...


1

Add the following to your ~/.bashrc: function mktouch() { mkdir -p "$(dirname "$1")" && touch "$1" } Then reload bash then use it like mktouch your/path/file.txt.


0

Are you running this with bash, or with zsh? You've tagged this with bash, but your question mentions a zsh error. Like ksh, bash arrays start from zero. zsh arrays start from one (unless you have the KSH_ARRAYS variable set). See man zshparam and search for Array Subscripts


2

First of all, for GUI notifications, you can use notify-send. The "standard" way to run it is notify-send <summary> [body], and you could change the expiration time, the urgency, category etc. Now, in order to notify of every new line that appears in some log file, you could run something such as: tail -n -0 -f <log file> | while read ...


2

The [!...] pattern matches a single character that is not part of the ... set within the square brackets. This is a filename globbing pattern used by POSIX shells. The [^...] pattern works the same, but is a POSIX regular expression. This pattern is not generally portable to other shells as a filename globbing pattern, but the bash shell recognizes it and ...


1

If you need to create a user, it's easy. You can run this command: sudo useradd <username> --password <password> to create your user. If you want to keep it secret, I don't have much familiarity with this option, but try adding --system to the end, as suggested in the comments. Hope this helps!


7

As pointed out by others already, the find utility does not by default support extended globbing patterns as found in the bash shell and others (originally inherited from the ksh shell). You may use the bash shell to perform these tests though: find /some/path -type f \ -exec bash -O extglob -c '[[ ${1##*/} == prefix?(_suffix).zip ]]' bash {} \; \ -...


7

find only uses “basic” shell patterns, as described in POSIX. It doesn’t support extglob-style globs (even though the GNU implementation says it uses fnmatch, and the GNU C library’s implementation of fnmatch supports extended patterns). If you’re using GNU find, you can filter using regular expressions instead; see the relevant section of the documentation ...


3

The other answer mentioned regular expressions, which made me think of an obvious solution: using -regex instead of -name: find /some/path -type f -regex '.*/prefix\(_suffix\)?\.zip' I suspect it might be slower, but maybe not so much.


3

What you want to achieve seems to be outputting the content of the shell variable $ip after assigning the output of the ping command to it - that means, you want to first assign command output to a variable, and then print the resulting variable content on the console. However, you are using the pipe (|) operator to link these two commands. This is the wrong ...


5

For bash, unless you already have history datetime stamping enabled with the HISTTIMEFORMAT variable, you can't do that. Going forward you can enable timestamping by providing a value for HISTTIMEFORMAT. For example, HISTTIMEFORMAT=$'%Y-%m-%d %H:%M:%S\t' The documentation (man bash) writes, HISTTIMEFORMAT If this variable is set and not null, its value is ...


0

It is due to quoting. GNU Parallel is not part of the shell so every input has to be quoted if it would be interpreted by the shell. And since you call GNU Parallel from a shell (which will interpret input) and GNU Parallel starts a shell (that interprets the input) it has to be quoted twice, unless you use -q, which you can only use if you need the full ...


1

Command 1-3 did not suspend your ssh session, they suspended your remote shell, from which there is probably no recovery. The shell on the remote server can not suspend your ssh session. That has to be done from the local end using the keyboard by typing enter ~ ctrl+z. This key sequence is read by the local ssh directly and it commands it to suspend itself....


0

That's because grep will continue to look into that folder after the creation of myfile. You can simply give it another path: grep -E -r -o -n r"%}(.*){%" > /tmp/myfile


1

If you are using GNU bash (as your login shell on Linux) and if you want some environment variable FOO to be set for every user to string value bar you could add in file /etc/bash.bashrc (near the end) a few lines like: # to be added in /etc/bash.bashrc export FOO=bar See §6.2 Bash startup files for more. Of course, you need root permission to edit (once, ...


0

Let the shell interpret input data at your own risk, of course, but that is what you're asking for help to do so: $ echo first > foolbar $ echo second > foo\*bar $ cat $(awk 'BEGIN{print "foo*bar"}') second first The above assumes the list of arguments to cat won't exceed the shells max args length, see https://stackoverflow.com/a/4185165/...


1

Googling for /usr/sbin/mkdict (because it's really interesting that it's in sbin and not bin) finds this bugreport No man pages found for /usr/sbin/mkdict & /usr/sbin/packer. These binaries are part of the cracklib-dicts RPM package, but no man pages are included in RPM package. from Red Hat, which fits Oracle Linux. Cracklib does seem to have a Python ...


-1

echo "He said to me, \"I've seen that.\"" Seems to me to be the simplest way to return the text: He said to me, "I've seen that."


0

As long as there are no special shell characters in $base and $fa_pattern this should work: base=/mnt/datagenetique/ANALYSIS/Infectiologie/COVID-WGS/Analyse/ fa_pattern=_*_ds*/consensus/*.consensus_hard_masked_sequence.fa # Generate one file per pattern cat input.csv | parallel --colsep , eval cat $base/{2}_*/dragen-covidseq/{1}$fa_pattern '>' {1}.fa #...


1

Here's a convoluted way: root_test=$( sudo su -l -c 'printf "%s\n" "$test"' ) or, assuming root's shell is bash: eval "$(sudo su -l -c 'declare -p test')" Either way, you need to become root, in root's login environment, to access the variable's value.


0

If you want to expand the * characters as shell glob characters (wildcards) you have to pass them to a program that will do this, e.g. to a shell. Assuming that the fields of the input file do not contain other characters that have a special meaning for the shell, you can try (1): awk -F, 'NR>0 {print "cat /mnt/datagenetique/ANALYSIS/Infectiologie/...


-3

Regarding the statement mawk ... therefore not represent integers larger than 2^31-1 (i.e., 2147483647.) in the answer by @they: this statement is false. You absolutely can read in and print out hex up to double-precision unsigned integer limit, aka 253-1 : echo '0x1234BEEF9CAFE7' \ \ | mawk '{ CONVFMT=OFMT="%.20g"; print a=+( ...


0

For zsh I was able to achieve the desired result by running the command compctl -M '' 'm:{a-zA-Z}={A-Za-z}' Upon doing that, I was able to cd into directories without using the same casing as their names. If you want to be permanent (not just for the session) just add it to your .zprofile in your home directory. That worked for me as well. Hope this helps.


0

You can do this using ffmpeg: ffmpeg -y -i layer2.gif -i layer1.png -filter_complex [0]overlay=x=0:y=0[out] -map [out] -map 0:a? mergedLayers.gif -y flag says to overwrite output files without asking. So if you already have a file named mergedLayers.gif it will get overwritten when this command is run. -i flag is the input url (in this case just a file name)....


0

is it possible to install full chrome os through kvm on linux ? Yes. Its a Linux with an android-style userland and a chrome-heavy UI. and where can I get the full .iso file or the img of chrome os? https://chromium.googlesource.com/chromiumos/docs/+/HEAD/cros_vm.md contains all the steps you need to do. Google doesn't distribute chrome OS images as for ...


0

You can do it with an alias: alias al='(read arg; echo The arg is: "$arg".) <<<' al something > The arg is: "something".


1

Who says mawk can't do it? echo 0x8110D248 | mawk '{OFMT="%.20g"; print +$0 }' 2165363272 % echo 0x8110D248 | mawk '{ printf("%.f\n", $0) }' 2165363272 Unlike other variants of AWK, mawk-1.3.4 uses scientific notation past 2³¹-1. The OFMT setting circumvents that. At default settings, mawk goes to 2⁵³-1, nawk goes to approx 100-...


2

You should make your scripts executable and let the scripts themselves define the shell to be used to execute them. Then you can add flags to the interpreter line to address questions like the one you've raised. This could cause the script to exit on first error: #!/bin/sh -e ../configure make make install Unfortunately you can't do it the easy and self-...


1

You can use a redirection around any command, including compound commands. For example: some_function () { echo "This also $1 to the file" } { echo "This goes to the file" some_function "goes" } >some_file echo "This does not go to the file" some_function "does not go" You can do a permanent ...


0

There doesn't seem to be a way to run background tasks correctly. The only way that works is to run openvt in the foreground without the -w option.


0

It turns out the issue occurs in "vi" from Debian's vim-tiny package, but not with "vi" from vim-basic or vim-gtk. The reason is vim-tiny installs an /etc/vim/vimrc.tiny with a line "set compatible" not commented out. The others only install /etc/vim/vimrc. This explains the differences in behavior among my installations. ...


0

Try adding stty sane to the script before running openvt. For example: #!/bin/bash stty sane openvt -c 8 -- /bin/bash If that doesn't work, try writing a wrapper script to run with openvt instead of running /bin/bash directly. The wrapper would be something like: #!/bin/bash stty sane exec bash Save it as something like /usr/local/bin/stty-sane-bash, ...


0

One liner that handles redirects and can extract tar.bz2 files. Use xzfor extracting gzip files. curl -L https://downloads.getmonero.org/cli/linux64 | tar xj


1

Try adding the following line to your vimrc. (more information: :help xterm-focus-event) set t_fd= t_fe= Vim 8.2.2345 adds support for xterm focus event, which are enabled by default. https://github.com/vim/vim/commit/681fc3fa782e99fe69ed2c83c3e29109d2d61e1a In my environment, when this new setting is enabled and there is a mapping to esc in insert mode, ...


2

Use find and -execdir which executes the given command in the directory where the file is found: find /apps -type f -name '*updated'\ -execdir bash -c 'cat "$0" > "$(basename "$0" .updated).json"' {} \; For a dry-run, just echo the command first and maybe print the found file: find /apps -type f -name '*updated' -print\ -...


1

yes, do as following to adding an hour to the current EPOCH (Using GNU date): date -d'+1hour' +%s%3N or adding an hour and 10 minutes and 20seconds date -d'+1hour +10minutes +20seconds' +%s%3N or add all in seconds (1hour+10min+20sec=4220sec): date -d'+4220seconds' +%s%3N


0

For zsh, this is very easy to do by invoking add-zsh-hook on the chpwd event. env_on_chdir () { case $PWD in /home/user/path/to/dir ) export GO111MODULE=on; ;; /home/user/other/dir ) export NO_COLOR=true; ;; * ) # change background, when entering any other directory ...


10

Run it with set -x to see what the shell actually runs, the commands are shown in the lines starting with + : + printf 'Guess the number (1-10) : ' Guess the number (1-10) : + read -r n + '[' 'randint=$((' '(' RANDOM % 10 ')' + 1 '))' = ']' bash: line 4: [: too many arguments [...] What's that in the test, inside [ ... ], the assignment randint=...(*)? It ...


1

There's no need to write two commands on one line. If you had 100 commands in your if statement you wouldn't && them together because it would be horrible to read. Whilst other responses concerning the possibility of echo failing are technically correct, I suspect the senior devs intent was about readability.


0

Root can literally read all your processes' memory. It will take them no effort at all; they can just halt the process for which that variable is set (in your case, your shell), and execute the libc function to get the value of the variable, or directly read the memory *envp themselves. You literally cannot keep a secret from root, as long as that secret is ...


0

Here are 4 techniques I've compiled. You can programmatically decide what to do if the script is being executed versus sourced. From check_if_sourced_or_executed.sh in my eRCaGuy_hello_world repo: #!/usr/bin/env bash main() { echo "Running main function." # put your code here echo -e "\nTOTAL TIME TO RUN main func:" } # ...


-1

I prefer this: [[ $(echo "$param" | awk '{print NF}') -eq 0 ]]


2

replacing head, tail and cut with sed, you could do as following: date -d"$(sed -n '2{s/^\(.\{10\}\).*/\1/p;q}' -- "$path/$tofile")" +'%Y%m%d'


0

you can just pipe the output of your tail -1 into your cut -c1-10. Then everything is in one line. Also, it's not clear why you use date -f <(...) instead of just date "$(...)".


Top 50 recent answers are included