id
int64
site
string
title
string
question_body
string
question_body_md
string
question_score
int32
question_view_count
int32
question_answer_count
int32
question_comment_count
int32
question_favorite_count
int32
question_tags
list
question_creation_date
string
question_last_edit_date
string
question_user_id
int64
accepted_answer_id
int64
answers
list
best_answer
string
text
string
char_length
int32
tokens_estimate
int32
meta
dict
650,045
unix.stackexchange.com
find pipe to less - why only correct lines are left when I press "up" key?
<p>I by accident find a good way to filter useful lines of <code>find</code>: just pipe it to <code>less</code> and when it shows <code>(END)</code> at the bottom, press <code>up</code> arrow key and only correct lines are left. No <code>Permission denied</code>, no symbolic link errors, nothing else.</p> <pre class="l...
I by accident find a good way to filter useful lines of `find`: just pipe it to `less` and when it shows `(END)` at the bottom, press `up` arrow key and only correct lines are left. No `Permission denied`, no symbolic link errors, nothing else. ``` find / -name foo | less ``` But, why? Cannot find an answer about why t...
6
807
2
1
1
[ "<bash><find><less>" ]
2021-05-17T11:17:01.957
2021-05-18T14:22:08.183
189,721
650,047
[ { "id": 650047, "body": "<p><code>find</code> with no “action” applies its default <code>-print</code> action, which outputs the full file name to standard output. Errors go to standard error.</p>\n<p>The pipe operator only redirects standard output; so only “correct” file names are sent to <code>less</code...
`find` with no “action” applies its default `-print` action, which outputs the full file name to standard output. Errors go to standard error. The pipe operator only redirects standard output; so only “correct” file names are sent to `less`, everything else goes to standard error, which is your terminal. `less` also wr...
# find pipe to less - why only correct lines are left when I press "up" key? **Tags:** <bash><find><less> **Question (score 6):** I by accident find a good way to filter useful lines of `find`: just pipe it to `less` and when it shows `(END)` at the bottom, press `up` arrow key and only correct lines are left. No `P...
1,887
471
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
650,381
unix.stackexchange.com
Concatenate files using a specific order based on another file
<p>I would like to concatenate multiple files following a specific order from an other file.</p> <p>I have multiple files called <code>freq_&lt;something&gt;</code> that I want to concatenate. The &quot;something&quot; are listed in another file called &quot;list&quot;.</p> <p>So here is my list:</p> <pre><code>$ cat l...
I would like to concatenate multiple files following a specific order from an other file. I have multiple files called `freq_<something>` that I want to concatenate. The "something" are listed in another file called "list". So here is my list: ``` $ cat list 003137F 002980F 002993F ``` I want to do: ``` cat freq_003137...
5
435
3
1
0
[ "<bash><io-redirection><file-management>" ]
2021-05-19T09:09:45.663
2021-05-19T09:24:46.853
472,483
650,386
[ { "id": 650383, "body": "<p>Use <code>xargs</code></p>\n<pre><code>xargs -i cat freq_'{}' &lt; list &gt; freq_all\n</code></pre>\n", "body_md": "Use `xargs` ``` xargs -i cat freq_'{}' freq_all ```", "score": 10, "creation_date": "2021-05-19T09:17:06.050", "user_id": 123460, "is_accepted"...
Use `xargs` ``` xargs -i cat freq_'{}' freq_all ```
# Concatenate files using a specific order based on another file **Tags:** <bash><io-redirection><file-management> **Question (score 5):** I would like to concatenate multiple files following a specific order from an other file. I have multiple files called `freq_<something>` that I want to concatenate. The "somethi...
1,206
301
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
650,496
unix.stackexchange.com
How can I figure out if a command is piped into another command?
<p>Using a bash function that dumps some information about itself to stderr and then calls <code>cat</code> to form a pipeline, how can I tell which stage in the pipeline called which other stage?</p> <p>One solution is to provide each stage a name like, <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, a...
Using a bash function that dumps some information about itself to stderr and then calls `cat` to form a pipeline, how can I tell which stage in the pipeline called which other stage? One solution is to provide each stage a name like, `a`, `b`, `c`, `d`, and then when I look at the output I know that `a > b > c > d`. Bu...
10
767
1
0
4
[ "<bash><shell-script>" ]
2021-05-19T23:50:08.100
2021-05-20T00:53:23.363
437,828
650,500
[ { "id": 650500, "body": "<p>The pipes are anonymous (contrary to named pipes) because they are created with the <a href=\"https://man7.org/linux/man-pages/man2/pipe.2.html\" rel=\"noreferrer\"><code>pipe(2)</code></a> command. However, they of course have an internal ID which is displayed by <code>lsof</cod...
The pipes are anonymous (contrary to named pipes) because they are created with the `pipe(2)` (https://man7.org/linux/man-pages/man2/pipe.2.html) command. However, they of course have an internal ID which is displayed by `lsof` (and which you can see in `ls -l /proc/<pid>/fd`). But I don't see an identifier of stdout i...
# How can I figure out if a command is piped into another command? **Tags:** <bash><shell-script> **Question (score 10):** Using a bash function that dumps some information about itself to stderr and then calls `cat` to form a pipeline, how can I tell which stage in the pipeline called which other stage? One solutio...
3,720
930
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
650,610
unix.stackexchange.com
How to match a literal string containing an unclosed quote with ripgrep?
<p>I have a file that contains the some python code. There is a line that contains the following(including the quotes)</p> <p><code>'hello &quot;value&quot;'</code></p> <p>I want to search <code>'hello &quot;value&quot;</code> in the file. Notice the unclosed quote. I'm using ripgrep with the folowing command:</p> <p><...
I have a file that contains the some python code. There is a line that contains the following(including the quotes) `'hello "value"'` I want to search `'hello "value"` in the file. Notice the unclosed quote. I'm using ripgrep with the folowing command: `rg -F 'hello "value"` The above command is not working for the inp...
5
646
3
1
0
[ "<quoting><pattern-matching><ripgrep>" ]
2021-05-20T15:13:18.290
2021-05-20T16:08:15.220
379,023
null
[ { "id": 650611, "body": "<p>The text <code>'hello &quot;value&quot;</code> <em>as seen by the shell</em> starts with a single quote and never ends it. You'll get a continuation prompt (<code>$PS2</code>, often <code>&gt;</code>) asking for the rest of the string.</p>\n<p>To search for something like this yo...
The text `'hello "value"` as seen by the shell starts with a single quote and never ends it. You'll get a continuation prompt (`$PS2`, often `>`) asking for the rest of the string. To search for something like this you would need to escape the quotes (both sorts) from the shell, which you can do like this ``` "'hello \...
# How to match a literal string containing an unclosed quote with ripgrep? **Tags:** <quoting><pattern-matching><ripgrep> **Question (score 5):** I have a file that contains the some python code. There is a line that contains the following(including the quotes) `'hello "value"'` I want to search `'hello "value"` in ...
3,865
966
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
650,942
unix.stackexchange.com
Shell script returns 0 exit_status despite syntax error
<p>Consider this script:</p> <pre><code>#!/bin/sh foo=1 if [[ ! -z $foo ]]; then echo abc fi </code></pre> <p>It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubuntu (dash). However, its return code is still zero.</p> <pre><code>$ ./tmp.sh ./tmp.sh: 4: ....
Consider this script: ``` #!/bin/sh foo=1 if [[ ! -z $foo ]]; then echo abc fi ``` It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubuntu (dash). However, its return code is still zero. ``` $ ./tmp.sh ./tmp.sh: 4: ./tmp.sh: [[: not found $ echo $? 0 ``` How ...
10
615
2
2
1
[ "<shell><exit-status><dash>" ]
2021-05-22T20:09:37.327
2021-05-22T21:22:54.190
392,174
650,948
[ { "id": 650948, "body": "<p>Let me first explain why this happens. <a href=\"https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html\" rel=\"noreferrer\">POSIX Shell Command Language\nspec</a>\nsays:</p>\n<blockquote>\n<p>The exit status of the if command shall be the exit status of the th...
Let me first explain why this happens. POSIX Shell Command Language spec (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) says: The exit status of the if command shall be the exit status of the then or else compound-list that was executed, or zero, if none was executed. Since in your case `th...
# Shell script returns 0 exit_status despite syntax error **Tags:** <shell><exit-status><dash> **Question (score 10):** Consider this script: ``` #!/bin/sh foo=1 if [[ ! -z $foo ]]; then echo abc fi ``` It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubun...
4,622
1,155
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,000
unix.stackexchange.com
How to recursively set directory permissions with a find that lacks -exec?
<p>My Qnap NAS is cursed with a <code>find</code> command that lacks the <code>-exec</code> parameter, so I have to pipe to something. The shell is: GNU bash, version 3.2.57(2)-release-(arm-unknown-linux-gnueabihf)</p> <p>I'm trying to set the setgid bit on all subdirectories (not files) of the current directory.</p> <...
My Qnap NAS is cursed with a `find` command that lacks the `-exec` parameter, so I have to pipe to something. The shell is: GNU bash, version 3.2.57(2)-release-(arm-unknown-linux-gnueabihf) I'm trying to set the setgid bit on all subdirectories (not files) of the current directory. This does not work: ``` find . -type ...
5
533
3
2
0
[ "<bash><find><pipe><quoting><qnap>" ]
2021-05-23T08:50:30.727
2021-05-24T12:38:29.740
174,665
651,007
[ { "id": 651007, "body": "<p>The output of <code>find</code> emits file names separated by newlines<sup>1</sup>. This is not the format that <code>xargs</code> wants and <code>find</code> has no way to produce the format that <code>xargs</code> wants: it parses its input as whitespace-separated items, with <...
The output of `find` emits file names separated by newlines1. This is not the format that `xargs` wants and `find` has no way to produce the format that `xargs` wants: it parses its input as whitespace-separated items, with `\'"` used for quoting. Some versions of `xargs` can take newline-separated input, but if your `...
# How to recursively set directory permissions with a find that lacks -exec? **Tags:** <bash><find><pipe><quoting><qnap> **Question (score 5):** My Qnap NAS is cursed with a `find` command that lacks the `-exec` parameter, so I have to pipe to something. The shell is: GNU bash, version 3.2.57(2)-release-(arm-unknown...
3,932
983
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,155
unix.stackexchange.com
How to make Bash/Zsh prompt show only the current directory and its parent?
<p>How can I create a bash and a zsh prompt that shows only the current directory and its parent directory?</p> <p>For example, if I'm at the dir <code>~/pictures/photos/2021</code>, it should show:</p> <pre class="lang-bsh prettyprint-override"><code>[photos/2021]$ echo hi </code></pre> <p>That's all. Would like it fo...
How can I create a bash and a zsh prompt that shows only the current directory and its parent directory? For example, if I'm at the dir `~/pictures/photos/2021`, it should show: ``` [photos/2021]$ echo hi ``` That's all. Would like it for `bash` and for `zsh`.
7
1,613
2
1
2
[ "<bash><zsh><prompt>" ]
2021-05-24T13:21:32.083
2021-05-25T17:01:20.217
462,354
651,157
[ { "id": 651157, "body": "<p>In <code>zsh</code>:</p>\n<pre><code>PS1='[%2d] $ '\n</code></pre>\n<p>See <a href=\"https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Shell-state\" rel=\"noreferrer\"><code>info zsh 'prompt expansion'</code></a> for details.</p>\n<p>In <code>bash</code> (or <code>zsh ...
In `zsh`: ``` PS1='[%2d] $ ' ``` See `info zsh 'prompt expansion'` (https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Shell-state) for details. In `bash` (or `zsh -o promptsubst`, though you wouldn't want to do that there as if `$PWD` contains `%` characters, that would cause further prompt expansions): ``` ...
# How to make Bash/Zsh prompt show only the current directory and its parent? **Tags:** <bash><zsh><prompt> **Question (score 7):** How can I create a bash and a zsh prompt that shows only the current directory and its parent directory? For example, if I'm at the dir `~/pictures/photos/2021`, it should show: ``` [ph...
786
196
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,195
unix.stackexchange.com
awk script to prepare csv file
<p>I'm stuck creating an awk script that prepares a csv file before analysis. I need to create an output file with columns 1-2, 10, 13-15, 19-21. Also I need to replace the numbers on column 2 to the days of the week (so, 1 = Monday, 2 = Tuesday...) and convert the 21th column from nautical miles to km; and delete <cod...
I'm stuck creating an awk script that prepares a csv file before analysis. I need to create an output file with columns 1-2, 10, 13-15, 19-21. Also I need to replace the numbers on column 2 to the days of the week (so, 1 = Monday, 2 = Tuesday...) and convert the 21th column from nautical miles to km; and delete `""`of ...
7
828
2
4
1
[ "<awk><scripting><csv>" ]
2021-05-24T19:45:38.937
2021-05-24T21:33:29.903
469,363
651,201
[ { "id": 651210, "body": "<pre><code>awk '\n BEGIN {\n split(&quot;Monday Tuesday Wednesday Thursday Friday Saturday Sunday&quot;,days)\n FS=OFS=&quot;,&quot;\n }\n NR &gt; 1 {\n gsub(/&quot;/,&quot;&quot;)\n $2 = days[$2]\n $21 *= 1.852\n }\n { print $1, $2,...
``` awk ' BEGIN { split("Monday Tuesday Wednesday Thursday Friday Saturday Sunday",days) FS=OFS="," } NR > 1 { gsub(/"/,"") $2 = days[$2] $21 *= 1.852 } { print $1, $2, $10, $13, $14, $15, $19, $20, $21 } ' file "DAY_OF_MONTH","DAY_OF_WEEK","ORIGIN","DEST","DEP_TIME","DEP_DEL15","CANCELLED","DIVERTED","DISTANCE" 1,Tues...
# awk script to prepare csv file **Tags:** <awk><scripting><csv> **Question (score 7):** I'm stuck creating an awk script that prepares a csv file before analysis. I need to create an output file with columns 1-2, 10, 13-15, 19-21. Also I need to replace the numbers on column 2 to the days of the week (so, 1 = Monda...
3,073
768
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,408
unix.stackexchange.com
Why is "requiretty" not working?
<p>It's my understanding that the <code>requiretty</code> option does not allow sudo on PTYs.</p> <p>My VM's <code>sudoers</code>:</p> <pre><code># # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See...
It's my understanding that the `requiretty` option does not allow sudo on PTYs. My VM's `sudoers`: ``` # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a...
5
473
1
0
0
[ "<debian><ssh><sudo>" ]
2021-05-26T04:07:53.123
2021-05-26T17:41:38.290
473,501
651,424
[ { "id": 651424, "body": "<p>Your understanding is not correct: a pseudo-TTY is considered fully equivalent to a &quot;real&quot; TTY.</p>\n<p>When <code>tty</code> prints <code>/dev/pts/0</code> it means the session has a valid TTY.</p>\n<p>But if you connect to the VM with SSH default settings and specify ...
Your understanding is not correct: a pseudo-TTY is considered fully equivalent to a "real" TTY. When `tty` prints `/dev/pts/0` it means the session has a valid TTY. But if you connect to the VM with SSH default settings and specify the command to run, the situation will be different: ``` $ ssh VM-user@VM-hostname "host...
# Why is "requiretty" not working? **Tags:** <debian><ssh><sudo> **Question (score 5):** It's my understanding that the `requiretty` option does not allow sudo on PTYs. My VM's `sudoers`: ``` # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ i...
3,661
915
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,662
unix.stackexchange.com
Checking if a subdirectory exists using glob in script
<p>I'm trying to check if a directory <code>bin</code> is inside a directory which can sometimes change. In this particular case, the version number of ruby can change (e.g. <code>$HOME/.gem/ruby/2.6.0/bin</code>). Here's what I did so far:</p> <pre class="lang-zsh prettyprint-override"><code>#!/usr/bin/env zsh ruby_ge...
I'm trying to check if a directory `bin` is inside a directory which can sometimes change. In this particular case, the version number of ruby can change (e.g. `$HOME/.gem/ruby/2.6.0/bin`). Here's what I did so far: ``` #!/usr/bin/env zsh ruby_gem_home="$HOME/.gem/ruby/*/bin" if [[ -d $ruby_gem_home ]]; then echo "The ...
6
558
3
0
1
[ "<shell-script><zsh><directory><wildcards>" ]
2021-05-27T16:07:25.030
2021-05-27T18:22:01.180
290,185
651,668
[ { "id": 651668, "body": "<p>Use an array, and check whether the first element (i.e. [0] in bash, [1] in zsh) of the array is a directory. e.g. in <code>bash</code>:</p>\n<pre class=\"lang-bsh prettyprint-override\"><code># the trailing slash in &quot;$HOME&quot;/.gem/ruby/*/bin/ ensures that\n# the glob ma...
Use an array, and check whether the first element (i.e. [0] in bash, [1] in zsh) of the array is a directory. e.g. in `bash`: ``` # the trailing slash in "$HOME"/.gem/ruby/*/bin/ ensures that # the glob matches only directories. rubygemdirs=( "$HOME"/.gem/ruby/*/bin/ ) if [ -d "${rubygemdirs[0]}" ] ; then echo "At leas...
# Checking if a subdirectory exists using glob in script **Tags:** <shell-script><zsh><directory><wildcards> **Question (score 6):** I'm trying to check if a directory `bin` is inside a directory which can sometimes change. In this particular case, the version number of ruby can change (e.g. `$HOME/.gem/ruby/2.6.0/b...
6,000
1,500
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
651,980
unix.stackexchange.com
Difference between command `command` vs command `builtin` in Shell Scripting
<p>I understand the command <code>command</code> is specified in the <a href="https://pubs.opengroup.org/onlinepubs/9699919799/toc.htm" rel="nofollow noreferrer">latest POSIX standard</a> and <code>builtin</code> is not. I also realize that both commands are <em>regular builtins</em> (i.e. they can be overwritten by us...
I understand the command `command` is specified in the latest POSIX standard (https://pubs.opengroup.org/onlinepubs/9699919799/toc.htm) and `builtin` is not. I also realize that both commands are regular builtins (i.e. they can be overwritten by user-defined functions). Some shells define `builtin`, but not all (e.g. `...
5
108
1
0
0
[ "<command><history><shell-builtin>" ]
2021-05-29T19:08:19.123
2021-05-30T20:38:40.243
471,017
652,064
[ { "id": 652064, "body": "<p>The <a href=\"https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html#tag_20_22_18\" rel=\"nofollow noreferrer\">POSIX rationale for <code>command</code></a> answers most of the historical aspects your question.</p>\n<blockquote>\n<p>The <em>command</em> utility i...
The POSIX rationale for `command` (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html#tag_20_22_18) answers most of the historical aspects your question. The command utility is somewhat similar to the Eighth Edition shell builtin command, but since command also goes to the file system to search for...
# Difference between command `command` vs command `builtin` in Shell Scripting **Tags:** <command><history><shell-builtin> **Question (score 5):** I understand the command `command` is specified in the latest POSIX standard (https://pubs.opengroup.org/onlinepubs/9699919799/toc.htm) and `builtin` is not. I also reali...
10,118
2,529
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,076
unix.stackexchange.com
How to mark directories in the output of the `find` command?
<p>For example, I looking for files and directories in some directory:</p> <pre class="lang-bsh prettyprint-override"><code>ubuntu@example:/etc/letsencrypt$ sudo find . -name example.com* ./archive/example.com ./renewal/example.com.conf ./live/example.com ubuntu@example:/etc/letsencrypt$ </code></pre> <p>How can I mar...
For example, I looking for files and directories in some directory: ``` ubuntu@example:/etc/letsencrypt$ sudo find . -name example.com* ./archive/example.com ./renewal/example.com.conf ./live/example.com ubuntu@example:/etc/letsencrypt$ ``` How can I mark that `./archive/example.com` and `./live/example.com` are direct...
12
1,226
5
2
4
[ "<linux><ubuntu><find>" ]
2021-05-30T17:53:42.777
2021-06-01T12:25:38.137
169,259
652,085
[ { "id": 652085, "body": "<p>Print the file type along with the name with <code>-printf &quot;%y %p\\n&quot;</code>:</p>\n<pre><code>$ sudo find . -name 'example.com*' -printf &quot;%y %p\\n&quot;\nd ./archive/example.com\nf ./renewal/example.com.conf\nd ./live/example.com\n</code></pre>\n<p>The use of <code...
Print the file type along with the name with `-printf "%y %p\n"`: ``` $ sudo find . -name 'example.com*' -printf "%y %p\n" d ./archive/example.com f ./renewal/example.com.conf d ./live/example.com ``` The use of `-printf` assumes GNU `find` (the most common `find` implementation on Linux systems).
# How to mark directories in the output of the `find` command? **Tags:** <linux><ubuntu><find> **Question (score 12):** For example, I looking for files and directories in some directory: ``` ubuntu@example:/etc/letsencrypt$ sudo find . -name example.com* ./archive/example.com ./renewal/example.com.conf ./live/examp...
3,515
878
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,142
unix.stackexchange.com
Why does sleep, when run in a shell script, ignore SIGINT?
<p>When I run <code>sleep</code> manually, and then <code>kill -INT</code> it, sleep exits immediately. For example:</p> <pre><code>$ /bin/sleep 60 &amp; [1] 4002356 $ kill -INT 4002356 [1]+ Interrupt /bin/sleep 60 $ ps -C sleep PID TTY TIME CMD $ </code></pre> <p>However, when I do ...
When I run `sleep` manually, and then `kill -INT` it, sleep exits immediately. For example: ``` $ /bin/sleep 60 & [1] 4002356 $ kill -INT 4002356 [1]+ Interrupt /bin/sleep 60 $ ps -C sleep PID TTY TIME CMD $ ``` However, when I do the same thing in a shell script, `sleep` ignores the `SIGINT`. For example: ``` set -o x...
7
633
1
4
0
[ "<shell-script><shell><sleep><sigint>" ]
2021-05-31T05:55:43.727
2021-05-31T07:27:46.480
65,444
652,145
[ { "id": 652145, "body": "<p>In <code>/bin/sleep 10 &amp;</code> the terminating <code>&amp;</code> makes the shell run <code>sleep</code> asynchronously. Job control is by default disabled in a script. In Bash the following applies [emphasis mine]:</p>\n<blockquote>\n<p>Non-builtin commands started by Bash ...
In `/bin/sleep 10 &` the terminating `&` makes the shell run `sleep` asynchronously. Job control is by default disabled in a script. In Bash the following applies [emphasis mine]: Non-builtin commands started by Bash have signal handlers set to the values inherited by the shell from its parent. When job control is not ...
# Why does sleep, when run in a shell script, ignore SIGINT? **Tags:** <shell-script><shell><sleep><sigint> **Question (score 7):** When I run `sleep` manually, and then `kill -INT` it, sleep exits immediately. For example: ``` $ /bin/sleep 60 & [1] 4002356 $ kill -INT 4002356 [1]+ Interrupt /bin/sleep 60 $ ps -C sl...
2,131
532
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,223
unix.stackexchange.com
In Linux, is there a system layer/script that handles the opening of files?
<p>in Linux, is there a layer/script that handles program-requests to open files?</p> <p>Like when you open a file-descriptor in bash: <code>exec 3 &lt;&gt;/documents/foo.txt</code>or your text-editor opens <code>/documents/foo.txt</code></p> <p>I can't believe an editor can &quot;just open up a file&quot; for read/wri...
in Linux, is there a layer/script that handles program-requests to open files? Like when you open a file-descriptor in bash: `exec 3 <>/documents/foo.txt`or your text-editor opens `/documents/foo.txt` I can't believe an editor can "just open up a file" for read/write access on its own. I rather imagine this to be a req...
6
1,362
4
8
2
[ "<linux><files>" ]
2021-05-31T17:41:07.190
2021-05-31T19:16:55.177
440,130
null
[ { "id": 652226, "body": "<p>This layer is inside the kernel in Linux and other systems that don't stray too far from the historical Unix design (and in most non-Unix operating systems as well).</p>\n<p>This part of the kernel is called the <a href=\"https://en.wikipedia.org/wiki/Virtual_file_system\" rel=\"...
This layer is inside the kernel in Linux and other systems that don't stray too far from the historical Unix design (and in most non-Unix operating systems as well). This part of the kernel is called the VFS (virtual file system) layer (https://en.wikipedia.org/wiki/Virtual_file_system). The role of the VFS is to manag...
# In Linux, is there a system layer/script that handles the opening of files? **Tags:** <linux><files> **Question (score 6):** in Linux, is there a layer/script that handles program-requests to open files? Like when you open a file-descriptor in bash: `exec 3 <>/documents/foo.txt`or your text-editor opens `/document...
7,540
1,885
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,299
unix.stackexchange.com
Changing Python's default version breaks Ubuntu 20.04
<p>I'm creating an AMI of <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_20.04_LTS_(Focal_Fossa)" rel="nofollow noreferrer">Ubuntu 20.04</a> (Focal Fossa), and I want the default Python version to be 3.6.</p> <p>I installed Python 3.6, also the right pip, and then set the alternative like so:</p> ...
I'm creating an AMI of Ubuntu 20.04 (https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_20.04_LTS_(Focal_Fossa)) (Focal Fossa), and I want the default Python version to be 3.6. I installed Python 3.6, also the right pip, and then set the alternative like so: ``` update-alternatives --install \ /usr/bin/python3...
7
1,307
2
0
1
[ "<ubuntu><python3><alternatives>" ]
2021-06-01T10:01:19.170
2021-06-02T15:26:54.797
150,289
652,301
[ { "id": 652301, "body": "<p>As you discovered, the system does rely on the <em>system</em> version of Python being as it expects. If you really want a system with Python 3.6, your best bet is to find a (ideally, still supported) release using Python 3.6: in your case, Ubuntu 18.04.</p>\n<p>If you want to pr...
As you discovered, the system does rely on the system version of Python being as it expects. If you really want a system with Python 3.6, your best bet is to find a (ideally, still supported) release using Python 3.6: in your case, Ubuntu 18.04. If you want to provide Python 3.6 for programs running on your AMI, you co...
# Changing Python's default version breaks Ubuntu 20.04 **Tags:** <ubuntu><python3><alternatives> **Question (score 7):** I'm creating an AMI of Ubuntu 20.04 (https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_20.04_LTS_(Focal_Fossa)) (Focal Fossa), and I want the default Python version to be 3.6. I install...
2,707
676
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,316
unix.stackexchange.com
The UNIX and Linux SysAdm Handbook: Why are cached man pages a "security risk"?
<p>The <em>UNIX and Linux System Administration Handbook</em> says:</p> <blockquote> <p>man maintains a cache of formatted pages in /var/cache/man or /usr/share/man if the appropriate directories are writable; however, this is a security risk. Most systems preformat the man pages once at installation time (see catman) ...
The UNIX and Linux System Administration Handbook says: man maintains a cache of formatted pages in /var/cache/man or /usr/share/man if the appropriate directories are writable; however, this is a security risk. Most systems preformat the man pages once at installation time (see catman) or not at all. What is the "secu...
29
5,136
6
3
3
[ "<security><man>" ]
2021-06-01T11:16:35.193
2021-06-02T12:05:49.690
459,222
null
[ { "id": 652326, "body": "<p>It's not safe to let users manipulate the content of man pages (or any data really) that will also be used by other users, because there is a danger of <em>cache poisoning</em>. As the old BOFH joke goes:</p>\n<blockquote>\n<p>To learn everything about your system, from the root ...
It's not safe to let users manipulate the content of man pages (or any data really) that will also be used by other users, because there is a danger of cache poisoning. As the old BOFH joke goes: To learn everything about your system, from the root up, use the "read manual" command with the "read faster" switch like th...
# The UNIX and Linux SysAdm Handbook: Why are cached man pages a "security risk"? **Tags:** <security><man> **Question (score 29):** The UNIX and Linux System Administration Handbook says: man maintains a cache of formatted pages in /var/cache/man or /usr/share/man if the appropriate directories are writable; howeve...
6,094
1,523
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,331
unix.stackexchange.com
How do I find the first non-zero byte on a block device, with an optional offset?
<p>I'm trying to find the first non-zero byte (starting from an optional offset) on a block device using <code>dd</code> and print its offset, but I am stuck. I didn't mention <code>dd</code> in the title as I figured there might be a more appropriate tool than <code>dd</code> to do this, but I figured <code>dd</code> ...
I'm trying to find the first non-zero byte (starting from an optional offset) on a block device using `dd` and print its offset, but I am stuck. I didn't mention `dd` in the title as I figured there might be a more appropriate tool than `dd` to do this, but I figured `dd` should be a good start. If you know of a more a...
11
1,019
2
3
1
[ "<bash><dd><block-device><byte>" ]
2021-06-01T13:01:21.967
2021-06-02T22:53:04.080
474,454
652,335
[ { "id": 652335, "body": "<p>You can do this using <a href=\"https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cmp.html\" rel=\"noreferrer\"><code>cmp</code></a>, comparing to <code>/dev/zero</code>:</p>\n<pre><code>cmp /path/to/block-device /dev/zero\n</code></pre>\n<p><code>cmp</code> will give yo...
You can do this using `cmp` (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cmp.html), comparing to `/dev/zero`: ``` cmp /path/to/block-device /dev/zero ``` `cmp` will give you the offset of the first non-zero byte. If you want to skip bytes, you can use GNU `cmp`’s `-i` option, or if you’re not using GNU `...
# How do I find the first non-zero byte on a block device, with an optional offset? **Tags:** <bash><dd><block-device><byte> **Question (score 11):** I'm trying to find the first non-zero byte (starting from an optional offset) on a block device using `dd` and print its offset, but I am stuck. I didn't mention `dd` ...
3,494
873
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,375
unix.stackexchange.com
What’s an efficient way to convert human-readable sizes to byte quantities?
<p>I would like to convert the ZFS output of &quot;10.9T&quot; to actual bytes, using something in a line or two, rather than run generic math functions, and if conditions for <code>T</code>, <code>G</code>, <code>M</code>, etc.. Is there an efficient way to do this?</p> <p>For now, I have something like this:</p> <pre...
I would like to convert the ZFS output of "10.9T" to actual bytes, using something in a line or two, rather than run generic math functions, and if conditions for `T`, `G`, `M`, etc.. Is there an efficient way to do this? For now, I have something like this: ``` MINFREE="50G" POOLSIZE=`zpool list $POOLNAME -o size` #Si...
14
2,367
4
6
3
[ "<bash><text-processing>" ]
2021-06-01T20:42:42.037
2021-06-03T22:26:14.967
111,873
652,386
[ { "id": 652377, "body": "<p>There is no good way to convert <code>zfs</code>'s human-readable numbers to actual bytes. The human-readable numbers are rounded off and therefore inexact.</p>\n<p>If you want exact numbers, use the <code>-p</code> option (machine parseable), and the output will be in bytes, wh...
There is no good way to convert `zfs`'s human-readable numbers to actual bytes. The human-readable numbers are rounded off and therefore inexact. If you want exact numbers, use the `-p` option (machine parseable), and the output will be in bytes, which you can parse and format however you wish. ``` $ zfs list tank/var;...
# What’s an efficient way to convert human-readable sizes to byte quantities? **Tags:** <bash><text-processing> **Question (score 14):** I would like to convert the ZFS output of "10.9T" to actual bytes, using something in a line or two, rather than run generic math functions, and if conditions for `T`, `G`, `M`, et...
6,387
1,596
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,493
unix.stackexchange.com
Who decided the bc math library will define sine cosine and arctangent?
<p>If you load the <a href="https://www.gnu.org/software/bc/manual/html_node/bc_18.html" rel="nofollow noreferrer">bc math library</a> you get the trig functions <code>s()</code> and <code>c()</code> and <code>a()</code> which are sine, cosine, and arctangent respectively. Why these three functions?</p> <p>I know why i...
If you load the bc math library (https://www.gnu.org/software/bc/manual/html_node/bc_18.html) you get the trig functions `s()` and `c()` and `a()` which are sine, cosine, and arctangent respectively. Why these three functions? I know why it's those three from the mathematical perspective: it's because those are the thr...
8
256
1
10
1
[ "<history><bc><math><reference>" ]
2021-06-02T16:42:21.253
2021-06-02T23:35:40.250
74,616
652,575
[ { "id": 652575, "body": "<p>Not a full answer, but perhaps somewhat useful.</p>\n<p>More of a list of examples of use of trig functions in early adaptions. Also a look into the UNIX world.</p>\n<hr />\n<h1>ALGOL</h1>\n<p>Interesting paper concerning the history:</p>\n<ul>\n<li><a href=\"https://heerdebeer.o...
Not a full answer, but perhaps somewhat useful. More of a list of examples of use of trig functions in early adaptions. Also a look into the UNIX world. # ALGOL Interesting paper concerning the history: - The History of the ALGOL Effort, by HT de Beer (https://heerdebeer.org/ALGOL/The_History_of_ALGOL.pdf) ALGOL was de...
# Who decided the bc math library will define sine cosine and arctangent? **Tags:** <history><bc><math><reference> **Question (score 8):** If you load the bc math library (https://www.gnu.org/software/bc/manual/html_node/bc_18.html) you get the trig functions `s()` and `c()` and `a()` which are sine, cosine, and arc...
10,486
2,621
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,623
unix.stackexchange.com
How to evaluate the wear level of a NVMe SSD?
<p>I have a laptop with NVMe SSD:</p> <pre class="lang-none prettyprint-override"><code># nvme list Node SN Model Namespace Usage Format FW Rev ---------------- -------------------- ---------------------------------------...
I have a laptop with NVMe SSD: ``` # nvme list Node SN Model Namespace Usage Format FW Rev ---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- -------- /dev/nvme0n1 KXG50ZNV512G NVMe TOSHIBA 512GB 1 512.11 GB / 512.11 GB 512 B + 0 B AADA41...
7
1,767
1
0
0
[ "<ssd><smartctl><nvme>" ]
2021-06-03T12:25:59.457
2021-06-03T21:48:10.043
126,755
652,631
[ { "id": 652631, "body": "<p>The wear level is given by the “Percentage Used” field, <a href=\"http://www.nvmexpress.org/wp-content/uploads/NVM_Express_1_2b_Gold_20160603.pdf\" rel=\"noreferrer\">which is specified as</a></p>\n<blockquote>\n<p><strong>Percentage Used:</strong> Contains a vendor specific esti...
The wear level is given by the “Percentage Used” field, which is specified as (http://www.nvmexpress.org/wp-content/uploads/NVM_Express_1_2b_Gold_20160603.pdf) Percentage Used: Contains a vendor specific estimate of the percentage of NVM subsystem life used based on the actual usage and the manufacturer’s prediction of...
# How to evaluate the wear level of a NVMe SSD? **Tags:** <ssd><smartctl><nvme> **Question (score 7):** I have a laptop with NVMe SSD: ``` # nvme list Node SN Model Namespace Usage Format FW Rev ---------------- -------------------- ---------------------------------------- --------- -------------------------- ------...
3,676
919
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,698
unix.stackexchange.com
Use awk or sed to remove everything between < >
<p>I have the following in a txt file:</p> <pre><code>&lt;ol&gt;&lt;li&gt;&lt;b&gt;&lt;a href=&quot;/page1/Mark_Yato&quot; title=&quot;Mark Yato&quot;&gt;Mark Yato&lt;/a&gt; ft. MarkAm &amp;amp; &lt;a href=&quot;/page1/Giv%C4%93on&quot; title=&quot;Givēon&quot;&gt;Givēon&lt;/a&gt; - &lt;a href=&quot;/page1/Mark_Yato:Th...
I have the following in a txt file: ``` - Mark Yato (/page1/Mark_Yato) ft. MarkAm & Givēon (/page1/Giv%C4%93on) - Thuieo (/page1/Mark_Yato:Thuieo) (7) - The Central (/page1/The_Central) - AHTIOe oie (/page1/The_Central:AHTIOe oie) (7) - Taa Too A (/page1/Taa_Too_A) - ryhwtyw w (/page1/Taa_Too_A:ryhwtyw w) (8) ``` and a...
7
1,486
8
5
1
[ "<ubuntu><awk><sed>" ]
2021-06-03T21:53:55.860
2021-06-04T10:12:34.687
398,851
null
[ { "id": 652709, "body": "<p>Parsing markup with regular expressions is <a href=\"https://stackoverflow.com/q/1732348/10488700\">notoriously problematic</a>.</p>\n<p>While not an issue with your sample data, angle brackets may appear in tag attributes, comments and possibly other places, making regular expre...
Parsing markup with regular expressions is notoriously problematic (https://stackoverflow.com/q/1732348/10488700). While not an issue with your sample data, angle brackets may appear in tag attributes, comments and possibly other places, making regular expressions that match from `<` to `>` unreliable. You should resor...
# Use awk or sed to remove everything between < > **Tags:** <ubuntu><awk><sed> **Question (score 7):** I have the following in a txt file: ``` - Mark Yato (/page1/Mark_Yato) ft. MarkAm & Givēon (/page1/Giv%C4%93on) - Thuieo (/page1/Mark_Yato:Thuieo) (7) - The Central (/page1/The_Central) - AHTIOe oie (/page1/The_Cen...
5,209
1,302
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
652,822
unix.stackexchange.com
Incrementally Swap Lines Between Two Regex Patterns in a File
<p>I'm trying to do some text processing on a file using a bash script. The goal is to take all of the lines starting with &quot;field:&quot; indented under an 'attribute:' label and swap them with the associated line starting with &quot;- attr:&quot; that follows.</p> <p>So far I think I have regex patterns that shoul...
I'm trying to do some text processing on a file using a bash script. The goal is to take all of the lines starting with "field:" indented under an 'attribute:' label and swap them with the associated line starting with "- attr:" that follows. So far I think I have regex patterns that should match the labels: `/ *field:...
5
185
4
1
1
[ "<shell-script><awk><sed><python>" ]
2021-06-04T16:44:23.417
2021-06-04T17:22:50.760
475,989
652,825
[ { "id": 652825, "body": "<p>Using any awk in any shell on every Unix box:</p>\n<pre><code>$ awk '$1==&quot;field:&quot;{s=ORS $0; next} {print $0 s; s=&quot;&quot;}' file\n- metric: 'example.metric.1'\n attributes:\n - attr: 'example1'\n field: 'example 1'\n - attr: 'example2'\n field: 'exa...
Using any awk in any shell on every Unix box: ``` $ awk '$1=="field:"{s=ORS $0; next} {print $0 s; s=""}' file - metric: 'example.metric.1' attributes: - attr: 'example1' field: 'example 1' - attr: 'example2' field: 'example 2' - attr: 'example3' field: 'example 3' - attr: 'example4' field: 'example 4' - metric: 'examp...
# Incrementally Swap Lines Between Two Regex Patterns in a File **Tags:** <shell-script><awk><sed><python> **Question (score 5):** I'm trying to do some text processing on a file using a bash script. The goal is to take all of the lines starting with "field:" indented under an 'attribute:' label and swap them with t...
2,526
631
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,128
unix.stackexchange.com
Are there any tools available to store SMART data over time?
<p>I'd like to start storing the SMART data over time and see any trends based on disk ID/serial number. Something that would let me, for example just get the smart information from disks once a day and put it in a database. Is there already a tool for this in Linux, or do I have to roll my own?</p>
I'd like to start storing the SMART data over time and see any trends based on disk ID/serial number. Something that would let me, for example just get the smart information from disks once a day and put it in a database. Is there already a tool for this in Linux, or do I have to roll my own?
7
884
3
0
0
[ "<hard-disk><smart>" ]
2021-06-06T22:10:49.430
2021-06-07T20:22:01.403
19,912
653,157
[ { "id": 653157, "body": "<p>There are already tools which can do this, often as part of a more general monitoring tool. One I find useful is <a href=\"https://munin-monitoring.org/\" rel=\"noreferrer\">Munin</a>, which has a <a href=\"https://gallery.munin-monitoring.org/plugins/munin-2.0/smart_/\" rel=\"no...
There are already tools which can do this, often as part of a more general monitoring tool. One I find useful is Munin (https://munin-monitoring.org/), which has a SMART plugin (https://gallery.munin-monitoring.org/plugins/munin-2.0/smart_/) to trace the available attributes: Munin is available in many distributions. `...
# Are there any tools available to store SMART data over time? **Tags:** <hard-disk><smart> **Question (score 7):** I'd like to start storing the SMART data over time and see any trends based on disk ID/serial number. Something that would let me, for example just get the smart information from disks once a day and p...
4,303
1,075
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,132
unix.stackexchange.com
Join a number of lines with a starting and ending pattern
<p>I've a file like this:</p> <pre><code>method AAA one (1,111): some_text_1 method BBB two (2, 222): tuesday method CCC three (3, 333): sunny_day method DDD four (4, 444_a, 444_b): last_week </code></pre> <p>I want it to look like this:</p> <pre><code>method AAA one (1,111): some_text_1 m...
I've a file like this: ``` method AAA one (1,111): some_text_1 method BBB two (2, 222): tuesday method CCC three (3, 333): sunny_day method DDD four (4, 444_a, 444_b): last_week ``` I want it to look like this: ``` method AAA one (1,111): some_text_1 method BBB two (2,222): tuesday method CCC three (3,333): sunny_day m...
7
431
6
0
0
[ "<shell-script><sed>" ]
2021-06-06T22:30:51.163
2021-06-07T01:52:07.967
476,272
null
[ { "id": 653133, "body": "<p>Based on <a href=\"https://catonmat.net/sed-one-liners-explained-part-one\" rel=\"noreferrer\">Sed One-Liners Explained, Part I: File Spacing, Numbering and Text Conversion and Substitution</a>, <strong>39. Append a line to the next if it ends with a backslash &quot;\\&quot;</str...
Based on Sed One-Liners Explained, Part I: File Spacing, Numbering and Text Conversion and Substitution (https://catonmat.net/sed-one-liners-explained-part-one), 39. Append a line to the next if it ends with a backslash "\", but changing the backslash to comma and extending the substitution to include following whitesp...
# Join a number of lines with a starting and ending pattern **Tags:** <shell-script><sed> **Question (score 7):** I've a file like this: ``` method AAA one (1,111): some_text_1 method BBB two (2, 222): tuesday method CCC three (3, 333): sunny_day method DDD four (4, 444_a, 444_b): last_week ``` I want it to look lik...
3,338
834
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,202
unix.stackexchange.com
Pipe globs to ls
<p>Contents of file <code>filelist</code>:</p> <pre class="lang-none prettyprint-override"><code>/some/path/*.txt /other/path/*.dat /third/path/example.doc </code></pre> <p>I want to list those files, so I do:</p> <pre class="lang-bsh prettyprint-override"><code>cat filelist | xargs ls </code></pre> <p>But instead of e...
Contents of file `filelist`: ``` /some/path/*.txt /other/path/*.dat /third/path/example.doc ``` I want to list those files, so I do: ``` cat filelist | xargs ls ``` But instead of expanding those globs, I get: ``` ls: cannot access '/some/path/*.txt': No such file or directory ls: cannot access '/other/path/*.dat': No ...
6
600
3
2
0
[ "<linux><bash><pipe><ls><cat>" ]
2021-06-07T11:40:10.890
2021-06-07T18:15:07.963
291,147
653,208
[ { "id": 653208, "body": "<p>Shells expand globs. Here, that's one of the very rare cases where the implicit split+glob operator invoked upon unquoted command substitution in Bourne-like shells other than zsh can be useful:</p>\n<pre><code>IFS='\n' # split on newline only\nset +o noglob # make sure globbing ...
Shells expand globs. Here, that's one of the very rare cases where the implicit split+glob operator invoked upon unquoted command substitution in Bourne-like shells other than zsh can be useful: ``` IFS=' ' # split on newline only set +o noglob # make sure globbing is not disabled ls -ld -- $(cat filelist) # split+glob...
# Pipe globs to ls **Tags:** <linux><bash><pipe><ls><cat> **Question (score 6):** Contents of file `filelist`: ``` /some/path/*.txt /other/path/*.dat /third/path/example.doc ``` I want to list those files, so I do: ``` cat filelist | xargs ls ``` But instead of expanding those globs, I get: ``` ls: cannot access '/s...
4,577
1,144
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,265
unix.stackexchange.com
How to insert a line between consecutive duplicate lines?
<p>I want to add a dummy IP address but only after two consecutive duplicate lines are found.</p> <p>I am working on a Linux system and this is my input file:</p> <pre><code> IP_Remote_Address Address : 192.168.1.1 IP_Remote_Address Address : 192.168.1.2 IP_Remote_Address Address : 192.168.1.3 IP...
I want to add a dummy IP address but only after two consecutive duplicate lines are found. I am working on a Linux system and this is my input file: ``` IP_Remote_Address Address : 192.168.1.1 IP_Remote_Address Address : 192.168.1.2 IP_Remote_Address Address : 192.168.1.3 IP_Remote_Address IP_Remote_Address Address : 1...
5
597
3
3
0
[ "<text-processing><awk><sed>" ]
2021-06-07T19:28:53.720
2021-06-07T21:15:07.043
324,252
653,272
[ { "id": 653272, "body": "<p><code>awk</code>:</p>\n<pre><code>awk 'p==$0{print &quot; Address : NOT_FOUND&quot;}{p=$0}1'\n</code></pre>\n<p>A rather naive solution.</p>\n<ul>\n<li><code>p==$0</code> IF p == current line\n<ul>\n<li>THEN print <code>not found</code></li>\n</ul>\n</li>\n<li><code>p=$0</cod...
`awk`: ``` awk 'p==$0{print " Address : NOT_FOUND"}{p=$0}1' ``` A rather naive solution. - `p==$0` IF p == current line THEN print `not found` - `p=$0` SET p = current line - `1`: print Handles consecutive duplicate lines. And as noted by @san-fran (https://unix.stackexchange.com/users/315749/fra-san) in comments under...
# How to insert a line between consecutive duplicate lines? **Tags:** <text-processing><awk><sed> **Question (score 5):** I want to add a dummy IP address but only after two consecutive duplicate lines are found. I am working on a Linux system and this is my input file: ``` IP_Remote_Address Address : 192.168.1.1 IP...
4,501
1,125
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,413
unix.stackexchange.com
Show exit code of last command in Bash prompt if it returned error
<p>I've added the return value of the last command to <code>PS1</code> (aka &quot;the prompt&quot;) in my <code>.bashrc</code>.</p> <p>Now I'd like to have it shown only if the value is nonzero.</p> <p>Android's shell has it:</p> <pre><code>${| local e=$? (( e )) &amp;&amp; REPLY+=&quot;$e|&quot; return $e } </code></p...
I've added the return value of the last command to `PS1` (aka "the prompt") in my `.bashrc`. Now I'd like to have it shown only if the value is nonzero. Android's shell has it: ``` ${| local e=$? (( e )) && REPLY+="$e|" return $e } ``` Question: how to convert it to bash?
11
1,128
4
0
1
[ "<bash><shell><prompt>" ]
2021-06-08T15:29:47.793
2021-06-09T21:36:23.860
57,678
653,471
[ { "id": 653417, "body": "<pre><code>PS1='${?#0}$ '\n</code></pre>\n<p>It uses a special form of <a href=\"https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html\" rel=\"nofollow noreferrer\">parameter expansion</a>, <code>${?#0}</code>, which means: &quot;Remove the character zero...
``` PS1='${?#0}$ ' ``` It uses a special form of parameter expansion (https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html), `${?#0}`, which means: "Remove the character zero if it is the first character of `${?}`, the exit code of the previous command." You can also change the color of the...
# Show exit code of last command in Bash prompt if it returned error **Tags:** <bash><shell><prompt> **Question (score 11):** I've added the return value of the last command to `PS1` (aka "the prompt") in my `.bashrc`. Now I'd like to have it shown only if the value is nonzero. Android's shell has it: ``` ${| local ...
2,701
675
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,844
unix.stackexchange.com
How does `awk 'NF {p=1} p'` remove blank lines from the beginning and end of a file?
<p>Searching for a way to remove blank lines from the beginning and the end (using <code>tac</code>) of a file, I've stumbled across this one:</p> <pre><code>awk 'NF {p=1} p' </code></pre> <p>How / why does this work?</p> <p>I understand <code>NF</code> is only <code>true</code> if there are any fields (if the line is ...
Searching for a way to remove blank lines from the beginning and the end (using `tac`) of a file, I've stumbled across this one: ``` awk 'NF {p=1} p' ``` How / why does this work? I understand `NF` is only `true` if there are any fields (if the line is not a blank line).
5
1,052
7
1
1
[ "<text-processing><awk>" ]
2021-06-11T14:35:50.373
2021-07-23T15:47:09.243
477,032
653,848
[ { "id": 653848, "body": "<p>This will remove blank lines from the beginning, <strong>but not from the end</strong> of a file. <em>[Notice: this answer was witten before the <a href=\"https://unix.stackexchange.com/revisions/653844/4\">edit to the question</a> that mentioned <code>tac</code>]</em></p>\n<p>It...
This will remove blank lines from the beginning, but not from the end of a file. [Notice: this answer was witten before the edit to the question (https://unix.stackexchange.com/revisions/653844/4) that mentioned `tac`] It works as follows: - `NF` is the number of fields found on the current line. If it is zero, that me...
# How does `awk 'NF {p=1} p'` remove blank lines from the beginning and end of a file? **Tags:** <text-processing><awk> **Question (score 5):** Searching for a way to remove blank lines from the beginning and the end (using `tac`) of a file, I've stumbled across this one: ``` awk 'NF {p=1} p' ``` How / why does this...
4,415
1,103
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
653,919
unix.stackexchange.com
Why does adding a . in %s prevent the number from getting printed?
<p>I am trying to learn commands in Bash and came across these examples. Why does adding a <code>'.'</code> prevent the sequence number from getting printed?</p> <p>This is the behaviour I want, but I couldn't find anything on <a href="https://linux.die.net/man/1/printf" rel="nofollow noreferrer">the man page</a>.</p> ...
I am trying to learn commands in Bash and came across these examples. Why does adding a `'.'` prevent the sequence number from getting printed? This is the behaviour I want, but I couldn't find anything on the man page (https://linux.die.net/man/1/printf). ``` printf "%.sI" $(seq 10) ``` `IIIIIIIIII` ``` printf "%sI" $...
5
340
1
0
0
[ "<bash>" ]
2021-06-12T03:46:10.393
2021-06-12T15:01:28.417
144,663
653,922
[ { "id": 653922, "body": "<p><code>printf</code> allows you to specify a precision which is applicable even for strings:</p>\n<p>Relevant statements from the <a href=\"https://linux.die.net/man/3/printf\" rel=\"noreferrer\">printf(3) manpage</a>:</p>\n<blockquote>\n<p>An optional precision, in the form of a ...
`printf` allows you to specify a precision which is applicable even for strings: Relevant statements from the printf(3) manpage (https://linux.die.net/man/3/printf): An optional precision, in the form of a period ('.') followed by an optional decimal digit string. If the precision is given as just '.', or the precision...
# Why does adding a . in %s prevent the number from getting printed? **Tags:** <bash> **Question (score 5):** I am trying to learn commands in Bash and came across these examples. Why does adding a `'.'` prevent the sequence number from getting printed? This is the behaviour I want, but I couldn't find anything on t...
1,095
273
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,067
unix.stackexchange.com
What is more efficient or recommended for reading output of a command into variables in Bash?
<p>If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the examples below:</p> <ol> <li><code>IFS=: read user x1 uid gid x2 home shell &lt;&lt;&lt;$(grep :root: /etc/passwd | head -n1)</code></li> </ol> <p>and</p> <ol start="2"> <li><code>IFS=: ...
If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the examples below: - `IFS=: read user x1 uid gid x2 home shell <<<$(grep :root: /etc/passwd | head -n1)` and - `IFS=: read user x1 uid gid x2 home shell < <(grep :root: /etc/passwd | head -n1)...
6
795
2
1
3
[ "<linux><bash><process-substitution><here-string>" ]
2021-06-13T08:12:59.863
2021-06-14T12:40:05.317
330,980
654,070
[ { "id": 654070, "body": "<p>First note that using <code>read</code> without <code>-r</code> is to process input where <code>\\</code> is used to escape the field or line delimiters which is not the case of <code>/etc/passwd</code>. It's very rare that you would want to use <code>read</code> without <code>-r...
First note that using `read` without `-r` is to process input where `\` is used to escape the field or line delimiters which is not the case of `/etc/passwd`. It's very rare that you would want to use `read` without `-r`. Now as to those two forms, a note that neither are standard `sh` syntax. `<<<` is from `zsh` in 19...
# What is more efficient or recommended for reading output of a command into variables in Bash? **Tags:** <linux><bash><process-substitution><here-string> **Question (score 6):** If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the example...
3,589
897
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,187
unix.stackexchange.com
Command 'time' works on its own but not in a pipeline
<p>Consider the following:</p> <pre><code># time sleep 1 real 0m1.001s user 0m0.001s sys 0m0.000s # echo foo | time sleep 1 bash: time: command not found </code></pre> <p>Um... wut?</p> <p>OK, so <em>clearly</em> Bash is searching for commands in a somehow different way when run as a pipeline. Can anyone exp...
Consider the following: ``` # time sleep 1 real 0m1.001s user 0m0.001s sys 0m0.000s # echo foo | time sleep 1 bash: time: command not found ``` Um... wut? OK, so clearly Bash is searching for commands in a somehow different way when run as a pipeline. Can anyone explain to me what the difference is? Does piping disable...
11
847
2
6
2
[ "<bash><pipe><time>" ]
2021-06-14T10:11:42.027
2021-06-14T22:30:46.553
26,776
654,199
[ { "id": 654199, "body": "<p>The <code>bash</code> shell implements <code>time</code> as a keyword. The keyword is part of syntax of the pipeline.</p>\n<p>The syntax of a pipeline in <code>bash</code> is (from the section entitled &quot;<a href=\"https://www.gnu.org/software/bash/manual/html_node/Pipelines....
The `bash` shell implements `time` as a keyword. The keyword is part of syntax of the pipeline. The syntax of a pipeline in `bash` is (from the section entitled "Pipelines (https://www.gnu.org/software/bash/manual/html_node/Pipelines.html#Pipelines)" in the `bash` manual): ``` [time [-p]] [!] command1 [ | or |& command...
# Command 'time' works on its own but not in a pipeline **Tags:** <bash><pipe><time> **Question (score 11):** Consider the following: ``` # time sleep 1 real 0m1.001s user 0m0.001s sys 0m0.000s # echo foo | time sleep 1 bash: time: command not found ``` Um... wut? OK, so clearly Bash is searching for commands in a s...
2,351
587
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,189
unix.stackexchange.com
Tell Linux what to use swap for
<p>I am using Ubuntu 20.04 Server edition.</p> <p>I have a 512GB of RAM, with about 130GB typically used for a process running on the machine. I also have two ramdisks (tmpfs) both configured as 500GB.</p> <p>As tmpfs disks expand and contract the amount of RAM they use, depending on how full they are, typically the ra...
I am using Ubuntu 20.04 Server edition. I have a 512GB of RAM, with about 130GB typically used for a process running on the machine. I also have two ramdisks (tmpfs) both configured as 500GB. As tmpfs disks expand and contract the amount of RAM they use, depending on how full they are, typically the ramdisks use very l...
9
351
1
3
1
[ "<ubuntu><mount><swap><ram>" ]
2021-06-14T10:19:41.580
2021-06-14T11:39:28.550
389,886
null
[ { "id": 654195, "body": "<p>To the best of my knowledge (and FelixJN's link seems to agree), all things in RAM are equally swappable, and the decision what to swap is made on freshness, not on type of data. My guess is that this is a good heuristic, even for your use case!</p>\n<p>However, you can trick aro...
To the best of my knowledge (and FelixJN's link seems to agree), all things in RAM are equally swappable, and the decision what to swap is made on freshness, not on type of data. My guess is that this is a good heuristic, even for your use case! However, you can trick around, a bit, at least. Assuming your 512GB RAM ma...
# Tell Linux what to use swap for **Tags:** <ubuntu><mount><swap><ram> **Question (score 9):** I am using Ubuntu 20.04 Server edition. I have a 512GB of RAM, with about 130GB typically used for a process running on the machine. I also have two ramdisks (tmpfs) both configured as 500GB. As tmpfs disks expand and cont...
1,727
431
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,338
unix.stackexchange.com
No space left on device when moving 700k files to a single directory within the same FS
<p>I use the following command to find and move a huge number of files on my server:</p> <pre><code>find SomeDir/ -maxdepth 10 -type f -mtime +90 -exec mv {} SomeDir2/ \; </code></pre> <p>After moving about 700,000 files, I get this error:</p> <pre><code>mv: cannot move ‘SomeDir/Dir1/Dir2/Dir3/file.jpg.gz’ to ‘SomeDir2...
I use the following command to find and move a huge number of files on my server: ``` find SomeDir/ -maxdepth 10 -type f -mtime +90 -exec mv {} SomeDir2/ \; ``` After moving about 700,000 files, I get this error: ``` mv: cannot move ‘SomeDir/Dir1/Dir2/Dir3/file.jpg.gz’ to ‘SomeDir2/file.jpg.gz’: No space left on device...
5
171
2
20
0
[ "<find><disk-usage><mv>" ]
2021-06-15T10:49:02.817
2021-06-16T14:54:31.253
211,766
null
[ { "id": 654353, "body": "<p>You're probably exceedingt <code>max_dir_size_kb</code> set (or left default) at mount time of the directory:</p>\n<p><a href=\"https://www.kernel.org/doc/Documentation/filesystems/ext4.txt\" rel=\"nofollow noreferrer\">Linux docs</a>:</p>\n<blockquote>\n<pre><code>max_dir_size_k...
You're probably exceedingt `max_dir_size_kb` set (or left default) at mount time of the directory: Linux docs (https://www.kernel.org/doc/Documentation/filesystems/ext4.txt): ``` max_dir_size_kb=n This limits the size of the directories so that any attempt to expand them beyond the specified limit in kilobytes will cau...
# No space left on device when moving 700k files to a single directory within the same FS **Tags:** <find><disk-usage><mv> **Question (score 5):** I use the following command to find and move a huge number of files on my server: ``` find SomeDir/ -maxdepth 10 -type f -mtime +90 -exec mv {} SomeDir2/ \; ``` After mov...
2,039
509
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,455
unix.stackexchange.com
Upgrading manjaro system fails when install lib32-libcanberra
<p>I used <code>pacman -Syu</code> to upgrade my Manjaro system, but some new libraries like <code>lib32-libcanberra-pulse</code> and <code>libcanberra-pulse</code> failed to be installed due to the dependencies.</p> <p>I have tried twice whether the libraries are to be replaced or not, but both attempts fail. Details ...
I used `pacman -Syu` to upgrade my Manjaro system, but some new libraries like `lib32-libcanberra-pulse` and `libcanberra-pulse` failed to be installed due to the dependencies. I have tried twice whether the libraries are to be replaced or not, but both attempts fail. Details are shown below. How can I install these li...
22
10,628
1
0
3
[ "<upgrade><manjaro>" ]
2021-06-16T02:08:01.480
2021-06-21T20:27:17.483
441,457
654,460
[ { "id": 654460, "body": "<p>You need to read the <a href=\"https://forum.manjaro.org/t/stable-update-2021-06-14-kernels-browsers-mesa-deepin-systemd-gnome-apps-40-2-pipewire-haskell/70192/2\" rel=\"noreferrer\">announcements</a></p>\n<blockquote>\n<p>You might be blocked updating when using pacman due to so...
You need to read the announcements (https://forum.manjaro.org/t/stable-update-2021-06-14-kernels-browsers-mesa-deepin-systemd-gnome-apps-40-2-pipewire-haskell/70192/2) You might be blocked updating when using pacman due to some libcanberra packages. Simply remove those packages: sudo pacman -Rdd lib32-libcanberra-pulse...
# Upgrading manjaro system fails when install lib32-libcanberra **Tags:** <upgrade><manjaro> **Question (score 22):** I used `pacman -Syu` to upgrade my Manjaro system, but some new libraries like `lib32-libcanberra-pulse` and `libcanberra-pulse` failed to be installed due to the dependencies. I have tried twice whe...
2,800
700
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,484
unix.stackexchange.com
Why does the bash shebang work, but the sh shebang doesn't, for a string substitution
<p>I've been tracking down an issue I've been facing in a buildkite script, and here's what I've got:</p> <p>Firstly, I enter the shell of a docker image:</p> <pre><code>docker run --rm -it --entrypoint bash node:12.21.0 </code></pre> <p>This docker image doesn't have any text editors, so I create my shell scripts by c...
I've been tracking down an issue I've been facing in a buildkite script, and here's what I've got: Firstly, I enter the shell of a docker image: ``` docker run --rm -it --entrypoint bash node:12.21.0 ``` This docker image doesn't have any text editors, so I create my shell scripts by concating to a file: ``` touch a.sh...
5
1,727
2
2
2
[ "<bash><shell-script>" ]
2021-06-16T09:32:31.540
2021-06-16T15:02:51.780
209,769
654,486
[ { "id": 654486, "body": "<p><code>/bin/sh</code> is only expected to be a POSIX shell, and the POSIX shell <a href=\"https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02\" rel=\"noreferrer\">doesn’t know about substrings in parameter expansions</a>.</p>\n<p><a href=\"https:...
`/bin/sh` is only expected to be a POSIX shell, and the POSIX shell doesn’t know about substrings in parameter expansions (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02). POSIX (https://pubs.opengroup.org/onlinepubs/9699919799/) “defines a standard operating system interface and...
# Why does the bash shebang work, but the sh shebang doesn't, for a string substitution **Tags:** <bash><shell-script> **Question (score 5):** I've been tracking down an issue I've been facing in a buildkite script, and here's what I've got: Firstly, I enter the shell of a docker image: ``` docker run --rm -it --ent...
2,798
699
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,555
unix.stackexchange.com
Calling Linux kernel methods from a kernel module
<p>What is the right way of calling kernel functions in a C file from a kernel module in Linux?</p> <p>I want to call <code>exit_task_namespaces</code> in <code>linux/nsproxy.c</code> from my first ever kernel module</p> <p>I am doing this:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;linux/nsproxy.h...
What is the right way of calling kernel functions in a C file from a kernel module in Linux? I want to call `exit_task_namespaces` in `linux/nsproxy.c` from my first ever kernel module I am doing this: ``` #include … static ssize_t device_read(struct file *flip, char *buffer, size_t len, loff_t *offset) { struct task_s...
9
1,414
1
5
2
[ "<kernel-modules><c>" ]
2021-06-16T20:06:41.710
2021-06-17T18:29:17.547
401,549
654,564
[ { "id": 654564, "body": "<p>Modules can only access <a href=\"https://www.kernel.org/doc/html/latest/kernel-hacking/hacking.html#symbols\" rel=\"noreferrer\">exported symbols</a>, and <code>exit_task_namespaces</code> isn’t exported — so even though it is visible in the header files, it can’t be used in a m...
Modules can only access exported symbols (https://www.kernel.org/doc/html/latest/kernel-hacking/hacking.html#symbols), and `exit_task_namespaces` isn’t exported — so even though it is visible in the header files, it can’t be used in a module. Exported symbols can be accessed as you’d expect, there’s nothing special to ...
# Calling Linux kernel methods from a kernel module **Tags:** <kernel-modules><c> **Question (score 9):** What is the right way of calling kernel functions in a C file from a kernel module in Linux? I want to call `exit_task_namespaces` in `linux/nsproxy.c` from my first ever kernel module I am doing this: ``` #incl...
1,415
353
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,625
unix.stackexchange.com
Setting up vsftp
<p><strong>Beginner</strong></p> <p>Hi,</p> <p>So for a school assignment, I have to set up a FTP server (vsftp) on OpenSUSE. The teacher told us to use a chroot list, but whenever I use a chroot list, all users have full control over the whole filesystem. What am I doing wrong?</p> <p><strong>Situation</strong> A dire...
Beginner Hi, So for a school assignment, I have to set up a FTP server (vsftp) on OpenSUSE. The teacher told us to use a chroot list, but whenever I use a chroot list, all users have full control over the whole filesystem. What am I doing wrong? Situation A directory containing data. Inside of that directory are 2 othe...
6
93
1
0
0
[ "<chroot><vsftpd>" ]
2021-06-17T10:07:53.567
2021-06-17T10:52:34.717
477,826
654,633
[ { "id": 654633, "body": "<p>The documentation, as found with <code>man vsftpd.conf</code> writes the following,</p>\n<blockquote>\n<p><strong><code>chroot_list_enable</code></strong> If activated, you may provide a list of local users who are placed in a chroot() jail in their home directory upon login.</p...
The documentation, as found with `man vsftpd.conf` writes the following, `chroot_list_enable` If activated, you may provide a list of local users who are placed in a chroot() jail in their home directory upon login. OK so far. But it then continues, The meaning is slightly different if `chroot_local_user` is set to `YE...
# Setting up vsftp **Tags:** <chroot><vsftpd> **Question (score 6):** Beginner Hi, So for a school assignment, I have to set up a FTP server (vsftp) on OpenSUSE. The teacher told us to use a chroot list, but whenever I use a chroot list, all users have full control over the whole filesystem. What am I doing wrong? S...
2,584
646
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,689
unix.stackexchange.com
Regain sudo access after nuking secondary groups
<p>While setting up docker on Ubuntu 20.04 I did <code>sudo usermod -G docker $USER</code>. As noted in related questions here, I missed the <code>-a</code> flag and replaced all secondary groups. However, I didn't realize this until after I rebooted my machine. This is a single-user work station. I could fix this with...
While setting up docker on Ubuntu 20.04 I did `sudo usermod -G docker $USER`. As noted in related questions here, I missed the `-a` flag and replaced all secondary groups. However, I didn't realize this until after I rebooted my machine. This is a single-user work station. I could fix this with `root`, but I don't have...
11
992
2
3
1
[ "<ubuntu><sudo><group>" ]
2021-06-17T18:51:13.933
2021-06-18T17:44:13.433
21,888
654,697
[ { "id": 654697, "body": "<p>You still have one group left: <code>docker</code>. That means you still have control over the docker daemon. This daemon can run a container with the host's root filesystem <a href=\"https://docs.docker.com/storage/bind-mounts/\" rel=\"noreferrer\">mounted</a> and then the conta...
You still have one group left: `docker`. That means you still have control over the docker daemon. This daemon can run a container with the host's root filesystem mounted (https://docs.docker.com/storage/bind-mounts/) and then the container can edit files (`vi` is available in busybox) or simpler: can `chroot` to the h...
# Regain sudo access after nuking secondary groups **Tags:** <ubuntu><sudo><group> **Question (score 11):** While setting up docker on Ubuntu 20.04 I did `sudo usermod -G docker $USER`. As noted in related questions here, I missed the `-a` flag and replaced all secondary groups. However, I didn't realize this until ...
3,369
842
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,725
unix.stackexchange.com
How can I exclude all keys with a specific value inside a JSON with jq?
<p>Let's say I have a JSON like the following:</p> <pre><code>{ &quot;key1&quot;: { &quot;keyA&quot;: &quot;1&quot;, &quot;keyB&quot;: &quot;null&quot;, &quot;keyC&quot;: &quot;null&quot; }, &quot;key2&quot;: { &quot;keyA&quot;: &quot;null&quot;, &quot;keyB&quot;: &qu...
Let's say I have a JSON like the following: ``` { "key1": { "keyA": "1", "keyB": "null", "keyC": "null" }, "key2": { "keyA": "null", "keyB": "3", "keyC": "null" } } ``` I'd like to find a way of excluding all keys with the value `null` on my JSON. So the result would be the following: ``` { "key1": { "keyA": "1" }, "ke...
5
2,641
2
4
0
[ "<jq>" ]
2021-06-18T03:34:38.983
2021-06-18T17:04:54.303
444,310
654,730
[ { "id": 654730, "body": "<pre><code>del(..|select(. == &quot;null&quot;))\n</code></pre>\n<p>This uses the <a href=\"https://stedolan.github.io/jq/manual/#RecursiveDescent:..\" rel=\"noreferrer\">recursive-descent operator <code>..</code></a> and <a href=\"https://stedolan.github.io/jq/manual/#select(boolea...
``` del(..|select(. == "null")) ``` This uses the recursive-descent operator `..` (https://stedolan.github.io/jq/manual/#RecursiveDescent:..) and `select` function (https://stedolan.github.io/jq/manual/#select(boolean_expression)) to find all the locations anywhere in the object with values that are equal to `"null"` a...
# How can I exclude all keys with a specific value inside a JSON with jq? **Tags:** <jq> **Question (score 5):** Let's say I have a JSON like the following: ``` { "key1": { "keyA": "1", "keyB": "null", "keyC": "null" }, "key2": { "keyA": "null", "keyB": "3", "keyC": "null" } } ``` I'd like to find a way of excluding...
3,942
985
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
654,922
unix.stackexchange.com
'find -empty -delete' deletes non-empty directories
<p>If I create the following directory structure:</p> <pre><code>mkdir -p dir1/dir2/dir3/dir4 </code></pre> <p>then I run <code>find dir1</code>, it returns:</p> <pre><code>dir1 dir1/dir2 dir1/dir2/dir3 dir1/dir2/dir3/dir4 </code></pre> <p>If I run <code>find dir1 -empty</code>, it returns only:</p> <pre><code>dir1/dir...
If I create the following directory structure: ``` mkdir -p dir1/dir2/dir3/dir4 ``` then I run `find dir1`, it returns: ``` dir1 dir1/dir2 dir1/dir2/dir3 dir1/dir2/dir3/dir4 ``` If I run `find dir1 -empty`, it returns only: ``` dir1/dir2/dir3/dir4 ``` showing that only dir4 is empty. However, if I run `find dir1 -empty...
6
408
1
0
1
[ "<find>" ]
2021-06-19T13:10:17.030
2021-06-19T22:40:06.337
85,900
654,925
[ { "id": 654925, "body": "<p>Because <code>-delete</code> implies <code>-depth</code>, or depth-first iteration, so <code>find</code> first looks at <code>dir1/dir2/dir3/dir4</code>, notices it's empty, deletes it, then looks at <code>dir1/dir2/dir3</code>, notices it's (now) empty and deletes it...</p>\n<p>...
Because `-delete` implies `-depth`, or depth-first iteration, so `find` first looks at `dir1/dir2/dir3/dir4`, notices it's empty, deletes it, then looks at `dir1/dir2/dir3`, notices it's (now) empty and deletes it... The GNU manpage (https://manpages.debian.org/stretch/findutils/find.1.en.html) says: `-depth` Process e...
# 'find -empty -delete' deletes non-empty directories **Tags:** <find> **Question (score 6):** If I create the following directory structure: ``` mkdir -p dir1/dir2/dir3/dir4 ``` then I run `find dir1`, it returns: ``` dir1 dir1/dir2 dir1/dir2/dir3 dir1/dir2/dir3/dir4 ``` If I run `find dir1 -empty`, it returns only...
2,735
683
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,084
unix.stackexchange.com
Install make, gcc and similar on fresh Debian install without internet connection
<p>I'm a long time Fedora BFU and decided to switch to Debian for my new Dell XPS. Unfortunately, on a fresh install, I only get to work with a microscopic CLI and no internet connection, as both GPU and network card seem to need additional drivers to work. I found both drivers online, but I'm failing to install them.<...
I'm a long time Fedora BFU and decided to switch to Debian for my new Dell XPS. Unfortunately, on a fresh install, I only get to work with a microscopic CLI and no internet connection, as both GPU and network card seem to need additional drivers to work. I found both drivers online, but I'm failing to install them. GPU...
8
1,264
1
8
0
[ "<debian>" ]
2021-06-20T20:55:25.013
2021-06-22T17:28:23.650
478,273
655,088
[ { "id": 655088, "body": "<p>In your situation, I would install using <a href=\"https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/10.10.0+nonfree/amd64/iso-dvd/\" rel=\"nofollow noreferrer\">the unofficial, firmware-included full DVD</a> (which can also be used on a USB stick). Whi...
In your situation, I would install using the unofficial, firmware-included full DVD (https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/10.10.0+nonfree/amd64/iso-dvd/) (which can also be used on a USB stick). While labelled as “unofficial” this is still prepared by the same people who prepare ...
# Install make, gcc and similar on fresh Debian install without internet connection **Tags:** <debian> **Question (score 8):** I'm a long time Fedora BFU and decided to switch to Debian for my new Dell XPS. Unfortunately, on a fresh install, I only get to work with a microscopic CLI and no internet connection, as bo...
2,467
616
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,127
unix.stackexchange.com
Extract servers' blocks and values from Nginx conf
<p>How can we extract nginx server blocks using AWK? Input</p> <pre><code>server { # php/fastcgi listen 80; server_name domain1.com www.domain1.com; access_log logs/domain1.access.log main; root html; location ~ \.php$ { fastcgi_pass 127.0.0.1:1025; } } server { # simple reverse-proxy listen ...
How can we extract nginx server blocks using AWK? Input ``` server { # php/fastcgi listen 80; server_name domain1.com www.domain1.com; access_log logs/domain1.access.log main; root html; location ~ \.php$ { fastcgi_pass 127.0.0.1:1025; } } server { # simple reverse-proxy listen 80; server_name domain2.com www.domain2.c...
5
213
2
3
1
[ "<text-processing><awk><nginx>" ]
2021-06-21T07:48:19.080
2021-06-21T10:08:30.780
477,724
null
[ { "id": 655136, "body": "<p>Since you can have more than one space-separated value per line, using <code>awk</code> is a bit tricky. It is absolutely possible in awk, but it's simpler to use something like Perl instead:</p>\n<pre><code>$ perl -lne '\n if(/(^| )server / || eof){ \n print join &quot...
Since you can have more than one space-separated value per line, using `awk` is a bit tricky. It is absolutely possible in awk, but it's simpler to use something like Perl instead: ``` $ perl -lne ' if(/(^| )server / || eof){ print join " ",@ll if $ll[0]; @ll=(); } /^(listen|root|server_name)\s+(\S[^;]+)/ && push @ll,$...
# Extract servers' blocks and values from Nginx conf **Tags:** <text-processing><awk><nginx> **Question (score 5):** How can we extract nginx server blocks using AWK? Input ``` server { # php/fastcgi listen 80; server_name domain1.com www.domain1.com; access_log logs/domain1.access.log main; root html; location ~ \....
3,966
991
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,335
unix.stackexchange.com
How to update expired Skype signing key
<p>Yesterday, I received signature expired:</p> <pre class="lang-none prettyprint-override"><code>Err:24 https://repo.skype.com/deb stable InRelease The following signatures were invalid: EXPKEYSIG 1F3045A5DF7587C3 Skype Linux Client Repository &lt;se-um@microsoft.com&gt; </code></pre> <p...
Yesterday, I received signature expired: ``` Err:24 https://repo.skype.com/deb stable InRelease The following signatures were invalid: EXPKEYSIG 1F3045A5DF7587C3 Skype Linux Client Repository ``` Today the same problem, solutions? I'm on Linux Mint 20.1.
14
3,772
1
0
2
[ "<linux-mint><apt><gpg><skype>" ]
2021-06-22T16:52:41.657
2021-06-22T17:49:56.573
126,755
655,336
[ { "id": 655336, "body": "<p>The solution is pretty simple, Microsoft keeps their updated GPG signing key in this file: <a href=\"https://repo.skype.com/data/SKYPE-GPG-KEY\" rel=\"noreferrer\">https://repo.skype.com/data/SKYPE-GPG-KEY</a></p>\n<p>So, one can do for example:</p>\n<pre class=\"lang-none pretty...
The solution is pretty simple, Microsoft keeps their updated GPG signing key in this file: https://repo.skype.com/data/SKYPE-GPG-KEY (https://repo.skype.com/data/SKYPE-GPG-KEY) So, one can do for example: ``` curl -s https://repo.skype.com/data/SKYPE-GPG-KEY | sudo apt-key add - ``` Note: You should not implicitly trus...
# How to update expired Skype signing key **Tags:** <linux-mint><apt><gpg><skype> **Question (score 14):** Yesterday, I received signature expired: ``` Err:24 https://repo.skype.com/deb stable InRelease The following signatures were invalid: EXPKEYSIG 1F3045A5DF7587C3 Skype Linux Client Repository ``` Today the same...
947
236
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,470
unix.stackexchange.com
Handling 64-bit integers in a shell script
<p>I am trying to calculate the used bandwidth on the Ethernet interface (which is 1000 Mbit/s). To test my script, I am using the <a href="https://linux.die.net/man/1/iperf" rel="nofollow noreferrer">iperf</a> tool to generate huge bandwidths.</p> <p>The problem I am facing is when <code>eth0_rx1</code> and <code>eth0...
I am trying to calculate the used bandwidth on the Ethernet interface (which is 1000 Mbit/s). To test my script, I am using the iperf (https://linux.die.net/man/1/iperf) tool to generate huge bandwidths. The problem I am facing is when `eth0_rx1` and `eth0_rx2` gets the values which are greater than maximum 32-bit valu...
7
1,084
3
6
0
[ "<shell-script><arithmetic>" ]
2021-06-23T12:34:17.723
2021-06-24T15:17:13.473
450,545
655,471
[ { "id": 655471, "body": "<p>Given that <code>printf 'eth0 Download rate: %s B/s\\n' &quot;$((eth0_rx2-eth0_rx1))&quot;</code> is giving you the correct value, as long as integer arithmetic is good enough, you’ve got your answer: <code>$((eth0_rx2-eth0_rx1))</code>, <em>i.e.</em> <a href=\"https://www.gnu.or...
Given that `printf 'eth0 Download rate: %s B/s\n' "$((eth0_rx2-eth0_rx1))"` is giving you the correct value, as long as integer arithmetic is good enough, you’ve got your answer: `$((eth0_rx2-eth0_rx1))`, i.e. shell arithmetic (https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html). Many shells, nota...
# Handling 64-bit integers in a shell script **Tags:** <shell-script><arithmetic> **Question (score 7):** I am trying to calculate the used bandwidth on the Ethernet interface (which is 1000 Mbit/s). To test my script, I am using the iperf (https://linux.die.net/man/1/iperf) tool to generate huge bandwidths. The pro...
3,864
966
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,551
unix.stackexchange.com
Replace the nth-from-end occurrence of string in each line
<p>Using sed, how can I replace the Nth to last occurrence of a character on each line of a given file?</p> <p>In this case I want to replace the 3rd to last <code>;</code> with <code>,</code></p> <p>input</p> <pre><code>1;2;3;4;5;6;7;8;9 10;20;30;40;50;60;70;80;90 100;200;300;400;500;600;700;800;900 </code></pre> <p>e...
Using sed, how can I replace the Nth to last occurrence of a character on each line of a given file? In this case I want to replace the 3rd to last `;` with `,` input ``` 1;2;3;4;5;6;7;8;9 10;20;30;40;50;60;70;80;90 100;200;300;400;500;600;700;800;900 ``` expected output ``` 1;2;3;4;5;6,7;8;9 10;20;30;40;50;60,70;80;90...
9
1,222
6
0
0
[ "<debian><text-processing><sed>" ]
2021-06-23T20:31:16.653
2021-06-24T08:16:50.650
340,265
655,554
[ { "id": 655558, "body": "<p>You could simply reverse the lines, change the Nth occurrence, then re-reverse:</p>\n<pre><code> rev file | sed 's/;/,/3' | rev\n</code></pre>\n", "body_md": "You could simply reverse the lines, change the Nth occurrence, then re-reverse: ``` rev file | sed 's/;/,/3' | rev ``...
You could simply reverse the lines, change the Nth occurrence, then re-reverse: ``` rev file | sed 's/;/,/3' | rev ```
# Replace the nth-from-end occurrence of string in each line **Tags:** <debian><text-processing><sed> **Question (score 9):** Using sed, how can I replace the Nth to last occurrence of a character on each line of a given file? In this case I want to replace the 3rd to last `;` with `,` input ``` 1;2;3;4;5;6;7;8;9 10...
3,276
819
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,715
unix.stackexchange.com
Disambiguating the word "command" in Linux
<p>The word <em>command</em> refers to two different concepts in Linux:</p> <ol> <li>An executable program, such as <em>grep</em> (or a shell built-in, such as <em>cd</em>). Example usage: &quot;Here are the top 10 Linux commands you should learn.&quot;</li> <li>A full text string sent to the shell for execution, such ...
The word command refers to two different concepts in Linux: - An executable program, such as grep (or a shell built-in, such as cd). Example usage: "Here are the top 10 Linux commands you should learn." - A full text string sent to the shell for execution, such as grep com /etc/hosts. Example usage: "Type a Linux comma...
11
1,266
4
14
2
[ "<terminology>" ]
2021-06-24T19:30:34.313
2021-06-24T20:05:32.863
45,254
null
[ { "id": 655730, "body": "<p>POSIX <strong>refers to the things that are like <code>grep</code> and <code>cd</code> as &quot;<a href=\"https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_439\" rel=\"noreferrer\">utilities</a>&quot;</strong>, and <strong>reserves &quot;<a href=\"ht...
POSIX refers to the things that are like `grep` and `cd` as "utilities (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_439)", and reserves "command (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_104)" for the instructions. Used consistently, these terms...
# Disambiguating the word "command" in Linux **Tags:** <terminology> **Question (score 11):** The word command refers to two different concepts in Linux: - An executable program, such as grep (or a shell built-in, such as cd). Example usage: "Here are the top 10 Linux commands you should learn." - A full text string...
8,756
2,189
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,796
unix.stackexchange.com
Why is mawk's output (STDOUT) buffered even though it is the terminal?
<p>I am aware that <code>STDOUT</code> is usually buffered by commands like <code>mawk</code> (but not <code>gawk</code>), <code>grep</code>, <code>sed</code>, and so on, unless used with the appropriate options (i.e. <code>mawk --Winteractive</code>, or <code>grep --line-buffered</code>, or <code>sed --unbuffered</cod...
I am aware that `STDOUT` is usually buffered by commands like `mawk` (but not `gawk`), `grep`, `sed`, and so on, unless used with the appropriate options (i.e. `mawk --Winteractive`, or `grep --line-buffered`, or `sed --unbuffered`). But the buffering doesn't happen when `STDOUT` is a terminal/tty, in which case it is ...
5
236
1
2
0
[ "<shell><awk><stdout><buffer>" ]
2021-06-25T11:46:37.013
2021-06-25T13:28:46.133
152,418
655,807
[ { "id": 655807, "body": "<p>It's not that it's buffering its <strong>output</strong>.</p>\n<p><code>mawk</code> is the only utility that I know that buffers its <strong>input</strong>.</p>\n<p>See also <a href=\"https://github.com/ThomasDickey/original-mawk/issues/41#issuecomment-241070898\" rel=\"noreferre...
It's not that it's buffering its output. `mawk` is the only utility that I know that buffers its input. See also https://github.com/ThomasDickey/original-mawk/issues/41#issuecomment-241070898 (https://github.com/ThomasDickey/original-mawk/issues/41#issuecomment-241070898) In other words, `mawk` will not start processin...
# Why is mawk's output (STDOUT) buffered even though it is the terminal? **Tags:** <shell><awk><stdout><buffer> **Question (score 5):** I am aware that `STDOUT` is usually buffered by commands like `mawk` (but not `gawk`), `grep`, `sed`, and so on, unless used with the appropriate options (i.e. `mawk --Winteractive`...
2,242
560
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,827
unix.stackexchange.com
How to search for multiline text files containing a set of words (e.g., AAA & (BBB | CCC) & ~DD)?
<p>I need to find the files that fulfill relatively complex condition. For example, I want to find all files that fulfill all below conditions:</p> <ul> <li>does contain word AAAA</li> <li>does contain word BBB or CCCCC (may contain both of them)</li> <li>does not contain word DDD</li> </ul> <p>The words may appear in ...
I need to find the files that fulfill relatively complex condition. For example, I want to find all files that fulfill all below conditions: - does contain word AAAA - does contain word BBB or CCCCC (may contain both of them) - does not contain word DDD The words may appear in any order and may appear in different line...
9
457
3
3
1
[ "<grep><find><search><text>" ]
2021-06-25T15:32:38.850
2021-07-19T20:34:34.613
60,841
655,837
[ { "id": 655837, "body": "<p>Your solution is pretty legible for the task, in my opinion. However, it's slow, because it spawns 3 processes per file. I reckon Awk is better suited here because it will allow to read a whole batch of files (as allowed by ARG_MAX) in a single go, using <code>{} +</code> instead...
Your solution is pretty legible for the task, in my opinion. However, it's slow, because it spawns 3 processes per file. I reckon Awk is better suited here because it will allow to read a whole batch of files (as allowed by ARG_MAX) in a single go, using `{} +` instead of `{} \;`. GNU Awk: ``` find . -type f -exec gawk...
# How to search for multiline text files containing a set of words (e.g., AAA & (BBB | CCC) & ~DD)? **Tags:** <grep><find><search><text> **Question (score 9):** I need to find the files that fulfill relatively complex condition. For example, I want to find all files that fulfill all below conditions: - does contain ...
2,350
587
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
655,974
unix.stackexchange.com
Automatically running code before closing SSH connection
<p>I'm remotely connecting to a shared server and I would like to have a line of code executed automatically in the remote machine <strong>before</strong> I close the connection (e.g. by pressing Ctrl+D).</p> <p>More specifically, I'd like to kill the SSH agent before I leave, as I noticed it keeps running even after I...
I'm remotely connecting to a shared server and I would like to have a line of code executed automatically in the remote machine before I close the connection (e.g. by pressing Ctrl+D). More specifically, I'd like to kill the SSH agent before I leave, as I noticed it keeps running even after I'm gone. The agent is start...
7
463
1
2
1
[ "<ssh><ssh-agent>" ]
2021-06-27T03:31:35.200
2021-06-27T05:20:15.560
201,272
655,975
[ { "id": 655975, "body": "<p>You can set a <code>trap</code> in <code>.bashrc</code> that runs when <a href=\"https://unix.stackexchange.com/q/17314/140633\">shell exits</a>:</p>\n<p>Something like</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>trap 'test -n &quot;$SSH_AGENT_PID&quot; &amp;&amp; eva...
You can set a `trap` in `.bashrc` that runs when shell exits (https://unix.stackexchange.com/q/17314/140633): Something like ``` trap 'test -n "$SSH_AGENT_PID" && eval "$(/usr/bin/ssh-agent -k)"' 0 ``` Optionally add a routine in `.bash_logout`
# Automatically running code before closing SSH connection **Tags:** <ssh><ssh-agent> **Question (score 7):** I'm remotely connecting to a shared server and I would like to have a line of code executed automatically in the remote machine before I close the connection (e.g. by pressing Ctrl+D). More specifically, I'd...
1,235
308
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,005
unix.stackexchange.com
What does “Case sensitivity is a function of the Linux filesystem not the Linux operating system” mean?
<p>I just read the following sentence:</p> <blockquote> <p>Case Sensitivity is a function of the Linux filesystem NOT the Linux operating system.</p> </blockquote> <p>What I deduced from this sentence is if I'm on a Linux machine but I am working with a device formatted using the Windows File System, then case sensitiv...
I just read the following sentence: Case Sensitivity is a function of the Linux filesystem NOT the Linux operating system. What I deduced from this sentence is if I'm on a Linux machine but I am working with a device formatted using the Windows File System, then case sensitivity will NOT be a thing. I tried the followi...
15
4,509
6
4
1
[ "<bash><filesystems><zsh><case-sensitivity>" ]
2021-06-27T10:16:36.727
2021-06-29T11:52:18.130
479,172
656,019
[ { "id": 656019, "body": "<p>Here, you're running:</p>\n<pre><code>ls te*\n</code></pre>\n<p>Using a feature of your <em>shell</em> called <em>globbing</em> or <em>filename generation</em> (pathname expansion in POSIX), not of the Linux system nor of any filesystem used on Linux.</p>\n<p><code>te*</code> is ...
Here, you're running: ``` ls te* ``` Using a feature of your shell called globbing or filename generation (pathname expansion in POSIX), not of the Linux system nor of any filesystem used on Linux. `te*` is expanded by the shell to the list of files that match that pattern. To do that, the shell requests the list of en...
# What does “Case sensitivity is a function of the Linux filesystem not the Linux operating system” mean? **Tags:** <bash><filesystems><zsh><case-sensitivity> **Question (score 15):** I just read the following sentence: Case Sensitivity is a function of the Linux filesystem NOT the Linux operating system. What I ded...
5,380
1,345
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,179
unix.stackexchange.com
Bash variables do not expand inside array if declare is used
<p>Recently I decided to read a bit more on the bash built-ins <code>declare</code>, <code>local</code>, and <code>readonly</code>, which led me to switch from:</p> <pre><code>local variable_name variable_name='value' readonly variable_name </code></pre> <p>To:</p> <pre><code>variable_name='value' declare -r variable_n...
Recently I decided to read a bit more on the bash built-ins `declare`, `local`, and `readonly`, which led me to switch from: ``` local variable_name variable_name='value' readonly variable_name ``` To: ``` variable_name='value' declare -r variable_name ``` This change cut down the number of lines written and allowed me...
7
449
2
3
0
[ "<bash><shell-script><curl><array><readonly>" ]
2021-06-28T16:00:27.230
2021-06-28T16:16:54.297
479,351
656,181
[ { "id": 656181, "body": "<p>With:</p>\n<blockquote>\n<pre><code>curl_version=&quot;$(command curl --version | awk 'NR==1 {print $2}')&quot;\ndeclare -r curl_version\n</code></pre>\n</blockquote>\n<p>within a function, you're setting the <code>$curl_version</code> global variable to some value and then creat...
With: ``` curl_version="$(command curl --version | awk 'NR==1 {print $2}')" declare -r curl_version ``` within a function, you're setting the `$curl_version` global variable to some value and then creating a separate local and readonly variable which is initially unset. It looks like you want: ``` # instantiate a new l...
# Bash variables do not expand inside array if declare is used **Tags:** <bash><shell-script><curl><array><readonly> **Question (score 7):** Recently I decided to read a bit more on the bash built-ins `declare`, `local`, and `readonly`, which led me to switch from: ``` local variable_name variable_name='value' reado...
4,922
1,230
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,205
unix.stackexchange.com
sks-keyservers gone. What to use instead?
<p><a href="https://sks-keyservers.net/" rel="noreferrer">https://sks-keyservers.net/</a> says</p> <blockquote> <p>This service is deprecated. This means it is no longer maintained, and new HKPS certificates will not be issued. Service reliability should not be expected.</p> <p>Update 2021-06-21: Due to even more GDPR ...
https://sks-keyservers.net/ (https://sks-keyservers.net/) says This service is deprecated. This means it is no longer maintained, and new HKPS certificates will not be issued. Service reliability should not be expected. Update 2021-06-21: Due to even more GDPR takedown requests, the DNS records for the pool will no lon...
15
2,582
4
0
4
[ "<gpg><pgp>" ]
2021-06-28T18:57:21.103
2021-10-06T15:18:06.363
2,972
663,037
[ { "id": 656210, "body": "<blockquote>\n<p>Which keyservers can I use for <code>gpg --keyserver &quot;$keyserver1&quot; --recv-key keyid</code> that I can expect not will go away anytime soon?</p>\n</blockquote>\n<p>The recommendation is to use <code>keys.openpgp.org</code>, however this keyserver only inclu...
Which keyservers can I use for `gpg --keyserver "$keyserver1" --recv-key keyid` that I can expect not will go away anytime soon? The recommendation is to use `keys.openpgp.org`, however this keyserver only includes User IDs for keys whose owners have personally confirmed via email (basically eliminating large swaths of...
# sks-keyservers gone. What to use instead? **Tags:** <gpg><pgp> **Question (score 15):** https://sks-keyservers.net/ (https://sks-keyservers.net/) says This service is deprecated. This means it is no longer maintained, and new HKPS certificates will not be issued. Service reliability should not be expected. Update ...
2,072
518
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,291
unix.stackexchange.com
Tape readable with scsitape but not dd or tar, why?
<p>I just installed an Exabyte tape drive:</p> <pre><code>$ lsscsi -g [11:0:0:0] process Marvell 91xx Config 1.01 - /dev/sg0 [12:0:1:0] cd/dvd TOSHIBA CD-ROM XM-3401TA 0283 /dev/sr0 /dev/sg1 [12:0:5:0] tape EXABYTE EXB-8500-85Qanx0 046G /dev/st0 /dev/sg2 [N:1:4:1] disk Samsung...
I just installed an Exabyte tape drive: ``` $ lsscsi -g [11:0:0:0] process Marvell 91xx Config 1.01 - /dev/sg0 [12:0:1:0] cd/dvd TOSHIBA CD-ROM XM-3401TA 0283 /dev/sr0 /dev/sg1 [12:0:5:0] tape EXABYTE EXB-8500-85Qanx0 046G /dev/st0 /dev/sg2 [N:1:4:1] disk Samsung SSD 970 EVO 250GB__1 /dev/nvme1n1 [N:0:4:1] disk Samsung...
7
505
1
0
1
[ "<scsi><tape>" ]
2021-06-29T12:29:34.663
2021-06-29T13:54:36.223
1,639
null
[ { "id": 656292, "body": "<p>It turns out that the tape was written with a fixed block size, and using the <code>mt</code> command from the <code>mt-st</code> package allows us to accommodate this:</p>\n<pre><code>$ mt -f /dev/nst0 rewind\n$ mt -f /dev/nst0 setblk 10240\n$ tar -f /dev/nst0 -t\n[ files list...
It turns out that the tape was written with a fixed block size, and using the `mt` command from the `mt-st` package allows us to accommodate this: ``` $ mt -f /dev/nst0 rewind $ mt -f /dev/nst0 setblk 10240 $ tar -f /dev/nst0 -t [ files list normally ] ``` 10240 here corresponds to 20 blocks of 512 bytes (20 is the tra...
# Tape readable with scsitape but not dd or tar, why? **Tags:** <scsi><tape> **Question (score 7):** I just installed an Exabyte tape drive: ``` $ lsscsi -g [11:0:0:0] process Marvell 91xx Config 1.01 - /dev/sg0 [12:0:1:0] cd/dvd TOSHIBA CD-ROM XM-3401TA 0283 /dev/sr0 /dev/sg1 [12:0:5:0] tape EXABYTE EXB-8500-85Qanx...
2,816
704
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,328
unix.stackexchange.com
"[libseat/backend/seatd.c:70] Could not connect to socket /run/seatd.sock: no such file or directory" after updating wlroots, Sway and libseat on Arch
<p>I just updated my system, there were only three updates available: <code>wlroots</code>, <code>sway</code> and <code>libseat</code>.</p> <p>I don't have a display manager installed and before loading Sway I'm shown this:</p> <p><code>[wlr] [libseat] [libseat/backend/seatd.c:70] Could not connect to socket /run/seatd...
I just updated my system, there were only three updates available: `wlroots`, `sway` and `libseat`. I don't have a display manager installed and before loading Sway I'm shown this: `[wlr] [libseat] [libseat/backend/seatd.c:70] Could not connect to socket /run/seatd.sock: no such file or directory` I've never had such a...
6
3,554
1
1
1
[ "<arch-linux><sway>" ]
2021-06-29T19:01:45.010
2021-07-06T12:18:43.970
null
657,578
[ { "id": 657578, "body": "<p>Problem solved by adding <code>LIBSEAT_BACKEND=logind</code> to my <code>/etc/environment</code> file. I don't know if it's the correct way to fix the warning message but it worked. It seems like wlroots dropped logind dependency and rely on libseat for seat management. I learned...
Problem solved by adding `LIBSEAT_BACKEND=logind` to my `/etc/environment` file. I don't know if it's the correct way to fix the warning message but it worked. It seems like wlroots dropped logind dependency and rely on libseat for seat management. I learned this from a user in the Arch room on Matrix.
# "[libseat/backend/seatd.c:70] Could not connect to socket /run/seatd.sock: no such file or directory" after updating wlroots, Sway and libseat on Arch **Tags:** <arch-linux><sway> **Question (score 6):** I just updated my system, there were only three updates available: `wlroots`, `sway` and `libseat`. I don't hav...
881
220
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,465
unix.stackexchange.com
ls formatting inside watch command
<p>When I do <code>ls /dev/tty*</code>, I see the following output:</p> <pre><code>/dev/tty /dev/tty12 /dev/tty17 /dev/tty21 /dev/tty26 /dev/tty30 /dev/tty35 /dev/tty4 /dev/tty44 /dev/tty49 /dev/tty53 /dev/tty58 /dev/tty62 /dev/ttyS0 /dev/tty0 /dev/tty13 /dev/tty18 /dev/tty22 /dev/tty27 /dev/tty31...
When I do `ls /dev/tty*`, I see the following output: ``` /dev/tty /dev/tty12 /dev/tty17 /dev/tty21 /dev/tty26 /dev/tty30 /dev/tty35 /dev/tty4 /dev/tty44 /dev/tty49 /dev/tty53 /dev/tty58 /dev/tty62 /dev/ttyS0 /dev/tty0 /dev/tty13 /dev/tty18 /dev/tty22 /dev/tty27 /dev/tty31 /dev/tty36 /dev/tty40 /dev/tty45 /dev/tty5 /de...
9
425
2
2
0
[ "<linux><bash><shell><ls><watch>" ]
2021-06-30T18:10:41.253
2021-07-08T10:54:57.237
165,555
656,471
[ { "id": 656471, "body": "<blockquote>\n<p>What is the reason?</p>\n</blockquote>\n<p>When <code>watch</code> executes commands they are not connected to the\nterminal. In other words, <code>isatty(3)</code> returns 0. You can use the\nfollowing isatty.c to check if a command is connected to the terminal\nwh...
What is the reason? When `watch` executes commands they are not connected to the terminal. In other words, `isatty(3)` returns 0. You can use the following isatty.c to check if a command is connected to the terminal when it's ran: ``` #include #include #include int main(void) { printf("%d\n", isatty(STDOUT_FILENO)); re...
# ls formatting inside watch command **Tags:** <linux><bash><shell><ls><watch> **Question (score 9):** When I do `ls /dev/tty*`, I see the following output: ``` /dev/tty /dev/tty12 /dev/tty17 /dev/tty21 /dev/tty26 /dev/tty30 /dev/tty35 /dev/tty4 /dev/tty44 /dev/tty49 /dev/tty53 /dev/tty58 /dev/tty62 /dev/ttyS0 /dev/...
2,084
521
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,740
unix.stackexchange.com
Remove all sub-fields in column-organized datafile that contain "_XX"
<p>I have this type of file</p> <pre><code>#CHROM POS ID REF ALT QUAL FILTER INFO chr1 69511 rs2691305 A G . PASS AC=70482;AN=83312;AF=0.846001;popmax=eas;faf95_popmax=0.975176;AC_non_v2_XX=28734;AN_non_v2_XX=33774;AF_non_v2_XX=0.850773;nhomalt_non_v2_XX=13253;AC_no...
I have this type of file ``` #CHROM POS ID REF ALT QUAL FILTER INFO chr1 69511 rs2691305 A G . PASS AC=70482;AN=83312;AF=0.846001;popmax=eas;faf95_popmax=0.975176;AC_non_v2_XX=28734;AN_non_v2_XX=33774;AF_non_v2_XX=0.850773;nhomalt_non_v2_XX=13253;AC_non_cancer_fin_XX=1080;AN_non_cancer_fin_XX=1090;AF_non_cancer_fin_XX=...
6
239
5
4
0
[ "<text-processing><sed><bioinformatics>" ]
2021-07-02T15:57:28.283
2021-07-03T01:04:10.153
479,981
null
[ { "id": 656742, "body": "<p>Here is the solution:</p>\n<pre><code>sed 's/;[^;]*_XX[^;]*//g'\n</code></pre>\n<p>You need to look for <code>_XX</code> within two <code>;</code>s and so, you should let every other character pass.</p>\n", "body_md": "Here is the solution: ``` sed 's/;[^;]*_XX[^;]*//g' ``` Y...
Here is the solution: ``` sed 's/;[^;]*_XX[^;]*//g' ``` You need to look for `_XX` within two `;`s and so, you should let every other character pass.
# Remove all sub-fields in column-organized datafile that contain "_XX" **Tags:** <text-processing><sed><bioinformatics> **Question (score 6):** I have this type of file ``` #CHROM POS ID REF ALT QUAL FILTER INFO chr1 69511 rs2691305 A G . PASS AC=70482;AN=83312;AF=0.846001;popmax=eas;faf95_popmax=0.975176;AC_non_v2...
8,419
2,104
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
656,859
unix.stackexchange.com
Detect if a script is being run via shebang or was specified as a command line argument
<p>In the Pyenv project, we've had a peculiar problem.</p> <p>We are substituting <code>python</code> (and <code>python*</code>) with our Bash scripts (&quot;shims&quot;) that select a Python executable to run at runtime.</p> <p>Now, <a href="https://github.com/pyenv/pyenv/issues/1813" rel="nofollow noreferrer">some us...
In the Pyenv project, we've had a peculiar problem. We are substituting `python` (and `python*`) with our Bash scripts ("shims") that select a Python executable to run at runtime. Now, some users wish to use a special selection logic (https://github.com/pyenv/pyenv/issues/1813) when a Python script is run as `path/to/s...
6
244
1
5
1
[ "<bash><shebang>" ]
2021-07-03T14:37:39.427
2021-07-03T15:40:33.100
23,609
656,866
[ { "id": 656866, "body": "<blockquote>\n<p>Since shebang is a Linux kernel feature -- maybe it sets some indicator that this mechanism has been used?</p>\n</blockquote>\n<p>Yes, it does. Linux sets the <code>AT_EXECFN</code> auxiliar vector entry to the path of the original executable. In C, you can do it wi...
Since shebang is a Linux kernel feature -- maybe it sets some indicator that this mechanism has been used? Yes, it does. Linux sets the `AT_EXECFN` auxiliar vector entry to the path of the original executable. In C, you can do it with `char *at_execfn = (char*)getauxval(AT_EXECFN)`, followed by `stat(at_execfn)`, etc. ...
# Detect if a script is being run via shebang or was specified as a command line argument **Tags:** <bash><shebang> **Question (score 6):** In the Pyenv project, we've had a peculiar problem. We are substituting `python` (and `python*`) with our Bash scripts ("shims") that select a Python executable to run at runtim...
2,226
556
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,060
unix.stackexchange.com
List all files with extensions .tif, .tiff, .TIF, .TIFF
<p>Given a nested directory, I would like to list all tif files with extension <code>.tif</code>, <code>.TIF</code>, <code>.tiff</code>, <code>.TIFF</code>.</p> <p>Currently I'm using</p> <pre><code>find . -type f -iname *.TIF -print ; find . -type f -iname *.TIFF -print; </code></pre> <p>Using <code>-iname</code> allo...
Given a nested directory, I would like to list all tif files with extension `.tif`, `.TIF`, `.tiff`, `.TIFF`. Currently I'm using ``` find . -type f -iname *.TIF -print ; find . -type f -iname *.TIFF -print; ``` Using `-iname` allows me to be case-insensitive but it goes through the directory twice to get files with `....
13
2,276
3
6
2
[ "<bash><find><filenames>" ]
2021-07-05T10:49:30.660
2021-07-06T16:28:30.320
480,275
657,061
[ { "id": 657061, "body": "<p><code>find</code> supports an “or” disjunction, <code>-o</code>:</p>\n<pre><code>find . -type f \\( -iname \\*.tif -o -iname \\*.tiff \\)\n</code></pre>\n<p>This will list all files whose name matches <code>*.tif</code> or <code>*.tiff</code>, ignoring case.</p>\n<p><code>-print<...
`find` supports an “or” disjunction, `-o`: ``` find . -type f \( -iname \*.tif -o -iname \*.tiff \) ``` This will list all files whose name matches `*.tif` or `*.tiff`, ignoring case. `-print` is the default action so it doesn’t need to be specified here. `*`, `(`, and `)` are escaped so that they lose their significan...
# List all files with extensions .tif, .tiff, .TIF, .TIFF **Tags:** <bash><find><filenames> **Question (score 13):** Given a nested directory, I would like to list all tif files with extension `.tif`, `.TIF`, `.tiff`, `.TIFF`. Currently I'm using ``` find . -type f -iname *.TIF -print ; find . -type f -iname *.TIFF ...
1,302
325
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,341
unix.stackexchange.com
Extract values from a string that follow a specific word using sed
<p>I'd like to extract only a specific value from command output.</p> <p>The string that the command returns is something like this:</p> <pre><code>Result: &quot; 5 Secs (11.2345%) 60 Secs (22.3456%) 300 Secs (33.4567%)&quot; </code></pre> <p>And I want to filter only the &quot;60 Secs&quot; value between ()</p> <pre><...
I'd like to extract only a specific value from command output. The string that the command returns is something like this: ``` Result: " 5 Secs (11.2345%) 60 Secs (22.3456%) 300 Secs (33.4567%)" ``` And I want to filter only the "60 Secs" value between () ``` 22.3456% ``` How can I do that?
5
376
4
1
0
[ "<sed><filter>" ]
2021-07-07T11:12:58.040
2021-07-08T08:30:12.413
480,595
657,343
[ { "id": 657343, "body": "<p>If that is the exact string that the command returns, then <code>sed</code> will work.</p>\n<pre><code>command_output | sed 's/.*60 Secs..\\(.*\\)..300.*/\\1/'\n</code></pre>\n<p>That prints everything between <code>60 Secs (</code> and <code>) 300</code>.</p>\n<p>Result:</p>\n<p...
If that is the exact string that the command returns, then `sed` will work. ``` command_output | sed 's/.*60 Secs..\(.*\)..300.*/\1/' ``` That prints everything between `60 Secs (` and `) 300`. Result: ``` 22.3456% ```
# Extract values from a string that follow a specific word using sed **Tags:** <sed><filter> **Question (score 5):** I'd like to extract only a specific value from command output. The string that the command returns is something like this: ``` Result: " 5 Secs (11.2345%) 60 Secs (22.3456%) 300 Secs (33.4567%)" ``` A...
1,850
462
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,359
unix.stackexchange.com
How would I replace two or more blank lines with a single blank line in Ed?
<p>In Ed I can do a search to replace all blank lines as follows:</p> <pre><code>g/^$/d </code></pre> <p>This deletes all blank lines. But what if I wish to delete two or more blank lines and keep 1? For example:</p> <pre><code>Line 1 Line 2 Line 3 </code></pre> <p>Becomes:</p> <pre><code>Line 1 Line 2 Line 3 </...
In Ed I can do a search to replace all blank lines as follows: ``` g/^$/d ``` This deletes all blank lines. But what if I wish to delete two or more blank lines and keep 1? For example: ``` Line 1 Line 2 Line 3 ``` Becomes: ``` Line 1 Line 2 Line 3 ```
9
393
2
2
0
[ "<regular-expression><ed>" ]
2021-07-07T12:57:44.547
2021-07-08T09:49:27.327
321,709
657,378
[ { "id": 657378, "body": "<p>Adapted from the <a href=\"https://vim.fandom.com/wiki/Best_Vim_Tips#Global_command\" rel=\"nofollow noreferrer\">Vim Wiki</a>:</p>\n<pre><code>ed -s file &lt;&lt;EOF\nv/./.,/./-1j\nw\nq\nEOF\n</code></pre>\n<ul>\n<li><code>v/./</code>: select all lines that don't match the regex...
Adapted from the Vim Wiki (https://vim.fandom.com/wiki/Best_Vim_Tips#Global_command): ``` ed -s file - `v/./`: select all lines that don't match the regex `.` (i.e., select all blank lines). Execute the following action on them: `.,/./-1j`: the `j`oin command is applied from a selected line (`.`) up to the the line abo...
# How would I replace two or more blank lines with a single blank line in Ed? **Tags:** <regular-expression><ed> **Question (score 9):** In Ed I can do a search to replace all blank lines as follows: ``` g/^$/d ``` This deletes all blank lines. But what if I wish to delete two or more blank lines and keep 1? For exa...
2,410
602
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,648
unix.stackexchange.com
Prevent the second command from starting in the bash pipe if the first command fails
<p>After learning (more or less) some useful discussions about pipes like <a href="https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another">Get exit status of process that's piped to another</a> and <a href="https://stackoverflow.com/questions/32684119/exit-when-one-process-in-p...
After learning (more or less) some useful discussions about pipes like Get exit status of process that's piped to another (https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another) and Exit when one process in pipe fails (https://stackoverflow.com/questions/32684119/exit-when-one...
11
1,186
5
3
1
[ "<bash><zsh><pipe>" ]
2021-07-09T12:24:41.327
2021-07-09T13:06:12.363
83,728
null
[ { "id": 657653, "body": "<p>Yes, there is a bit of a fundamental detail about pipes there.</p>\n<p>The point of a pipeline is to run the two or more commands in parallel, which avoids having to store all the data in full and can save time in that all processes can work at the same time. This by definition m...
Yes, there is a bit of a fundamental detail about pipes there. The point of a pipeline is to run the two or more commands in parallel, which avoids having to store all the data in full and can save time in that all processes can work at the same time. This by definition means that the second command starts before the f...
# Prevent the second command from starting in the bash pipe if the first command fails **Tags:** <bash><zsh><pipe> **Question (score 11):** After learning (more or less) some useful discussions about pipes like Get exit status of process that's piped to another (https://unix.stackexchange.com/questions/14270/get-exi...
2,938
734
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,656
unix.stackexchange.com
For loop over lines -- how to set IFS only for one `for` statement?
<p>Here is an example of behavior I want to achieve:</p> <p>Suppose I have a list of lines, each line containing space separated values:</p> <pre><code>lines='John Smith James Johnson' </code></pre> <p>And I want to loop over lines echoing name or surname only as user asked by prompt, so I change IFS globally:</p> <pre...
Here is an example of behavior I want to achieve: Suppose I have a list of lines, each line containing space separated values: ``` lines='John Smith James Johnson' ``` And I want to loop over lines echoing name or surname only as user asked by prompt, so I change IFS globally: ``` oIFS=$IFS IFS=' ' for line in $lines; ...
5
336
2
0
0
[ "<bash>" ]
2021-07-09T13:40:40.450
2021-07-10T16:41:23.407
305,248
null
[ { "id": 657661, "body": "<p>You could read the input lines to an array first with <code>mapfile</code>/<code>readarray</code>:</p>\n<pre><code>lines='John Smith\nJames Johnson'\nmapfile -t lines &lt;&lt;&lt; &quot;$lines&quot;\nfor line in &quot;${lines[@]}&quot;; do\n read name surname &lt;&lt;&lt; &quo...
You could read the input lines to an array first with `mapfile`/`readarray`: ``` lines='John Smith James Johnson' mapfile -t lines Here, ``` while IFS=... read line ; do ... read -p "Do you want to echo name? surname otherwise " done <<< "$lines" ``` both `read`s indeed read from the same input, but I think (didn't tes...
# For loop over lines -- how to set IFS only for one `for` statement? **Tags:** <bash> **Question (score 5):** Here is an example of behavior I want to achieve: Suppose I have a list of lines, each line containing space separated values: ``` lines='John Smith James Johnson' ``` And I want to loop over lines echoing ...
2,764
691
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,776
unix.stackexchange.com
I can't grep tmux ls output when no tmux server is running
<p>I'm trying to find a way to check if tmux server is running or not in order to update my zsh prompt with that information.</p> <h3>when tmux server is alive</h3> <pre class="lang-bsh prettyprint-override"><code>&gt; tmux ls 0: 1 windows (created Sat Jul 10 13:47:36 2021) (attached) </code></pre> <p>so I can grep tha...
I'm trying to find a way to check if tmux server is running or not in order to update my zsh prompt with that information. ### when tmux server is alive ``` > tmux ls 0: 1 windows (created Sat Jul 10 13:47:36 2021) (attached) ``` so I can grep that output, correct? grepping that output: ``` > tmux ls | grep -i "windows...
5
467
3
3
3
[ "<grep><zsh><tmux><prompt>" ]
2021-07-10T11:04:24.393
2021-07-12T16:00:32.217
461,559
null
[ { "id": 657782, "body": "<p>Your confusion comes from the fact that <code>tmux</code>, like all other utilities, writes error messages and other diagnostic messages to the <em>standard error stream</em> rather than to the <em>standard output stream</em>. With the <code>&gt;</code> redirection, you only red...
Your confusion comes from the fact that `tmux`, like all other utilities, writes error messages and other diagnostic messages to the standard error stream rather than to the standard output stream. With the `>` redirection, you only redirect the standard output stream, not the error messages. Likewise, when you pipe th...
# I can't grep tmux ls output when no tmux server is running **Tags:** <grep><zsh><tmux><prompt> **Question (score 5):** I'm trying to find a way to check if tmux server is running or not in order to update my zsh prompt with that information. ### when tmux server is alive ``` > tmux ls 0: 1 windows (created Sat Jul...
4,684
1,171
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
657,804
unix.stackexchange.com
Can it possibly work if I assign two shells to SHELL in cron?
<p>Recently I started the process of gradual switching my shell to <a href="https://github.com/nushell/nushell" rel="noreferrer">nu</a> and because of it I thought about assigning its path to SHELL in cron.</p> <p>Having read a good part of the manual at <code>man 5 crontab</code>, I took a look at PATH and copied the ...
Recently I started the process of gradual switching my shell to nu (https://github.com/nushell/nushell) and because of it I thought about assigning its path to SHELL in cron. Having read a good part of the manual at `man 5 crontab`, I took a look at PATH and copied the convention of using `:` in between the values atte...
5
948
2
6
2
[ "<shell><cron><environment-variables>" ]
2021-07-10T17:31:12.370
2021-07-12T14:37:18.040
346,682
657,883
[ { "id": 657805, "body": "<p>No, you can’t assign two shells to <code>SHELL</code>: <code>cron</code> needs to know which shell to start, there can only be one. The <code>SHELL</code> variable in <code>crontab</code> doesn’t specify <em>possible</em> shells, it specifies <em>the</em> shell to use. <code>cron...
No, you can’t assign two shells to `SHELL`: `cron` needs to know which shell to start, there can only be one. The `SHELL` variable in `crontab` doesn’t specify possible shells, it specifies the shell to use. `cron` reads the value in `SHELL`, if any, and uses that as the command to run; it doesn’t interpret `:` or any ...
# Can it possibly work if I assign two shells to SHELL in cron? **Tags:** <shell><cron><environment-variables> **Question (score 5):** Recently I started the process of gradual switching my shell to nu (https://github.com/nushell/nushell) and because of it I thought about assigning its path to SHELL in cron. Having ...
4,254
1,063
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,031
unix.stackexchange.com
How do I make a shortcut to a path using two tilde characters '~~' (or similar) in WSL/Ubuntu/Bash?
<p>I'm a newbie to Ubuntu/Linux world, so don't be hard on me.</p> <p>I'm using Ubuntu on Windows with WSL2 and the bash shell. Sometimes I want to copy files from Windows to Ubuntu or the other way around. I found some tutorials online on how to do this, and the simplest way is to navigate to <code>/mnt/c/Users/&lt;yo...
I'm a newbie to Ubuntu/Linux world, so don't be hard on me. I'm using Ubuntu on Windows with WSL2 and the bash shell. Sometimes I want to copy files from Windows to Ubuntu or the other way around. I found some tutorials online on how to do this, and the simplest way is to navigate to `/mnt/c/Users/<your_user>`. I want ...
10
1,691
4
1
2
[ "<bash><ubuntu><windows-subsystem-for-linux>" ]
2021-07-12T12:19:48.597
2021-07-13T18:50:53.787
481,253
658,033
[ { "id": 658032, "body": "<p>In your case, you can likely use a shell variable instead. You can call it <code>$WH</code> e.g. which is still reasonably short:</p>\n<pre><code>~$ export WH=/mnt/c/Users/your_user\n</code></pre>\n<p>This will set the variable <code>WH</code> to your Windows home directory and e...
In your case, you can likely use a shell variable instead. You can call it `$WH` e.g. which is still reasonably short: ``` ~$ export WH=/mnt/c/Users/your_user ``` This will set the variable `WH` to your Windows home directory and export it as environment variable. You can then use this variable as in ``` ~$ cp $WH/Desk...
# How do I make a shortcut to a path using two tilde characters '~~' (or similar) in WSL/Ubuntu/Bash? **Tags:** <bash><ubuntu><windows-subsystem-for-linux> **Question (score 10):** I'm a newbie to Ubuntu/Linux world, so don't be hard on me. I'm using Ubuntu on Windows with WSL2 and the bash shell. Sometimes I want t...
4,675
1,168
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,051
unix.stackexchange.com
How can I remove lines from a file in Unix where the first two columns have the same value?
<p>I have a file with several columns. I want to remove entire rows from this file at which the first and the second columns show the same value.</p> <p>For instance, my file is as the following:</p> <pre><code>Variant rsid chr pos 1:10177_A_AC rs367896724 1 10177 1:10352_T_TA rs2011064...
I have a file with several columns. I want to remove entire rows from this file at which the first and the second columns show the same value. For instance, my file is as the following: ``` Variant rsid chr pos 1:10177_A_AC rs367896724 1 10177 1:10352_T_TA rs201106462 1 10352 1:10511_G_A rs534229142 1 10511 1:10616_CCG...
9
1,278
7
2
2
[ "<text-processing><awk>" ]
2021-07-12T14:01:55.927
2021-07-18T12:57:57.207
481,271
658,058
[ { "id": 658055, "body": "<p>You almost make it</p>\n<pre><code>awk '$1!=$2' input.file &gt; output.file\n</code></pre>\n<p>This will keep line where first and second field are different (thus removing when equal).</p>\n<ul>\n<li><code>-F,</code> is wrong because <code>,</code> is not your field separator an...
You almost make it ``` awk '$1!=$2' input.file > output.file ``` This will keep line where first and second field are different (thus removing when equal). - `-F,` is wrong because `,` is not your field separator and setting it that way will make awk misinterpret the line content - `'$1==$2{sed -i}` is neither a awk, n...
# How can I remove lines from a file in Unix where the first two columns have the same value? **Tags:** <text-processing><awk> **Question (score 9):** I have a file with several columns. I want to remove entire rows from this file at which the first and the second columns show the same value. For instance, my file i...
4,196
1,049
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,270
unix.stackexchange.com
Is there some interactive analogue of `mktemp` that helps to organize throw-away directories?
<p>I often want a temporary directly where I can unpack some archive (or create a temporary project), see around some files. It is unpredictable in advance for how much time a particular directory may be needed.</p> <p>Such directories are often clutter home directory, <code>/tmp</code>, project directories. They often...
I often want a temporary directly where I can unpack some archive (or create a temporary project), see around some files. It is unpredictable in advance for how much time a particular directory may be needed. Such directories are often clutter home directory, `/tmp`, project directories. They often have names like some...
6
609
3
2
0
[ "<bash><filesystems><interactive><mktemp>" ]
2021-07-13T22:30:39.783
2021-07-21T09:27:42.510
17,594
658,274
[ { "id": 658274, "body": "<p>It doesn’t quite cover all the features you mention (easily making the temporary directory persistent), but I rather like <a href=\"https://github.com/kusalananda/shell-toolbox\" rel=\"nofollow noreferrer\">Kusalananda’s <code>shell</code></a> for this. It creates a temporary dir...
It doesn’t quite cover all the features you mention (easily making the temporary directory persistent), but I rather like Kusalananda’s `shell` (https://github.com/kusalananda/shell-toolbox) for this. It creates a temporary directory, starts a new shell inside it and cleans the temporary directory up when the shell exi...
# Is there some interactive analogue of `mktemp` that helps to organize throw-away directories? **Tags:** <bash><filesystems><interactive><mktemp> **Question (score 6):** I often want a temporary directly where I can unpack some archive (or create a temporary project), see around some files. It is unpredictable in a...
2,116
529
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,290
unix.stackexchange.com
What am I doing wrong when formatting my flash drive to NTFS?
<p>Before the attempt to format a flash drive:</p> <pre class="lang-none prettyprint-override"><code>$ sudo fdisk -l ... ... Disk /dev/sdc: 7.32 GiB, 7864320000 bytes, 15360000 sectors Disk model: DataTraveler 3.0 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (mini...
Before the attempt to format a flash drive: ``` $ sudo fdisk -l ... ... Disk /dev/sdc: 7.32 GiB, 7864320000 bytes, 15360000 sectors Disk model: DataTraveler 3.0 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: g...
5
2,155
2
1
0
[ "<filesystems><partition><ntfs><mkfs>" ]
2021-07-14T05:05:26.973
2021-07-14T07:02:08.347
164,309
null
[ { "id": 658292, "body": "<p>Here's what you're missing.</p>\n<p>There's a partition table and there are file systems - they are related but different. You can perfectly have partitions type <code>Linux filesystem</code> (MBR notation <code>Linux</code>) formatted as NTFS and partitions type <code>Microsoft ...
Here's what you're missing. There's a partition table and there are file systems - they are related but different. You can perfectly have partitions type `Linux filesystem` (MBR notation `Linux`) formatted as NTFS and partitions type `Microsoft basic data` (MBR notation `HPFS/NTFS/exFAT`) formatted as e.g. `ext4`. `mkf...
# What am I doing wrong when formatting my flash drive to NTFS? **Tags:** <filesystems><partition><ntfs><mkfs> **Question (score 5):** Before the attempt to format a flash drive: ``` $ sudo fdisk -l ... ... Disk /dev/sdc: 7.32 GiB, 7864320000 bytes, 15360000 sectors Disk model: DataTraveler 3.0 Units: sectors of 1 *...
3,444
861
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,464
unix.stackexchange.com
swap total is zero but used is too high
<pre><code>free -m total used free shared buffers cached Mem: 15708 15539 168 124 6 6272 -/+ buffers/cache: 9260 6447 Swap: 0 1759218604 0 sysctl vm.swappiness vm.swappiness = 0 grep Swap /proc/meminfo Swap...
``` free -m total used free shared buffers cached Mem: 15708 15539 168 124 6 6272 -/+ buffers/cache: 9260 6447 Swap: 0 1759218604 0 sysctl vm.swappiness vm.swappiness = 0 grep Swap /proc/meminfo SwapCached: 0 kB SwapTotal: 0 kB SwapFree: 36 kB ``` I have set vm.swappiness=0 to disable swap, but the output of `free -m` ...
6
927
2
1
0
[ "<linux><centos>" ]
2021-07-15T06:11:54.390
2021-07-15T08:22:25.083
160,632
658,478
[ { "id": 658478, "body": "<p>That's a very old RHEL/CentOS 6 kernel bug, you need to update to kernel-2.6.32-573.6.1.el6 (or newer). See this <a href=\"https://access.redhat.com/solutions/1571043\" rel=\"noreferrer\">RH customer portal article</a> (requires RH account) and this <a href=\"https://serverfault....
That's a very old RHEL/CentOS 6 kernel bug, you need to update to kernel-2.6.32-573.6.1.el6 (or newer). See this RH customer portal article (https://access.redhat.com/solutions/1571043) (requires RH account) and this question on serverfault (https://serverfault.com/questions/727378/free-reports-bogus-amount-of-swap-use...
# swap total is zero but used is too high **Tags:** <linux><centos> **Question (score 6):** ``` free -m total used free shared buffers cached Mem: 15708 15539 168 124 6 6272 -/+ buffers/cache: 9260 6447 Swap: 0 1759218604 0 sysctl vm.swappiness vm.swappiness = 0 grep Swap /proc/meminfo SwapCached: 0 kB SwapTotal: 0 ...
1,656
414
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,485
unix.stackexchange.com
How can I use quantifiers in a sed substitution expression?
<p>I'm using <code>| sed</code> to indent the result of some command (let's take a plain <code>$ echo something</code> for this example). I want to prefix the result with, say, 10 spaces. The following works fine:</p> <pre><code>$ echo something | sed 's/^/ /' something </code></pre> <p>But isn't there...
I'm using `| sed` to indent the result of some command (let's take a plain `$ echo something` for this example). I want to prefix the result with, say, 10 spaces. The following works fine: ``` $ echo something | sed 's/^/ /' something ``` But isn't there a way to use quantifiers in the `| sed` expression? I tried for e...
8
661
6
4
1
[ "<sed><regular-expression>" ]
2021-07-15T09:12:54.267
2021-07-22T10:36:14.483
152,418
658,562
[ { "id": 658489, "body": "<p>I don't think it's possible since the replacement in <code>sed</code> substitutions isn't a regular expression.</p>\n<p>An alternative could be to create a variable and use it as replacement, like this:</p>\n<pre class=\"lang-bsh prettyprint-override\"><code># use printf to set a...
I don't think it's possible since the replacement in `sed` substitutions isn't a regular expression. An alternative could be to create a variable and use it as replacement, like this: ``` # use printf to set as many spaces as you want $ i=$(printf "%10s") # use the created variable as replacement of the substitution $ ...
# How can I use quantifiers in a sed substitution expression? **Tags:** <sed><regular-expression> **Question (score 8):** I'm using `| sed` to indent the result of some command (let's take a plain `$ echo something` for this example). I want to prefix the result with, say, 10 spaces. The following works fine: ``` $ ...
3,356
839
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,580
unix.stackexchange.com
I'm trying to script a SSH connection test using a list of test users against a list of hosts using bash, can you help?
<p>I'm trying to test the ssh connection of a set of hosts using a corresponding set of test user accounts.</p> <p>ie: <code>testuser1 test ssh connection to server1</code>, <code>testuser2 test ssh connection to server2</code>, <code>testuser3 test ssh connection to server3</code> ect.</p> <p>Each test user is logging...
I'm trying to test the ssh connection of a set of hosts using a corresponding set of test user accounts. ie: `testuser1 test ssh connection to server1`, `testuser2 test ssh connection to server2`, `testuser3 test ssh connection to server3` ect. Each test user is logging in using a private key: `ssh -i ~/keys/testuser1k...
5
289
1
2
0
[ "<shell-script><ssh>" ]
2021-07-15T19:31:52.003
2021-07-15T21:10:19.023
481,791
null
[ { "id": 658583, "body": "<p>I'd suggest using a <code>while read</code> loop so that you can assign whitespace-separated tokens to individual variables, rather than relying on the implicit split+glob behavior of <code>$(cat hosts)</code></p>\n<p>The only tricky bit is that <code>read</code> reads from stand...
I'd suggest using a `while read` loop so that you can assign whitespace-separated tokens to individual variables, rather than relying on the implicit split+glob behavior of `$(cat hosts)` The only tricky bit is that `read` reads from standard input by default - and so does `ssh`. So you either need to pass the `-n` fla...
# I'm trying to script a SSH connection test using a list of test users against a list of hosts using bash, can you help? **Tags:** <shell-script><ssh> **Question (score 5):** I'm trying to test the ssh connection of a set of hosts using a corresponding set of test user accounts. ie: `testuser1 test ssh connection t...
2,504
626
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,699
unix.stackexchange.com
What does !cp:$ do?
<p>I saw this command in the documentation of one of the programs in my work:</p> <pre><code>cp company-sso /usr/local/bin/company-sso ; sudo chmod +x !cp:$ </code></pre> <p>I'm aware that <code>:</code> will stop the next command from being executed, it'll only be evaluated, but how does this work with <code>$</code>?...
I saw this command in the documentation of one of the programs in my work: ``` cp company-sso /usr/local/bin/company-sso ; sudo chmod +x !cp:$ ``` I'm aware that `:` will stop the next command from being executed, it'll only be evaluated, but how does this work with `$`? I've only seen `$` used before a variable name, ...
13
977
1
4
1
[ "<bash><shell-script><shell><file-copy>" ]
2021-07-16T15:26:53.030
2021-07-16T16:31:16.183
481,918
null
[ { "id": 658700, "body": "<p>This is <a href=\"https://www.gnu.org/software/bash/manual/html_node/History-Interaction.html\" rel=\"noreferrer\">history expansion</a>, introduced by <code>!</code>; the <code>$</code> must be intepreted in that context. <code>!cp:$</code> has two parts, separated by <code>:</c...
This is history expansion (https://www.gnu.org/software/bash/manual/html_node/History-Interaction.html), introduced by `!`; the `$` must be intepreted in that context. `!cp:$` has two parts, separated by `:`. `!cp` is the event designator, it means “find the most recent command starting with `cp`”. `$` is a word design...
# What does !cp:$ do? **Tags:** <bash><shell-script><shell><file-copy> **Question (score 13):** I saw this command in the documentation of one of the programs in my work: ``` cp company-sso /usr/local/bin/company-sso ; sudo chmod +x !cp:$ ``` I'm aware that `:` will stop the next command from being executed, it'll o...
2,385
596
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,779
unix.stackexchange.com
How to find what packages are added in a new Debian release
<p>I am updating my Debian system to a new major release and as Debian is famous for having one of the largest software repositories among Linux distros, I am interested to see what packages have been added since the last release. Currently I am updating from Debian 10 &quot;Buster&quot; to Debian 11 &quot;Bullseye&quo...
I am updating my Debian system to a new major release and as Debian is famous for having one of the largest software repositories among Linux distros, I am interested to see what packages have been added since the last release. Currently I am updating from Debian 10 "Buster" to Debian 11 "Bullseye". Is such a list main...
5
365
3
0
0
[ "<debian><apt><package-management><dpkg>" ]
2021-07-17T11:08:58.223
2021-07-17T11:40:26.360
24,334
658,790
[ { "id": 658783, "body": "<p>I don’t think <code>apt</code> can tell you on its own, but <code>aptitude</code> can. Install it if you don’t have it already, then run it <em>before</em> your update. You’ll see a screen like this:</p>\n<pre><code> Actions Undo Package Resolver Search Options Views Help\...
I don’t think `apt` can tell you on its own, but `aptitude` can. Install it if you don’t have it already, then run it before your update. You’ll see a screen like this: ``` Actions Undo Package Resolver Search Options Views Help C-T: Menu ?: Help q: Quit u: Update g: Preview/Download/Install/Remove Pkgs aptitude 0.8.11...
# How to find what packages are added in a new Debian release **Tags:** <debian><apt><package-management><dpkg> **Question (score 5):** I am updating my Debian system to a new major release and as Debian is famous for having one of the largest software repositories among Linux distros, I am interested to see what pa...
3,763
940
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,914
unix.stackexchange.com
Why sleep command process is still running in the background while I stopped it with CTRL-Z?
<p>What I do is:</p> <pre><code>sleep 5 </code></pre> <p>and immediately <kbd>CTRL</kbd>-<kbd>Z</kbd> so when I open <code>jobs</code> I see:</p> <pre><code>[1]+ Stopped sleep 5 </code></pre> <p>next when I do <code>fg %1</code> sleep process is no more running, it's done so that means it was running ...
What I do is: ``` sleep 5 ``` and immediately CTRL-Z so when I open `jobs` I see: ``` [1]+ Stopped sleep 5 ``` next when I do `fg %1` sleep process is no more running, it's done so that means it was running those 5 ( maybe 4? ) seconds while it was `Stopped`. Why?
8
724
3
2
1
[ "<process><background-process><jobs>" ]
2021-07-18T20:37:22.173
2021-07-21T07:05:59.527
477,078
658,922
[ { "id": 658922, "body": "<p>The utility calls <code>xnanosleep()</code> which in its turn calls the linux kernel <code>nanosleep()</code> system call. It works regardless of an application running/stopped state but when the application is stopped it cannot exit which means it does that when you unpause it.<...
The utility calls `xnanosleep()` which in its turn calls the linux kernel `nanosleep()` system call. It works regardless of an application running/stopped state but when the application is stopped it cannot exit which means it does that when you unpause it. https://linux.die.net/man/2/nanosleep (https://linux.die.net/m...
# Why sleep command process is still running in the background while I stopped it with CTRL-Z? **Tags:** <process><background-process><jobs> **Question (score 8):** What I do is: ``` sleep 5 ``` and immediately CTRL-Z so when I open `jobs` I see: ``` [1]+ Stopped sleep 5 ``` next when I do `fg %1` sleep process is n...
1,092
273
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,937
unix.stackexchange.com
Is there any risk to create an LVM group with two disks of different physical sector size?
<p>I have two hard drives of different physical sector size. I would like to create an LVM volume group with them, however, when I do so with <code>vgcreate</code>, I get a warning telling me that the two disks have different physical sector size. Is there something to be concerned about?</p>
I have two hard drives of different physical sector size. I would like to create an LVM volume group with them, however, when I do so with `vgcreate`, I get a warning telling me that the two disks have different physical sector size. Is there something to be concerned about?
5
342
1
2
0
[ "<partition><lvm><hard-disk><disk><volume>" ]
2021-07-19T02:02:45.380
2021-07-19T11:35:56.923
309,146
658,950
[ { "id": 658950, "body": "<p>You don't want to mix different sector sizes in a single VG. Newer versions of LVM don't even allow creating VG on PVs with mixed sector sizes by default (older versions show only the warning message you saw). The problem is not with the VG, but with the LVs and filesystems -- if...
You don't want to mix different sector sizes in a single VG. Newer versions of LVM don't even allow creating VG on PVs with mixed sector sizes by default (older versions show only the warning message you saw). The problem is not with the VG, but with the LVs and filesystems -- if you resize or move LV to the larger sec...
# Is there any risk to create an LVM group with two disks of different physical sector size? **Tags:** <partition><lvm><hard-disk><disk><volume> **Question (score 5):** I have two hard drives of different physical sector size. I would like to create an LVM volume group with them, however, when I do so with `vgcreate...
1,799
449
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
658,964
unix.stackexchange.com
How to pipe filenames with spaces from a list file into "grep"?
<p>First, I think the fact that I'm using cygwin is highly relevant here.</p> <p>In theory, I already know how to do this:</p> <pre><code>cat file | xargs grep pattern </code></pre> <p>The problem is, some of the file paths in <code>file</code> have spaces. The file looks like this:</p> <pre><code>subdir/foo/bar.html s...
First, I think the fact that I'm using cygwin is highly relevant here. In theory, I already know how to do this: ``` cat file | xargs grep pattern ``` The problem is, some of the file paths in `file` have spaces. The file looks like this: ``` subdir/foo/bar.html subdir/f o o/ba r.html subdir/~foo/bar.html ``` This caus...
6
810
4
4
2
[ "<shell><text-processing><filenames><cygwin>" ]
2021-07-19T07:29:54.877
2021-07-21T07:37:19.350
101,311
658,969
[ { "id": 658969, "body": "<p>Use <code>xargs -d '\\n'</code> if the input file contains one filename per line. e.g.</p>\n<pre><code>xargs -d '\\n' grep pattern &lt; file\n</code></pre>\n<p>If your filenames start with <code>~</code> to indicate &quot;my home directory&quot;, you first need to replace the <c...
Use `xargs -d '\n'` if the input file contains one filename per line. e.g. ``` xargs -d '\n' grep pattern want to interpolate the variable `$HOME` into the sed script, and uses `=` as the delimiter for the `s` operator because `$HOME` is going to contain /s (but is unlikely to contain an `=`). Or, if you're using `find...
# How to pipe filenames with spaces from a list file into "grep"? **Tags:** <shell><text-processing><filenames><cygwin> **Question (score 6):** First, I think the fact that I'm using cygwin is highly relevant here. In theory, I already know how to do this: ``` cat file | xargs grep pattern ``` The problem is, some o...
2,018
504
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,143
unix.stackexchange.com
Execute bash function to run screen
<p>I'm using an aws ubuntu instance. I would like to create an alias/function to run some shortcuts, for example to activate a python virtual environnement in a screen.</p> <p>I've made this function for example:</p> <pre class="lang-bsh prettyprint-override"><code># Alias for jupyter notebook function start_jupyter() ...
I'm using an aws ubuntu instance. I would like to create an alias/function to run some shortcuts, for example to activate a python virtual environnement in a screen. I've made this function for example: ``` # Alias for jupyter notebook function start_jupyter() { cd my_path/lab_workspace/ # 1. cd into my workspace sourc...
5
170
1
0
0
[ "<bash><gnu-screen>" ]
2021-07-20T09:28:27.137
2021-07-20T09:50:17.970
482,376
659,145
[ { "id": 659145, "body": "<p>The reason the function stopped is that you spawn an interactive screen session. You might want to do this instead:</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>screen -dmS jupyter_lab jupyter lab\n</code></pre>\n<p>This will create a detached screen session named <cod...
The reason the function stopped is that you spawn an interactive screen session. You might want to do this instead: ``` screen -dmS jupyter_lab jupyter lab ``` This will create a detached screen session named `jupyter_lab` and execute the command there. As per the `screen --help` info: ``` -dmS name Start as daemon: Sc...
# Execute bash function to run screen **Tags:** <bash><gnu-screen> **Question (score 5):** I'm using an aws ubuntu instance. I would like to create an alias/function to run some shortcuts, for example to activate a python virtual environnement in a screen. I've made this function for example: ``` # Alias for jupyter...
1,471
367
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,216
unix.stackexchange.com
How to do formatted printing with jq?
<p><code>jq</code> has built-in ability to convert numbers to string or concatenate strings.<br /> How can I format strings inside jq similar to <code>printf</code> like padding (%4s).</p> <p>For example, how can I force number to occupy 10 char spaces with left alignment?<br /> <code>echo '{&quot;title&quot; : &quot;A...
`jq` has built-in ability to convert numbers to string or concatenate strings. How can I format strings inside jq similar to `printf` like padding (%4s). For example, how can I force number to occupy 10 char spaces with left alignment? `echo '{"title" : "A sample name", "number" : 1214}' | jq '(.title) + " " + (.number...
6
2,263
2
0
2
[ "<bash><command-line><text-formatting><printf><jq>" ]
2021-07-20T19:10:11.703
2021-11-05T07:06:15.657
306,382
659,235
[ { "id": 659228, "body": "<p><code>jq</code> does not have <code>printf</code>. One way could be; <a href=\"https://github.com/stedolan/jq/issues/614\" rel=\"noreferrer\">Partially taken from here</a>:</p>\n<pre><code>echo '{&quot;title&quot; : &quot;A sample name&quot;, &quot;number&quot; : 1214}' | \njq '(...
`jq` does not have `printf`. One way could be; Partially taken from here (https://github.com/stedolan/jq/issues/614): ``` echo '{"title" : "A sample name", "number" : 1214}' | jq '(.title) + " " + (.number | tostring | (" " * (10 - length)) + .)' ``` Perhaps better added as a module. Personally I quickly find `jq` line...
# How to do formatted printing with jq? **Tags:** <bash><command-line><text-formatting><printf><jq> **Question (score 6):** `jq` has built-in ability to convert numbers to string or concatenate strings. How can I format strings inside jq similar to `printf` like padding (%4s). For example, how can I force number to ...
2,670
667
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,253
unix.stackexchange.com
Why does man complain about a function defined in .profile?
<p>I use Bash 5.1.8. Running <code>man</code> shows the manual page but with the following errors</p> <pre class="lang-bsh prettyprint-override"><code>man ps sh: bat: line 10: syntax error near unexpected token `(' sh: bat: line 10: ` *.?(ba)sh)' sh: error importing function definition for `bat' </code></pre> <p>I th...
I use Bash 5.1.8. Running `man` shows the manual page but with the following errors ``` man ps sh: bat: line 10: syntax error near unexpected token `(' sh: bat: line 10: ` *.?(ba)sh)' sh: error importing function definition for `bat' ``` I think some shell (`sh`) is finding Bashisms obnoxious. These errors vanish if I ...
7
1,153
2
6
0
[ "<bash><man><profile>" ]
2021-07-21T05:58:48.027
2021-07-21T08:22:32.373
30,580
659,259
[ { "id": 659259, "body": "<p><code>man</code> is not reading your <code>~/.profile</code> but it will run <code>sh</code> to interpret some command lines (or to interpret <code>nroff</code> which at least on my system is a <code>sh</code> script wrapper to <code>groff</code>), and on your system <code>sh</co...
`man` is not reading your `~/.profile` but it will run `sh` to interpret some command lines (or to interpret `nroff` which at least on my system is a `sh` script wrapper to `groff`), and on your system `sh` happens to be `bash`, which imports functions exported by `bash`'s `export -f` (in variables named `BASH_FUNC_fun...
# Why does man complain about a function defined in .profile? **Tags:** <bash><man><profile> **Question (score 7):** I use Bash 5.1.8. Running `man` shows the manual page but with the following errors ``` man ps sh: bat: line 10: syntax error near unexpected token `(' sh: bat: line 10: ` *.?(ba)sh)' sh: error import...
5,710
1,427
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,282
unix.stackexchange.com
Remove lines that contain two string matches
<p>How to delete all lines containing <code>def</code> AND <code>jkl</code> from the following file (lines 2 and 4)? I want the match to apply to sub-string matches of the fields, too. The fields in the file are space-separated.</p> <pre><code>$ cat test2.txt 1. abc def ghi 2. def ghi jkl 3. jkl mno pqr 4. jkl def stu...
How to delete all lines containing `def` AND `jkl` from the following file (lines 2 and 4)? I want the match to apply to sub-string matches of the fields, too. The fields in the file are space-separated. ``` $ cat test2.txt 1. abc def ghi 2. def ghi jkl 3. jkl mno pqr 4. jkl def stu 5. vwx yza bcd ``` I managed to do i...
6
608
5
0
0
[ "<text-processing>" ]
2021-07-21T10:27:16.120
2021-07-21T10:42:24.130
152,418
659,284
[ { "id": 659284, "body": "<p>With <code>sed</code> specifically, you could do:</p>\n<pre><code>sed -e '/def/!b' -e /jkl/d\n</code></pre>\n<p>Where the first <code>e</code>xpression <code>b</code>ranches out (which prints the line as we didn't pass the <code>-n</code> option) if <code>def</code> is not (<code...
With `sed` specifically, you could do: ``` sed -e '/def/!b' -e /jkl/d ``` Where the first `e`xpression `b`ranches out (which prints the line as we didn't pass the `-n` option) if `def` is not (`!`) found, and the second `d`eletes if `jkl` is found. So in the end the line is deleted only if both `def` and `jkl` are foun...
# Remove lines that contain two string matches **Tags:** <text-processing> **Question (score 6):** How to delete all lines containing `def` AND `jkl` from the following file (lines 2 and 4)? I want the match to apply to sub-string matches of the fields, too. The fields in the file are space-separated. ``` $ cat test...
3,296
824
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,287
unix.stackexchange.com
Convert a date from DD-MM-YYYY to YYYY-MM-DD format in bash LINUX
<p>Scenario:</p> <p>I am fetching a date value from a file into a variable and it is in DD-MM-YYYY format by default. I have to substract this date from system date. Subtraction is giving incorrect result if I had both dates in DD-MM-YYYY format. So I read a bit on google and decided to format both dates as YYYY-MM-DD ...
Scenario: I am fetching a date value from a file into a variable and it is in DD-MM-YYYY format by default. I have to substract this date from system date. Subtraction is giving incorrect result if I had both dates in DD-MM-YYYY format. So I read a bit on google and decided to format both dates as YYYY-MM-DD as this wi...
5
2,180
7
9
1
[ "<shell-script><text-processing><date>" ]
2021-07-21T10:58:49.700
2021-07-21T11:04:43.850
482,498
659,288
[ { "id": 659291, "body": "<p>You could switch to busybox <code>date</code> which allows specifying the input format:</p>\n<pre><code>$ date=19-7-2021\n$ busybox date -D %d-%m-%Y -d &quot;$date&quot; +%F\n2021-07-19\n</code></pre>\n<p>(beware it won't accept <code>019-007-2021</code> dates for instance).</p>...
You could switch to busybox `date` which allows specifying the input format: ``` $ date=19-7-2021 $ busybox date -D %d-%m-%Y -d "$date" +%F 2021-07-19 ``` (beware it won't accept `019-007-2021` dates for instance). Same with the ast-open implementation of `date` (unlikely to be available out of the box on your RedHat s...
# Convert a date from DD-MM-YYYY to YYYY-MM-DD format in bash LINUX **Tags:** <shell-script><text-processing><date> **Question (score 5):** Scenario: I am fetching a date value from a file into a variable and it is in DD-MM-YYYY format by default. I have to substract this date from system date. Subtraction is giving...
4,651
1,162
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,452
unix.stackexchange.com
Search, separate, and purge txt values
<p>What's really tripping me about this is the quote marks.</p> <p>I have a <code>file.txt</code> with lines like:</p> <pre><code>{&quot;a&quot;:&quot;town, state, country&quot;,&quot;e&quot;:[&quot;john@company.com&quot;],&quot;n&quot;:&quot;john smith&quot;} {&quot;a&quot;:&quot;town, state, country&quot;,&quot;e&quo...
What's really tripping me about this is the quote marks. I have a `file.txt` with lines like: ``` {"a":"town, state, country","e":["john@company.com"],"n":"john smith"} {"a":"town, state, country","e":["zac@company.com","zacsurname@gmail.com"],"n":"zac surname"} {"a":"town, state, country","n":"jane doe"} ``` and I'm l...
5
110
1
1
0
[ "<awk><grep><json>" ]
2021-07-22T11:31:11.707
2021-07-22T13:07:22.220
482,596
659,454
[ { "id": 659454, "body": "<p>Since your file is a JSON document, it makes most sense to use a JSON parser, such as <code>jq</code>, to parse it:</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>jq -r '\n select(has(&quot;n&quot;) and has(&quot;e&quot;)) |\n (.n|split(&quot; &quot;)[0]) as $name ...
Since your file is a JSON document, it makes most sense to use a JSON parser, such as `jq`, to parse it: ``` jq -r ' select(has("n") and has("e")) | (.n|split(" ")[0]) as $name | .e[] | [ $name, . ] | @tsv' file.txt ``` This selects all objects from your set of objects that has both a `n` and an `e` key and discards th...
# Search, separate, and purge txt values **Tags:** <awk><grep><json> **Question (score 5):** What's really tripping me about this is the quote marks. I have a `file.txt` with lines like: ``` {"a":"town, state, country","e":["john@company.com"],"n":"john smith"} {"a":"town, state, country","e":["zac@company.com","zac...
2,073
518
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,585
unix.stackexchange.com
What's the point of firewalling outgoing connections?
<p>I have a firewall (<a href="https://configserver.com/cp/csf.html" rel="nofollow noreferrer">csf</a>) that lets you to separately allow incoming and outgoing TCP ports. My question is, why would anyone want to have <em><strong>any</strong></em> outgoing ports closed?</p> <p>I understand that by default you might want...
I have a firewall (csf (https://configserver.com/cp/csf.html)) that lets you to separately allow incoming and outgoing TCP ports. My question is, why would anyone want to have any outgoing ports closed? I understand that by default you might want to have all ports closed for incoming connections. From there, if you are...
12
3,156
9
4
2
[ "<firewall><ftp><port>" ]
2021-07-23T08:02:37.807
2021-07-26T14:28:00.950
27,990
659,589
[ { "id": 659589, "body": "<p>There can be many reasons why someone might want to have outgoing ports closed. Here are some that I have applied to various servers at various times</p>\n<ul>\n<li>The machine is in a corporate environment where only outbound web traffic is permitted, and that via a proxy. All o...
There can be many reasons why someone might want to have outgoing ports closed. Here are some that I have applied to various servers at various times - The machine is in a corporate environment where only outbound web traffic is permitted, and that via a proxy. All other ports are closed because they are not needed. - ...
# What's the point of firewalling outgoing connections? **Tags:** <firewall><ftp><port> **Question (score 12):** I have a firewall (csf (https://configserver.com/cp/csf.html)) that lets you to separately allow incoming and outgoing TCP ports. My question is, why would anyone want to have any outgoing ports closed? I...
3,464
866
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,597
unix.stackexchange.com
What is the point of creating a user without a home directory?
<p>While reading useradd manual pages, see that <code>useradd -M <i>user</i></code> creates a user without home directory and I can not figure out what is the purpose on it.</p> <p>I am new on sysadmin topics and do not know much about it.</p>
While reading useradd manual pages, see that `useradd -M user` creates a user without home directory and I can not figure out what is the purpose on it. I am new on sysadmin topics and do not know much about it.
5
448
1
0
0
[ "<linux><users><home>" ]
2021-07-23T09:59:18.813
2021-07-23T12:56:04.907
482,379
null
[ { "id": 659600, "body": "<p>You may possibly want to use <code>-M</code> with <code>useradd</code> if the new user's home directory already exists.</p>\n<p>Note that the <code>-M</code> option turns off <em>the creation</em> of the user's home directory. You may use <code>-d</code> to assign a home directo...
You may possibly want to use `-M` with `useradd` if the new user's home directory already exists. Note that the `-M` option turns off the creation of the user's home directory. You may use `-d` to assign a home directory to the new user while at the same time using `-M`. It would be highly unusual to create a user with...
# What is the point of creating a user without a home directory? **Tags:** <linux><users><home> **Question (score 5):** While reading useradd manual pages, see that `useradd -M user` creates a user without home directory and I can not figure out what is the purpose on it. I am new on sysadmin topics and do not know ...
1,176
294
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,602
unix.stackexchange.com
What text editor supports positioning the cursor anywhere, even beyond the end of line?
<p>I want an editor that can put the cursor anywhere in the text document, as if it were filled with spaces everywhere.</p> <p>This way I can place the cursor anywhere and type or paste right away, without the need to fill the left hand side with spaces or tabs.</p> <p>Spaces on the right hand side of the cursor could ...
I want an editor that can put the cursor anywhere in the text document, as if it were filled with spaces everywhere. This way I can place the cursor anywhere and type or paste right away, without the need to fill the left hand side with spaces or tabs. Spaces on the right hand side of the cursor could be trimmed, moved...
5
399
2
0
0
[ "<linux><text-formatting><software-rec><editors>" ]
2021-07-23T10:33:34.500
2021-07-23T13:43:47.487
142,127
659,623
[ { "id": 659623, "body": "<p>Vim has the <a href=\"https://vimhelp.org/options.txt.html#%27virtualedit%27\" rel=\"nofollow noreferrer\"><code>virtualedit</code> option</a>:</p>\n<blockquote>\n<p>Virtual editing means that the cursor can be positioned where there is\nno actual character. This can be halfway ...
Vim has the `virtualedit` option (https://vimhelp.org/options.txt.html#%27virtualedit%27): Virtual editing means that the cursor can be positioned where there is no actual character. This can be halfway into a tab or beyond the end of the line. Useful for selecting a rectangle in Visual mode and editing a table. Issue ...
# What text editor supports positioning the cursor anywhere, even beyond the end of line? **Tags:** <linux><text-formatting><software-rec><editors> **Question (score 5):** I want an editor that can put the cursor anywhere in the text document, as if it were filled with spaces everywhere. This way I can place the cur...
1,528
382
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
659,744
unix.stackexchange.com
Why can't "cpulimit" limit chromium browser?
<p>Due to its high CPU usage i want to limit Chromium web browser by <code>cpulimit</code> and use terminal to run:</p> <pre><code>cpulimit -l 30 -- chromium --incognito </code></pre> <p>but it does not limit CPU usage as expected (i.e. to maximum to 30%). It again uses 100%. Why? What am I doing wrong?</p>
Due to its high CPU usage i want to limit Chromium web browser by `cpulimit` and use terminal to run: ``` cpulimit -l 30 -- chromium --incognito ``` but it does not limit CPU usage as expected (i.e. to maximum to 30%). It again uses 100%. Why? What am I doing wrong?
13
1,946
2
0
8
[ "<chrome><cpulimit>" ]
2021-07-24T12:15:18.537
2021-07-24T14:45:01.083
458,762
659,762
[ { "id": 659762, "body": "<p>Yeah, chromium doesn't care much when you stop one of its threads.</p>\n<p><code>cpulimit</code> is, in 2021, really not the kind of tool that you want to use, <strong>especially</strong> not with interactive software: it &quot;throttles&quot; processes (or unsuccessfully tries t...
Yeah, chromium doesn't care much when you stop one of its threads. `cpulimit` is, in 2021, really not the kind of tool that you want to use, especially not with interactive software: it "throttles" processes (or unsuccessfully tries to, in your case) by stopping and resuming them via signals. Um. That's a terrible hack...
# Why can't "cpulimit" limit chromium browser? **Tags:** <chrome><cpulimit> **Question (score 13):** Due to its high CPU usage i want to limit Chromium web browser by `cpulimit` and use terminal to run: ``` cpulimit -l 30 -- chromium --incognito ``` but it does not limit CPU usage as expected (i.e. to maximum to 30%...
3,918
979
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
660,057
unix.stackexchange.com
shutdown, but still allow new logins
<p>I have a Linux VM on <a href="https://en.wikipedia.org/wiki/Amazon_Web_Services" rel="nofollow noreferrer">AWS</a> in <a href="https://en.wikipedia.org/wiki/Amazon_Elastic_Compute_Cloud" rel="nofollow noreferrer">EC2</a> that starts up, performs a task, and then shuts itself down. I am issuing the shutdown command ...
I have a Linux VM on AWS (https://en.wikipedia.org/wiki/Amazon_Web_Services) in EC2 (https://en.wikipedia.org/wiki/Amazon_Elastic_Compute_Cloud) that starts up, performs a task, and then shuts itself down. I am issuing the shutdown command like this: ``` shutdown -h 5 ``` I have a 5 minute delay to give myself time to ...
8
1,521
3
1
1
[ "<shutdown>" ]
2021-07-26T20:48:27.920
2021-07-31T15:11:05.257
483,270
660,064
[ { "id": 660064, "body": "<p>You could simply not use <code>shutdown</code> with a time specification, but</p>\n<pre><code>echo shutdown -h now | at now + 5 minutes\n</code></pre>\n<p>or similar; a simple</p>\n<pre><code>sleep $((60*5)) ; shutdown -h now\n</code></pre>\n<p>would do, too.</p>\n<p>However, usi...
You could simply not use `shutdown` with a time specification, but ``` echo shutdown -h now | at now + 5 minutes ``` or similar; a simple ``` sleep $((60*5)) ; shutdown -h now ``` would do, too. However, using `at` has the advantage that you can review waiting commands using `atq` and cancel them using `atrm`.
# shutdown, but still allow new logins **Tags:** <shutdown> **Question (score 8):** I have a Linux VM on AWS (https://en.wikipedia.org/wiki/Amazon_Web_Services) in EC2 (https://en.wikipedia.org/wiki/Amazon_Elastic_Compute_Cloud) that starts up, performs a task, and then shuts itself down. I am issuing the shutdown c...
2,096
524
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
662,461
unix.stackexchange.com
Bash : how to pass arguments to a heredoc script
<p>Imagine you have a silly script test.sh to which arguments are passed that would look like this:</p> <pre class="lang-bsh prettyprint-override"><code>bash test.sh arg1 arg2 arg3 </code></pre> <p>with test.sh being a silly script that displays its command line:</p> <pre><code>#!/bin/bash echo &quot;$0 $*&quot; </code...
Imagine you have a silly script test.sh to which arguments are passed that would look like this: ``` bash test.sh arg1 arg2 arg3 ``` with test.sh being a silly script that displays its command line: ``` #!/bin/bash echo "$0 $*" ``` I would like to do the same using bash heredoc << to feed the script to bash. So I tried...
10
441
1
0
1
[ "<bash><shell-script><here-document>" ]
2021-07-29T08:57:03.953
2021-07-29T12:24:09.163
402,499
662,466
[ { "id": 662466, "body": "<p>The here document is passed to the inner bash on its standard input. You need to instruct bash to read from standard input. With no command line arguments, this happens automatically. If there's at least one non-option argument and no <code>-s</code> or <code>-c</code> option, th...
The here document is passed to the inner bash on its standard input. You need to instruct bash to read from standard input. With no command line arguments, this happens automatically. If there's at least one non-option argument and no `-s` or `-c` option, the first non-option argument is the name of the script file to ...
# Bash : how to pass arguments to a heredoc script **Tags:** <bash><shell-script><here-document> **Question (score 10):** Imagine you have a silly script test.sh to which arguments are passed that would look like this: ``` bash test.sh arg1 arg2 arg3 ``` with test.sh being a silly script that displays its command li...
1,190
297
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
662,510
unix.stackexchange.com
Adding a column with random values to end of CSV
<p>I have a CSV with a list of users, and would like to add a column with a one-time-use randomly generated password, unique to each user.</p> <p>My script works... but then it just keeps going indefinitely adding rows. If I move the code to set the variable out of the loop, it works just fine, but then every user ge...
I have a CSV with a list of users, and would like to add a column with a one-time-use randomly generated password, unique to each user. My script works... but then it just keeps going indefinitely adding rows. If I move the code to set the variable out of the loop, it works just fine, but then every user gets the same ...
6
171
2
2
0
[ "<bash><shell-script><shell>" ]
2021-07-29T14:33:28.523
2021-07-31T14:32:11.513
484,681
null
[ { "id": 662513, "body": "<p>You have the syntax of your <code>while...do...done</code> loop wrong. You are running this:</p>\n<pre><code>while read x ; OneTimePass=$(openssl rand -base64 14 | head -c 6) ; do ...\n</code></pre>\n<p>The <code>while</code> keyword's expected format is explained in <code>help w...
You have the syntax of your `while...do...done` loop wrong. You are running this: ``` while read x ; OneTimePass=$(openssl rand -base64 14 | head -c 6) ; do ... ``` The `while` keyword's expected format is explained in `help while`: ``` $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a...
# Adding a column with random values to end of CSV **Tags:** <bash><shell-script><shell> **Question (score 6):** I have a CSV with a list of users, and would like to add a column with a one-time-use randomly generated password, unique to each user. My script works... but then it just keeps going indefinitely adding ...
4,011
1,002
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
662,597
unix.stackexchange.com
Understanding Linux FAT fs (FAT, VFAT, FAT32, exFAT) support
<p>I'm trying to understand which FAT based filesystems my Real Time 2.6 Linux supports. I have tried 3 things:</p> <ol> <li><p>/proc/filesystems shows <code>vfat</code> among others non-relevant for the question (like ext2, etc)</p> </li> <li><p>/proc/config.gz shows:</p> <pre><code># DOS/FAT/NT Filesystems # CONFIG_F...
I'm trying to understand which FAT based filesystems my Real Time 2.6 Linux supports. I have tried 3 things: - /proc/filesystems shows `vfat` among others non-relevant for the question (like ext2, etc) - /proc/config.gz shows: ``` # DOS/FAT/NT Filesystems # CONFIG_FAT_FS=y CONFIG_MSDOS_FS=y CONFIG_VFAT_FS=y CONFIG_FAT_...
5
714
1
7
0
[ "<linux><filesystems><fat>" ]
2021-07-30T08:24:40.153
2021-07-30T10:09:00.460
444,593
662,600
[ { "id": 662600, "body": "<p>The FAT drivers include <a href=\"https://elixir.bootlin.com/linux/v5.13.6/source/fs/fat/fat.h#L159\" rel=\"nofollow noreferrer\">support for FAT32</a>; it’s treated as a variant along with FAT12 and FAT16. If you see <code>vfat</code> in <code>/proc/filesystems</code>, then FAT3...
The FAT drivers include support for FAT32 (https://elixir.bootlin.com/linux/v5.13.6/source/fs/fat/fat.h#L159); it’s treated as a variant along with FAT12 and FAT16. If you see `vfat` in `/proc/filesystems`, then FAT32 is supported. exFAT is supported, in recent kernels, by a specific exFAT driver (https://elixir.bootli...
# Understanding Linux FAT fs (FAT, VFAT, FAT32, exFAT) support **Tags:** <linux><filesystems><fat> **Question (score 5):** I'm trying to understand which FAT based filesystems my Real Time 2.6 Linux supports. I have tried 3 things: - /proc/filesystems shows `vfat` among others non-relevant for the question (like ext...
1,431
357
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,116
unix.stackexchange.com
no /etc/X11/xorg.conf file in RHEL 7
<p>I found this <a href="https://unix.stackexchange.com/questions/333450/is-etc-x11-xorg-conf-deprecated">Is `/etc/X11/xorg.conf` deprecated?</a></p> <p>However it didn't shed much light on the issue.</p> <p>I am trying to make use of remote desktop software (nice) and it is erroring on there not being an xorg.conf fil...
I found this Is `/etc/X11/xorg.conf` deprecated? (https://unix.stackexchange.com/questions/333450/is-etc-x11-xorg-conf-deprecated) However it didn't shed much light on the issue. I am trying to make use of remote desktop software (nice) and it is erroring on there not being an xorg.conf file. For the past couple years ...
6
622
1
2
0
[ "<linux><xorg><graphics>" ]
2021-08-03T12:18:32.820
2021-11-11T19:53:30.220
154,426
null
[ { "id": 663118, "body": "<p>X.org configuration lives in a number of places, notably <code>/etc/X11/xorg.conf</code> (if it exists), and <code>.conf</code> files in <code>/etc/X11/xorg.conf.d</code> and <code>/usr/share/X11/xorg.conf.d</code>. (For an exhaustive list, see <code>man xorg.conf</code> on your ...
X.org configuration lives in a number of places, notably `/etc/X11/xorg.conf` (if it exists), and `.conf` files in `/etc/X11/xorg.conf.d` and `/usr/share/X11/xorg.conf.d`. (For an exhaustive list, see `man xorg.conf` on your system.) Most settings which used to require an `xorg.conf` file in the past are now auto-detec...
# no /etc/X11/xorg.conf file in RHEL 7 **Tags:** <linux><xorg><graphics> **Question (score 6):** I found this Is `/etc/X11/xorg.conf` deprecated? (https://unix.stackexchange.com/questions/333450/is-etc-x11-xorg-conf-deprecated) However it didn't shed much light on the issue. I am trying to make use of remote desktop...
2,430
607
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,245
unix.stackexchange.com
grep -v not working when piping from iwconfig but works when piping from cat on a file
<p>I am running <code>iwconfig | grep -v &quot;no wireless extensions&quot;</code> but can't get the -v option to work as expected. I want to exclude lines including &quot;no wireless extensions&quot;, i.e., I want to display only the active/working wireless interface or whatever this should be called.</p> <p>In the be...
I am running `iwconfig | grep -v "no wireless extensions"` but can't get the -v option to work as expected. I want to exclude lines including "no wireless extensions", i.e., I want to display only the active/working wireless interface or whatever this should be called. In the beginning I thought perhaps the command out...
7
382
2
0
0
[ "<grep>" ]
2021-08-04T09:45:30.637
2021-08-04T10:03:28.670
433,212
663,246
[ { "id": 663246, "body": "<p><code>iwconfig</code> outputs to both standard output and to standard error, depending on whether it found or did not find any wireless extensions for an interface. Piping only affects standard output.</p>\n<p>Example removing the output sent to the standard error stream (only s...
`iwconfig` outputs to both standard output and to standard error, depending on whether it found or did not find any wireless extensions for an interface. Piping only affects standard output. Example removing the output sent to the standard error stream (only shows interfaces that have wireless extensions): ``` $ /usr/s...
# grep -v not working when piping from iwconfig but works when piping from cat on a file **Tags:** <grep> **Question (score 7):** I am running `iwconfig | grep -v "no wireless extensions"` but can't get the -v option to work as expected. I want to exclude lines including "no wireless extensions", i.e., I want to dis...
2,958
739
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,257
unix.stackexchange.com
/bin/sh: wildcard expansion does not work in script
<p>I am using <code>dash</code> as <code>/bin/sh</code>. In my script, I have following line:</p> <pre><code>SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* </code></pre> <p>Which is supposed to match file <code>/tmp/ssh-abcdefghijkl/agent.1234</code>. Even when the file exists, the script does not expand the pattern, and ...
I am using `dash` as `/bin/sh`. In my script, I have following line: ``` SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* ``` Which is supposed to match file `/tmp/ssh-abcdefghijkl/agent.1234`. Even when the file exists, the script does not expand the pattern, and the variable instead contains the literal pattern: ``` echo ...
5
312
1
1
0
[ "<shell><wildcards><dash>" ]
2021-08-04T10:50:14.107
2021-08-05T06:01:02.207
155,832
663,259
[ { "id": 663259, "body": "<p>Filename globbing does not happen in assignments like</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.*\n</code></pre>\n<p>In your code where it <em>appears</em> to be working, you get your expected output because you do not quote...
Filename globbing does not happen in assignments like ``` SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* ``` In your code where it appears to be working, you get your expected output because you do not quote the expansion of `$SSH_AUTH_SOCK`. What your `sh -c` script is doing is assigning the literal string `/tmp/ssh-????...
# /bin/sh: wildcard expansion does not work in script **Tags:** <shell><wildcards><dash> **Question (score 5):** I am using `dash` as `/bin/sh`. In my script, I have following line: ``` SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* ``` Which is supposed to match file `/tmp/ssh-abcdefghijkl/agent.1234`. Even when the f...
2,143
535
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,436
unix.stackexchange.com
How does the ent program calculate "optimum compression"?
<p>The <a href="http://manpages.ubuntu.com/manpages/bionic/man1/ent.1.html" rel="noreferrer">ent</a> program can be run on a file to give output such as the following:</p> <blockquote> <p>Entropy = 4.731183 bits per byte.</p> <p>Optimum compression would reduce the size of this 15731 byte file by 40 percent.</p> <p>Chi...
The ent (http://manpages.ubuntu.com/manpages/bionic/man1/ent.1.html) program can be run on a file to give output such as the following: Entropy = 4.731183 bits per byte. Optimum compression would reduce the size of this 15731 byte file by 40 percent. Chi square distribution for 15731 samples is 235086.62, and randomly ...
6
336
1
0
0
[ "<compression>" ]
2021-08-05T12:31:29.063
2021-08-05T12:38:37.843
26,068
663,437
[ { "id": 663437, "body": "<p>The entropy gives the variety of information contained in the file, <em>i.e.</em> a representation of the number of different values present in the file; optimum compression, or perhaps more accurately, optimum encoding, would use exactly that amount of storage.</p>\n<p>In your c...
The entropy gives the variety of information contained in the file, i.e. a representation of the number of different values present in the file; optimum compression, or perhaps more accurately, optimum encoding, would use exactly that amount of storage. In your case, the file is currently 15,731 bytes in length, but st...
# How does the ent program calculate "optimum compression"? **Tags:** <compression> **Question (score 6):** The ent (http://manpages.ubuntu.com/manpages/bionic/man1/ent.1.html) program can be run on a file to give output such as the following: Entropy = 4.731183 bits per byte. Optimum compression would reduce the si...
2,677
669
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,647
unix.stackexchange.com
How to print zeros and ones of a file
<p><em>Long story short:</em> how to print in a terminal the binary digits constituting a file e.g. a library <em>.so</em> or a simple text <em>.txt</em> file</p> <hr /> <p><em>PC hardware works with electrical signal (basically it's an ON/OFF behaviour) which is well logically translated by the binary system (digits 0...
Long story short: how to print in a terminal the binary digits constituting a file e.g. a library .so or a simple text .txt file PC hardware works with electrical signal (basically it's an ON/OFF behaviour) which is well logically translated by the binary system (digits 0s and 1s). Visualizing the content of a file wou...
7
1,282
2
3
5
[ "<terminal><hardware><binary><xxd>" ]
2021-08-07T08:17:36.237
2021-08-09T19:51:13.513
186,963
null
[ { "id": 663658, "body": "<p><code>xxd</code> can give binary output. Example below.</p>\n<pre><code>$ cat foo\nHello World\n$ xxd -b foo\n00000000: 01001000 01100101 01101100 01101100 01101111 00100000 Hello\n00000006: 01010111 01101111 01110010 01101100 01100100 00001010 World.\n$\n</code></pre>\n", ...
`xxd` can give binary output. Example below. ``` $ cat foo Hello World $ xxd -b foo 00000000: 01001000 01100101 01101100 01101100 01101111 00100000 Hello 00000006: 01010111 01101111 01110010 01101100 01100100 00001010 World. $ ```
# How to print zeros and ones of a file **Tags:** <terminal><hardware><binary><xxd> **Question (score 7):** Long story short: how to print in a terminal the binary digits constituting a file e.g. a library .so or a simple text .txt file PC hardware works with electrical signal (basically it's an ON/OFF behaviour) wh...
1,015
253
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
663,936
unix.stackexchange.com
If using while read loops for text processing in bash is bad...what should I do, then?
<p>I guess this may be a naive question but I can't get my head around so I felt like asking... I was searching for some solution to a problem, when I found <a href="https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice/169720">this very interesting post</a> a...
I guess this may be a naive question but I can't get my head around so I felt like asking... I was searching for some solution to a problem, when I found this very interesting post (https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice/169720) about why is usi...
14
5,160
6
12
5
[ "<bash><shell-script><shell>" ]
2021-08-09T14:26:10.443
2021-08-12T06:33:24.863
352,134
663,945
[ { "id": 663945, "body": "<p>The point of the post you linked to is to explain that <em>using bash to parse text files is a bad idea in general</em>. It isn't specifically about using loops and there is nothing intrinsically wrong with shell loops in other contexts. Nobody is saying that a shell script with ...
The point of the post you linked to is to explain that using bash to parse text files is a bad idea in general. It isn't specifically about using loops and there is nothing intrinsically wrong with shell loops in other contexts. Nobody is saying that a shell script with `while` is somehow bad. That other post is saying...
# If using while read loops for text processing in bash is bad...what should I do, then? **Tags:** <bash><shell-script><shell> **Question (score 14):** I guess this may be a naive question but I can't get my head around so I felt like asking... I was searching for some solution to a problem, when I found this very i...
8,716
2,179
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
664,541
unix.stackexchange.com
Evaluate large file with ^H and ^M characters
<p>I have a logfile that contains many <code>^H</code> and <code>^M</code> characters, as the process that produces this file updates a text based progress bar.</p> <p>When using <code>cat</code> the output is evaluated and appears human readable and concise. Below is an example output.</p> <pre><code>Epoch 11/120 4355...
I have a logfile that contains many `^H` and `^M` characters, as the process that produces this file updates a text based progress bar. When using `cat` the output is evaluated and appears human readable and concise. Below is an example output. ``` Epoch 11/120 4355/4355 [==============================] - ETA: 0s - los...
5
185
2
5
0
[ "<bash><cat>" ]
2021-08-13T11:33:42.393
2021-08-24T10:33:57.357
486,714
665,959
[ { "id": 665959, "body": "<p><strong>Posting this as an answer for clarity.</strong></p>\n<p>As <em>rowboat</em> pointed out, in this case the command <code>awk -F '\\r' '{print $NF}' file</code> works as intended, by removing everything after the last carriage return. Though this is not robust as <em>zevzek...
Posting this as an answer for clarity. As rowboat pointed out, in this case the command `awk -F '\r' '{print $NF}' file` works as intended, by removing everything after the last carriage return. Though this is not robust as zevzek pointed out. I wrote a more robust solution in C++ below. ``` #include #include #include ...
# Evaluate large file with ^H and ^M characters **Tags:** <bash><cat> **Question (score 5):** I have a logfile that contains many `^H` and `^M` characters, as the process that produces this file updates a text based progress bar. When using `cat` the output is evaluated and appears human readable and concise. Below ...
4,303
1,075
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
664,625
unix.stackexchange.com
Debian kernel - why do I need the firmware file if the driver is compiled in the kernel?
<p>I am using <a href="https://www.mouser.sg/ProductDetail/Olimex-Ltd/MOD-WIFI-R5370-ANT?qs=J7x7253A5u4LBh0Sy0UYWQ==" rel="noreferrer">this usb wifi device</a> on Debian running on my <a href="https://www.mouser.sg/new/terasic-technologies/terasic-de10-nano-kit/" rel="noreferrer">DE10-Nano board</a>.</p> <p>Looking at ...
I am using this usb wifi device (https://www.mouser.sg/ProductDetail/Olimex-Ltd/MOD-WIFI-R5370-ANT?qs=J7x7253A5u4LBh0Sy0UYWQ==) on Debian running on my DE10-Nano board (https://www.mouser.sg/new/terasic-technologies/terasic-de10-nano-kit/). Looking at the product details, it seems like this uses the RT5370 chipset whic...
12
2,417
3
2
3
[ "<debian><linux-kernel><kernel-modules>" ]
2021-08-14T02:35:40.760
2021-08-15T13:21:17.910
324,101
664,626
[ { "id": 664626, "body": "<p>Many hardware device manufacturers do not embed firmware into their devices, they require firmware to be loaded into the device by the operating system's driver.</p>\n<p>Some other manufacturers embed an old version of the firmware but allow an updated version to be loaded by the...
Many hardware device manufacturers do not embed firmware into their devices, they require firmware to be loaded into the device by the operating system's driver. Some other manufacturers embed an old version of the firmware but allow an updated version to be loaded by the driver - quite often the embedded version is an...
# Debian kernel - why do I need the firmware file if the driver is compiled in the kernel? **Tags:** <debian><linux-kernel><kernel-modules> **Question (score 12):** I am using this usb wifi device (https://www.mouser.sg/ProductDetail/Olimex-Ltd/MOD-WIFI-R5370-ANT?qs=J7x7253A5u4LBh0Sy0UYWQ==) on Debian running on my ...
5,055
1,263
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
664,745
unix.stackexchange.com
Partially resolve/follow symlinks when globbing in zsh/Bash
<p>Assume I have a file <code>a</code> which is a symlink to <code>b</code>, which in turn is a symlink to <code>c</code>.</p> <p>With zsh's <code>:A</code> modifier, globbing a will result in an absolute path, resolving all symlinks, hence <code>a(:A)</code> will expand to the absolute path of <code>c</code> (on syste...
Assume I have a file `a` which is a symlink to `b`, which in turn is a symlink to `c`. With zsh's `:A` modifier, globbing a will result in an absolute path, resolving all symlinks, hence `a(:A)` will expand to the absolute path of `c` (on systems that have the `realpath` library). Is it possible to get `b` (absolute or...
5
139
1
0
1
[ "<bash><zsh><symlink><wildcards>" ]
2021-08-15T09:36:51.950
2021-08-16T07:17:52.510
293,900
664,746
[ { "id": 664746, "body": "<p>You can always create a function to be used with the <code>+</code> glob qualifier:</p>\n<pre>\n$ zmodload zsh/stat\n$ resolve() { [[ -L $REPLY ]] && stat -A REPLY +link -- ${1-$REPLY}; }\n$ print -r - a(+resolve)\nb\n$ print -r - a(+resolve:a)\n/home/stephane/b <sup><sub>(though...
You can always create a function to be used with the `+` glob qualifier: ``` $ zmodload zsh/stat $ resolve() { [[ -L $REPLY ]] && stat -A REPLY +link -- ${1-$REPLY}; } $ print -r - a(+resolve) b $ print -r - a(+resolve:a) /home/stephane/b (though see caveat below) ``` Note that if you do `a(+resolve+resolve)`, the seco...
# Partially resolve/follow symlinks when globbing in zsh/Bash **Tags:** <bash><zsh><symlink><wildcards> **Question (score 5):** Assume I have a file `a` which is a symlink to `b`, which in turn is a symlink to `c`. With zsh's `:A` modifier, globbing a will result in an absolute path, resolving all symlinks, hence `a...
2,136
534
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...
664,905
unix.stackexchange.com
Why does not Debian upgrade to Bookworm, even that sources.list defines 'testing'?
<p>After Debian 11 &quot;bullseye&quot; <a href="https://www.debian.org/News/2021/20210814" rel="noreferrer">was released on August 14th, 2021</a>, the <strong>Debian 12 &quot;bookworm&quot;</strong> is now the <a href="https://www.debian.org/releases/testing/" rel="noreferrer">official &quot;testing&quot; distribution...
After Debian 11 "bullseye" was released on August 14th, 2021 (https://www.debian.org/News/2021/20210814), the Debian 12 "bookworm" is now the official "testing" distribution (https://www.debian.org/releases/testing/). Why is my Debian still on bullseye, instead of automatically updating to bookworm, even my sources all...
8
3,296
1
1
0
[ "<debian><apt><upgrade><testing>" ]
2021-08-16T15:37:48.413
2021-08-16T15:48:44.760
369,770
664,907
[ { "id": 664907, "body": "<p>How the installed distribution names itself is determined by <a href=\"https://tracker.debian.org/pkg/base-files\" rel=\"nofollow noreferrer\">the <code>base-files</code> package</a>, and that can’t be updated for Bookworm before Bullseye is released, which means that Bookworm ca...
How the installed distribution names itself is determined by the `base-files` package (https://tracker.debian.org/pkg/base-files), and that can’t be updated for Bookworm before Bullseye is released, which means that Bookworm carries the same version as Bullseye when it is initially created (this is true for all new sui...
# Why does not Debian upgrade to Bookworm, even that sources.list defines 'testing'? **Tags:** <debian><apt><upgrade><testing> **Question (score 8):** After Debian 11 "bullseye" was released on August 14th, 2021 (https://www.debian.org/News/2021/20210814), the Debian 12 "bookworm" is now the official "testing" distr...
3,637
909
{ "source": "stackexchange-archive.org", "license": "CC BY-SA 4.0", "dump_version": "2021-12-07", "extraction_date": "2026-07-02T12:57:40Z", "parser_version": "stackexchange-streaming-v1.0", "site_name": "unix.stackexchange.com", "original_7z_url": "https://archive.org/download/stack-exchange-2021-12-07/u...