date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,403,460,625,000 |
I was testing bache on raspberry pi 4 with ubuntu. The reason I choose ubuntu that I found standard raspbian got some issues with bcache as kernel module not properly loaded. I tried to troubleshoot bit but then I move to ubuntu and it works straight away
My setup is like this.
1 x 1TB HGST 5400RPM 2.5 laptop hard dis... |
I managed to solve this issue with the instructions of https://www.raspberrypi.org/forums/viewtopic.php?t=245931 this topic.
This is due to Raspberry PI 4 USB 3.0 UASP driver issue and it make my external SSD connection intermittent. After adding line to cmdline.txt for ignore the UAS interface my SSD is working flaw... | Testing bcache with raspberry pi 4 on ubuntu |
1,403,460,625,000 |
In my new Fedora 31 install there is no \dev\bcache0. The caching device is Raid 1:
# ls -d /dev/b*
/dev/block /dev/bsg /dev/btrfs-control /dev/bus
# bcache-super-show /dev/md127
sb.magic ok
sb.first_sector 8 [match]
sb.csum CDCAF0DD6B68FD24 [match]
sb.version 1 ... |
I managed to do it:
# echo 1 > /sys/block/md127/bcache/stop; echo 1 > /sys/block/md127/bcache/detach; sleep 2; echo /dev/md127 > /sys/fs/bcache/register
# echo 32dbab45-f8b3-4ef8-89e2-32007fc4970b > /sys/block/md127/bcache/attach
# ll /dev/bcache0
brw-rw----. 1 root disk 252, 0 Jan 5 12:56 /dev/bcache0
| Missing bcache0 backing device |
1,403,460,625,000 |
Suppose I want to replace the crusty old HDD I'm using as a backing device with a new one. Can I transfer my data to the new device without having to set up.an entirely new bcache?
|
Yes in theory because the new device should have the same UUID as the old one if you perform a block level copy.
| Replace Bcache Backing Device |
1,402,998,002,000 |
I am trying to use arrays in Bourne shell (/bin/sh). I found that the way to initialize array elements is:
arr=(1 2 3)
But it is encountering an error:
syntax error at line 8: `arr=' unexpected
Now the post where I found this syntax says it is for bash, but I could not find any separate syntax for Bourne shell. Does... |
/bin/sh is hardly ever a Bourne shell on any systems nowadays (even Solaris which was one of the last major system to include it has now switched to a POSIX sh for its /bin/sh in Solaris 11). /bin/sh was the Thompson shell in the early 70s. The Bourne shell replaced it in Unix V7 in 1979.
/bin/sh has been the Bourne s... | Arrays in Unix Bourne Shell |
1,402,998,002,000 |
I am writing an installation script that will be run as /bin/sh.
There is a line prompting for a file:
read -p "goat may try to change directory if cd fails to do so. Would you like to add this feature? [Y|n] " REPLY
I would like to break this long line into many lines so that none of them exceed 80 characters. I'm t... |
First of all, let's decouple the read from the text line by using a variable:
text="line-1 line-2" ### Just an example.
read -p "$text" REPLY
In this way the problem becomes: How to assign two lines to a variable.
Of course, a first attempt to do that, is:
a="line-1 \
line-2"
Written as that, the var a a... | How to break a long string into multiple lines in the prompt of read -p within the source code? |
1,402,998,002,000 |
I know how to create an arithmetic for loop in bash.
How can one do an equivalent loop in a POSIX shell script?
As there are various ways of achieving the same goal, feel free to add your own answer and elaborate a little on how it works.
An example of one such bash loop follows:
#!/bin/bash
for (( i=1; i != 10; i++ )... |
I have found useful information in Shellcheck.net wiki, I quote:
Bash¹:
for ((init; test; next)); do foo; done
POSIX:
: "$((init))"
while [ "$((test))" -ne 0 ]; do foo; : "$((next))"; done
though beware that i++ is not POSIX so would have to be translated, for instance to i += 1 or i = i + 1.
: is a null comm... | How can I create an arithmetic loop in a POSIX shell script? |
1,402,998,002,000 |
I’m looking for an “in” operator that works something like this:
if [ "$1" in ("cat","dog","mouse") ]; then
echo "dollar 1 is either a cat or a dog or a mouse"
fi
It's obviously a much shorter statement compared to, say, using several "or" tests.
|
You can use case ... esac
$ cat in.sh
#!/bin/bash
case "$1" in
"cat"|"dog"|"mouse")
echo "dollar 1 is either a cat or a dog or a mouse"
;;
*)
echo "none of the above"
;;
esac
Ex.
$ ./in.sh dog
dollar 1 is either a cat or a dog or a mouse
$ ./in.sh hamster
none of the above
With ksh, bash -O extgl... | Is there an "in" operator in bash/bourne? |
1,402,998,002,000 |
I wrote a small script today which contained
grep -q ^local0 /etc/syslog.conf
During review, a coworker suggested that ^local0 be quoted because ^ means "pipe" in the Bourne shell. Surprised by this claim, I tried to track down any reference that mentioned this. Nothing I found on the internet suggested this was a pr... |
The ^ character as a synonym of | dates back from the Thompson shell. They were introduced at the same time in Unix v4 and are mentioned together in the man page. Sven Mascheck mentions that ^ was “probably [introduced] for reasons of convenience on early upper-case-only terminals” where typing | was “somewhat of a pa... | Use of ^ as a shell metacharacter |
1,402,998,002,000 |
I am looking at a script that has:
if [ "${PS1-}" ]; then
That trailing - bugs me a bit because it doesn't seem to Posix or Bash standard syntax. It this some arcane syntax that has been around forever, or is it a typo? Any references to standards / docs would be appreciated.
Normally I would code it:
if [ "$PS1" ]; ... |
This is definitely POSIX syntax. Paraphrasing:
Using ${parameter-word}, if parameter is
set and not null, then substitute the value of parameter,
set but null, then substitute null, and
unset, then substitute word.
Example session:
$ echo "${parameter-word}"
word
$ parameter=
$ echo "${parameter-word}"
$ parameter=... | Is "${PS1-}" valid syntax and how does it differ from plain "$PS1"? |
1,402,998,002,000 |
Trying here to write a shell script that keeps testing my server and email me when it becomes down.
The problem is that when I logout from ssh connection, despite running it with & at the end of command, like ./stest01.sh &, it automatically falls into else and keeps mailing me uninterruptedly, until I log again and k... |
When GNU grep tries to write its result, it will fail with a non-zero exit status, because it has nowhere to write the output, because the SSH connection is gone.
This means that the if statement is always taking the else branch.
To illustrate this (this is not exactly what's happening in your case, but it shows what ... | Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout |
1,402,998,002,000 |
I am on a closed network (i.e. no connectivity to the internet).
I have a bourne shell script that asks for the user to enter a regular expression for use with grep -P.
Generally speaking, I like to do some form of input validation.
Is there a way to test a string variable to see if it is a (valid) regex?
(Copying thi... |
No, but with some tools it's not hard to test whether a regex compiles or not.
For example, with grep: echo | grep -P '[' - the exit code, $?, will be 2, indicating an error occurred (and for this example, grep will print "grep: missing terminating ] for character class" to stderr - you can redirect stderr to /dev/nul... | Does Bourne Shell have a regex validator? |
1,402,998,002,000 |
#!/bin/sh
CONFIG_DIR="/var/opt/SUNWldm/"
read option
if [ $option -eq 9 ]; then
ret=1
elif [ -e ${CONFIG_DIR}file.xml.${option} ]; then
echo "TRUE"
fi
I have the above code in a while loop to present a list of options. Unfortunately I'm having problems with the elfi statement.
From: IF for Beginners... |
The Bourne shell is somewhat of an antique. The Solaris version doesn't have the -e operator for the test (a.k.a. [) builtin that was introduced somewhat late in the life of the Bourne shell¹ and enshrined by POSIX.
As a workaround, you can use -f to test for the existence of a regular file, or -r if you aren't intere... | bourne shell if [ -e $directory/file.$suffix ] |
1,402,998,002,000 |
I have two scripts that need to run and both require the same variables set the same way. As a result I figured I'd break the setting of the variables out into a separate script. However, I can't seem to get this to work right where the variables are showing in the main script.
For example, this is my main script:
#!/... |
Sourcing your script only sets shell variables, while printenv shows environment variables. You will have to export the variables for printenv to show them. You may have meant to use set instead, which will show shell variables.
You could have made this script:
#!/bin/sh
export MYVAR=MYVAL
echo "EXECUTED!!"
(given... | SH: How to make vars from one script available in the main script? |
1,402,998,002,000 |
I am reading the source code of the Maven wrapper written for the Bourne shell. I came across these lines:
if [ -z "$JAVA_HOME" ]; then
javaExecutable="$(which javac)"
if [ -n "$javaExecutable" ] && ! [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ]; then
# snip
expr when used with arg1 and arg2 and a : m... |
Classically, which was a csh script, and it printed an error message like no foo in /usr/bin:/bin and returned a success status. (At least one common version, there may have been others that behaved differently.) Example from FreeBSD 1.0 (yes, that's ancient):
if ( ! $?found ) then
echo no $arg in $path
en... | Does any implementation of `which` output "no" when executable cannot be found? |
1,402,998,002,000 |
In a POSIX sh, or in the Bourne shell (as in Solaris 10's /bin/sh), is it possible to have something like:
a='some var with spaces and a special space'
printf "%s\n" $a
And, with the default IFS, get:
some
var
with
spaces
and
a
special space
That is, protect the space between special and space by some combination of... |
Not really.
One solution is to reserve a character as the field separator. Obviously it will not be possible to include that character, whatever it is, in an option. Tab and newline are obvious candidates, if the source language makes it easy to insert them. I would avoid multibyte characters if you want portability (... | Is it possible to "protect" an IFS character from field splitting? |
1,402,998,002,000 |
Could someone please explain to me why my while loop seems to have an internal scope? I've seen multiple explanations online but they all have to do with pipes. My code has none.
The code:
#!/bin/sh
while read line
do
echo "File contents: $line"
echo
if [ 1=1 ]; then
test1=bob
fi
echo "While scope:"
... |
In the Bourne shell, redirecting a compound command (like your while loop) runs that compound command in a subshell.
In Solaris 10 and earlier1, you don't want to use /bin/sh as it's the Bourne shell. Use /usr/xpg4/bin/sh or /usr/bin/ksh instead to get a POSIX sh.
If for some reason you have to use /bin/sh, then to wo... | Variable scope in while-read-loop on Solaris |
1,402,998,002,000 |
I'm trying to get a (bourne shell) variable to expand like "$@" so it produces multiple words with some having preserved spaces. I've tried defining the variable in many different ways but still can't get it to work:
#!/bin/sh
n=\"one\ two\"\ three
for i in "$n"; do
echo $i
done
I want to define the variable so the ... |
So bourne shell (IIRC) doesn't support arrays. You can still use "$@"
set -- "one two" three
for i in "${@}" ; do
echo "$i"
done
Outputs:
one two
three
Tested on AIX 7.1 bsh.
| "$@" expansion for user defined variables |
1,402,998,002,000 |
I am attempting to write a script that automates the installation of ports/packages on new FreeBSD installs. To do this, the user who executes the script must be root.
The system is "supposed" to be virgin meaning bash and sudo may or may not be installed; so I am trying to account for it. To do this, I am checking... |
I would check the value of id -u, which is specified to:
Output only the effective user ID, using the format "%u\n".
Perhaps like this:
if [ $(id -u) -eq 0 ]
then
: root
else
: not root
fi
| Checking for root user in sh and bash [duplicate] |
1,402,998,002,000 |
Arising from this discussion:
When I have (zsh 5.8, bash 5.1.0)
var="ASCII"
echo "${var} has the length ${#var}, and is $(printf "%s" "$var"| wc -c) bytes long"
the answer is simple: these are 5 characters, occupying five bytes.
Now, var=Müller yields
Müller has the length 6, and is 7 bytes long
Which suggests the... |
In POSIX compliant shells (not the Bourne shell, that feature comes from the Korn shell), ${#var} like wc -m counts the number of characters¬π in $var and the behaviour is unspecified if the sequence of bytes stored in $var cannot be decoded to characters in the current locale.
Bytes are decoded into characters as per... | What is "length" of a string in Bourne shell compatibles' `${#string}`? |
1,402,998,002,000 |
I'm reading a shell script for adding a progress bar to certain processes (found here). I'm having trouble understanding this (optional) line:
#BAR_EXT=${BAR_EXT-}
The comment says that this will add an extension to each file, and maybe I just need to read further, but I'm not familiar with that use of the - operator... |
Does the script contain the command set -u?
That means
Treat unset variables and parameters
other than the special parameters "@" and "*"
as an error when performing parameter expansion.
If expansion is attempted on an unset variable or parameter,
the shell prints an error message,
and, if not interactive... | Bourne shell: trailing `-` operator in parameter substitution |
1,402,998,002,000 |
I want to try out Bourne shell on FreeBSD so I am starting to set it up for my use.
In .shrc, I set my prompt, enabled vi mode, set some aliases, and exported some variables.
However, I see that .profile also, by default, exports some variables.
It is my understanding that Bourne shell will source .profile on each sta... |
The closest thing to the Bourne shell, which wasn't really an open source program and cannot be found on pretty much any operating system nowadays, is the Heirloom Bourne shell from OpenSolaris, which is shells/heirloom-sh in the FreeBSD ports collection (usually installed under /usr/ports).
Note that this is not sh.
... | What is the difference between .shrc and .profile? |
1,402,998,002,000 |
I have a bash script which will be called by /bin/sh on a Solaris machine. When I run the script as /bin/sh ./solarisSh, it works. When I source the same script, it fails.
I know bash and Bourne Shell are almost nothing alike. This is not my question.
My question is: Why does Solaris /bin/sh behave so differentl... |
Deleting the $(...) command substitution removes the failure for me on 5.10. That suggests that what you're seeing is the effect of . parsing the entire file before it executes, and encountering an error at that unsupported syntax. By contrast, the script is being parsed line-by-line, so it exits before the syntax err... | Solaris /bin/sh sourcing a file behaves differently than executing a file. Why? |
1,402,998,002,000 |
Suppose I'm running bash on a Unix-ish system - not necessarily Linux and not necessarily very new; and it may not have every bit of software I'd like.
Now, I have a relative path for which I want to get the absolute path. What's the most robust and portable way of doing this?
The answers here seem to mostly assume th... |
I am not sure if the environment variable $PWD was set in the bourne shell, but the command pwd exists since the old minix and is part of POSIX, so:
abs_path="$(cd "$rel_path" && pwd -P)"
| How do I convert a relative to an absolute path, portably and robustly? |
1,402,998,002,000 |
Need improvement on a script which continuously tests website.
It's currently been used the following script, but it is giving a large amount of failing emails, while website is still up:
#!/bin/bash
while true; do
date > wsdown.txt ;
cp /dev/null pingop.txt ;
ping -i 1 -c 1 -W 1 website.com > pingop.txt ;... |
You don't need ; at the end of each line, this is not C.
You don't need:
cp /dev/null pingop.txt
because the very next line in the script
ping -i 1 -c 1 -W 1 google.com > pingop.txt
will overwrite contents of pingop.txt anyway. And if we're here, you
don't even need to save output of ping to the file if you're not
g... | Need Improvement on Script Which Continuously Tests Website |
1,402,998,002,000 |
This works fine:
#!/bin/sh
ALTER="$1"
NAME="$2"
for pr in $(pgrep $NAME); do
elapse=$(ps -o etime= -p $pr)
[ "${elapse%:*}" -gt "$ALTER" ] && echo $pr
done
But if I try to switch it to CShell:
#!/bin/csh
set ALTER = "$1"
set NAME = "$2"
for pr in $(pgrep $NAME); do
set elapse = $(ps -o etime= -p $pr)
... |
The first thing you should know about scripting in csh is that it is usually a very bad idea. That said, if you insist, the problems with your script are:
csh doesn't support the $() construct for command substitution, use ` ` instead.
csh doesn't support the for i ... do ... done syntax, use foreach i ... end instea... | Bourne Shell to CShell |
1,402,998,002,000 |
What do the letters PS stand for in $PS1?
Is it actually "Prompt String"?
Where did $PS1 first appear?
|
The V7 sh.1 man page defines PS1 as
Primary prompt string, by default ‘$ ’.
So yes, letters P and S in PS1 stand for “prompt string”.
PS1 was introduced with the Bourne shell in V7; older shells didn’t have anything like this. The Thompson shell, used before V7, didn’t have variables at all. The PWB (Mashey) shell i... | What is the etymology of $PS1? [closed] |
1,402,998,002,000 |
My problem definition is : 1.Write a Bourn shell script dTOe which takes as an input any number between 0 and 999 and prints the English value for this number. I am struggling with above problem. Could you give me any hints or helps?
#! /bin/bash
number=$1
if [ $number -lt 0 -o $number -gt 999 ]
then
echo put t... |
Think about how your thought process works for translating from digit form to prose form. What do you look at first? What do you do with that information? Is there a pattern to your workflow that you could express in a procedural form? How can this be broken into small, discrete steps which are analogous to the co... | How to use switch case in my case? |
1,402,998,002,000 |
From a bash or sh shell, how can I determine if it was called with the bash or sh command, a login shell, an xterm, and, in the case of the former, how was that called?
For example, if I call bash from an xterm, and then call it again, inside that instance, it might output something like
me@mylinuxmachine:~$ bash
me@m... |
You may use pstree for this:
$ bash
bash-4.4$ pstree -p "$$"
-+= 00001 root /sbin/init
\-+= 85460 kk tmux: server (/tmp/tmux-1000/default) (tmux)
\-+= 96572 kk -ksh93 (ksh93)
\-+= 72474 kk bash
\-+= 14184 kk pstree -p 72474
\-+- 51965 kk sh -c ps -kaxwwo user,pid,ppid,pgid,command
\... | Determine how bash or sh was called |
1,402,998,002,000 |
I'm trying to read two lines into two variables. In Bash I would use something like this:
cat << EOF > myfile
line1
line2
EOF
cat myfile | {
read firstline
echo $firstline # "line1" in bash and sh
read secondline
}
echo $firstline # "line1" in bash, empty in sh
echo $secondline
In Bourne Shell however $firstlin... |
(You most likely have firstline set already when you tested that code in bash, its value should be empty at the end).
When running the pipeline
cat myfile | { read firstline; read secondline; }
the right hand side is running in a subshell. Not because of the { ...; } but because it's part of a pipeline. The subshel... | Reading multiple lines in Bourne Shell |
1,402,998,002,000 |
I'm trying to execute rsync from a Bourne shell script (read: Bash extensions not available) and after lots of searching, single/double quotes combinations, escapes, etc, I wasn't able to correctly pass the --out-format='%n' argument.
For example, this script:
#!/bin/sh
(set -x ; $(rsync -auh --delete --out-format='%... |
You are running the rsync command in a command substitution. A command substitution will be replaced by the output of the command within it, and the way your script is written, this output will be executed as a command, which is why you get that error message and the seemingly weird tracing output.
Instead:
#!/bin/sh ... | Passing --out-format=FMT argument to rsync from Bourne shell script |
1,402,998,002,000 |
I ask in that way, because according to https://unix.stackexchange.com/a/46856/84749, when I start screen it's an "interactive, non-login" I'm doing. What's actually happening is I'm logging into a Bourne shell (not BASH) system, and when I do, it runs ~/.profile just fine, and sets up my aliases. But when I run scree... |
A login sh session reads the user's ~/.profile upon invocation. If the ENV variable is set to a filename after doing that, and if that file exists, the shell will use that file to further initialize the login session.
Interactive shells that are not login shells will only use $ENV if ENV is set, but will not read ~/.p... | Bourne shell: what does it execute on interactive, non-login? |
1,402,998,002,000 |
bash v3.2 (though I think holds for newer versions too):
In section 3.7.4 Environment, the docs say:
On invocation, the shell
scans its own environment and creates a parameter for each name found, automatically marking it for export to child processes.
And later in Appendix B Major Differences From The Bourne
Shell,... |
"Variables present in the shell’s initial environment are automatically exported to child processes. The Bourne shell does not normally do this unless the variables are explicitly marked using the export command.".
Consider:
% export FOO=abc
% bash -c 'FOO=xyz; echo "bash: FOO=$FOO"; echo "env:"; env |grep FOO'
bash... | export command behaviour in bash vs bourne shell |
1,402,998,002,000 |
Is the relation between Bourne shell and Bash similar to that of C and C++(if so it would signify that both have their place as a shell)? Whenever I read something about shells it always says that Bourne shell is dead and obsolete, but why?
|
It is most unlikely that you really use the Bourne Shell it is more likely that you are using dash (The Debian Almquist Shell). You may like to check this by calling:
echo $0
The exact name of the shell may be retrieved via the whatshell script from https://www.in-ulm.de/~mascheck/various/whatshell/
But dash is not ... | Why is Bourne shell considered obsolete? [closed] |
1,402,998,002,000 |
I keep two copies of the same source code tree: One is the "working copy", and the other is the "stored copy". When I finish editing the "working copy", I refresh the "stored copy" with rsync (only modified files will be copied and, moreover, deleted files in the working copy will be deleted in the stored one as well)... |
Given the constraints explained in the question and comments, I would start by removing the differences between the style guidelines used for the working copy and the stored copy. However I understand that can be very difficult, so feel free to ignore that advice.
I don’t think rsync (i.e., filtering the files while t... | Mirror-like of source code tree applying beautifier to modified files only |
1,402,998,002,000 |
I would like to use find on a directory structure to exit if at least
one file exists with a target condition, because this will lead to a failure of the rest of a shell script.
Since this shell script is intended to run on big directory structures I would like to exit of it as soon as possible.
For example I would li... |
Note that -prune just stops recursion into subdirectories; it doesn't stop at the first found entry. You probably want -quit with GNU or FreeBSD find or -exit with NetBSD find:
$ find . -name test
./test
./Y/test
$ find . -name test -print -quit
./test
Instead of testing the return code of find, you can test the o... | find exiting on 1st found and return code |
1,402,998,002,000 |
I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the Bourne shell that I do not know about?
#! /bin/sh
NAME=$1
if((test -e "$NAME"));then
echo File $NAME present
else
echo F... |
You don't need the enclosing parentheses, test itself would suffice:
if test -e "$NAME"; then
The (()) is for arithmetic comparison operations.
test is synonymous to [ command, so you can use:
if [ -e "$NAME" ]; then
too.
Also some shell has the [[ keyword:
if [[ -e "$NAME" ]]; then
| syntax error: invalid arithmetic operator (error token is ".c") |
1,402,998,002,000 |
What does the >|-redirection in bash do?
I just found out, that echo text >| somefile creates the file somefile (if not existing yet), and fills it with text. Similar as echo text > somefile would do.
Further experiments suggest that the >|-redirection behaves as the >-redirection does.
So, what is the >|-redirection... |
It is in the bash manual (3.6.2 Redirecting Output):
If the redirection operator is >|, or the redirection operator is > and
the noclobber option to the set builtin command is not enabled, the redirection is attempted even if the file named by word exists.
| What does a ">|"-redirection ("greater-pipe"-redirection) mean? [duplicate] |
1,402,998,002,000 |
I have a program that is currently working, but I need to modify it to ignore some stdin that is not fitting for its correct function.
Right now, to run the program:
printf "1\n3\n5\n" | sh prog
The program currently ignores non-integer input (like floats), but I also need it to ignore something like '4 10' on the sam... |
You can do...
while read line
do line=${line%%[!0-9]*}
[ -n "$line" ] || continue
: work w/ digits at line's head
done
Alternatively - and probably faster - you can do:
tr -cs 0-9\\n \ |
while IFS=\ read num na
do ${num:+":"} continue
: work w/ first seq of digits on line
done
Or is if you w... | Bourne shell: ignoring certain kinds of stdin |
1,402,998,002,000 |
I understand the concepts of terminal, console, shell and their differences. I know a shell today is an interpreter that communicates with the OS kernel to perform some actions and does it through terminal applications.
But in the old days when computers didn't had GUI, all the interaction a user had with a computer ... |
Not "the old days" — we still use computers without GUIs, because we have servers, embedded systems, and even some folks who prefer to have no graphical environment on their home workstations.
When you start up your computer, or SSH in, or whatever: yes, you're greeted with $ (or a login prompt first, depending). It's... | How was a shell like when operating systems didn't had a GUI? [closed] |
1,402,998,002,000 |
Help with deciphering commands
[ $1 -ge 20 ] && telnetd -p 233 -l /bin/sh
I know /bin/sh is a Bourne shell and telnetd is a telnet daemon but I'm not sure how they work together. I think someone tried to leave a back door open but I'm not sure what / how the other commands work together.
Thanks
|
In the context of FreshTomato, what the command does is, if the variable $1 is greater or equal to 20, then run a telnet daemon on port 233 that will drop you inside a shell.
[ $1 -ge 20 ] && telnetd -p 233 -l /bin/sh
$1 is the number of seconds the SES/WPS/AOSS button has been pressed
-p is the port number
-l to li... | Help with a deciphering command with telnetd in it |
1,402,998,002,000 |
I can sort the files either in descending order (of any size) or list all files greater than 1000 bytes but don't know how to sort files greater than 1000 bytes in a user specified directory.
List files greater than 1000 bytes :
for i in "$1/*" # $1 expects a directory name
do
if [ `wc -c $i` -gt 1000 ]
ec... |
Try this:
find . -maxdepth 1 -size +1000c -type f -exec ls -lhSa '{}' +
Explanation:
-maxdepth 1 - find files only in current directory
-size +1000c - find only files greather than 1000 bytes ("c" = bytes)
-type f - find only files
-exec <command> {} + - execute command. See man find for more information
If you do no... | sort files greater than 1000 bytes in descending order |
1,402,998,002,000 |
Sorry about the title it may not be clear. Here is the complete explanation of my doubt. I am writing the below shell script and expecting the mentioned output.
#!/bin/bash
python3
print("Hello World")
exit()
echo "The execution is completed"
The output what i am expecting is, it should enter the python3 interpreter ... |
#!/bin/bash
python3
print("Hello World")
exit()
echo "The execution is completed"
Scripts work differently from typing commands directly in a terminal, ie. what you want to do won't work this easily.
The #!/bin/bash line tells the kernel that the program it's trying to start is a script that need to be run with /bi... | How to get into python environment and run some python commands and return to normal terminal using shell script |
1,402,998,002,000 |
I set JAVA_HOME in .zshrc:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/
which is fine for interactive programs. But I have JVM programs running via cron, which uses Bourne shell. The bourne shell programs keep giving me this:
groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/default... |
Assuming you are referring to your own user's crontab, to avoid duplicating the definition of JAVA_HOME you can export the variable in ~/.zshenv (instead of ~/.zshrc), which is read even in non-interactive, non-login shells, and run zsh -c 'sh /path/to/script' in your cron job (replacing sh, based on what the program ... | Sharing environment variables between zsh and bourne shell (for crontab) |
1,350,390,457,000 |
I searched SO and found that to uppercase a string following would work
str="Some string"
echo ${str^^}
But I tried to do a similar thing on a command-line argument, which gave me the following error
Tried
#!/bin/bash
## Output
echo ${1^^} ## line 3: ${1^^}: bad substitution
echo {$1^^} ## No error, bu... |
The syntax str^^ which you are trying is available from Bash 4.0 and above. Perhaps yours is an older version (or you ran the script with sh explicitly):
Try this:
str="Some string"
printf '%s\n' "$str" | awk '{ print toupper($0) }'
| How to uppercase the command line argument? |
1,350,390,457,000 |
I would like to list all files matching a certain pattern while ignoring the case.
For example, I run the following commands:
ls *abc*
I want to see all the files that have "abc" as a part of the file name, ignoring the case, like
-rw-r--r-- 1 mtk mtk 0 Sep 21 08:12 file1abc.txt
-rw-r--r-- 1 mtk mtk 0 Sep 21 08:12 fi... |
This is actually done by your shell, not by ls.
In bash, you'd use:
shopt -s nocaseglob
and then run your command.
Or in zsh:
unsetopt CASE_GLOB
Or in yash:
set +o case-glob
and then your command.
You might want to put that into .bashrc, .zshrc or .yashrc, respectively.
Alternatively, with zsh:
setopt extendedglob
... | How to match case insensitive patterns with ls? |
1,350,390,457,000 |
Why is this?
When I do this
CD ~/Desktop
It doesn't take me to the Desktop. But this:
echo "foo
bar" | GREP bar
gives me:
bar
|
From your other questions I take it you're using OS X. The default HFS+ filesystem on OS X is case-insensitive: you can't have two files called "abc" and "ABC" in the same directory, and trying to access either name will get to the same file. The same thing can happen under Cygwin, or with case-insensitive filesystems... | Why can Shell builtins not be run with capital letters but other commands can? |
1,350,390,457,000 |
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 foll... |
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 entries in... | What does “Case sensitivity is a function of the Linux filesystem not the Linux operating system” mean? |
1,350,390,457,000 |
In vim, I know I can search with or without case sensitivity. But if I want to search for a string in either upper or lower case, and replace it with a replacement of the same case, is that possible in a single :s///?
For example, I want to change these lines:
short
Short
SHORT
to
long
Long
LONG
I can do this in thr... |
There isn't a native feature of :s that does this as far as I know, but if you're willing to install add-ons, you could look at Michael Geddes' keepcase plugin.
| Case-preserving search and replace in vim? |
1,350,390,457,000 |
I'm working on a website conversion. The files as they were linked and served from the web server were case insensitive. But, I've made a dump of the site on my linux system and I'm writing scripts to migrate data. The problem is that I'm running into case sensitivity problems between link strings in the pages and the... |
I don't know whether your unix-flavor has a rename. Many Linuxes have, and it is part of a perl-package, if you search for a repository.
find ./ -depth -exec rename -n 'y/[A-Z]/[a-z]/' {} ";"
Above version with
rename -n
doesn't really perform the action, but only print what would be done. You omit the -n to do it... | change entire directory tree to lower-case names |
1,350,390,457,000 |
This question occurred to me the other day when I was working on a development project that relies on an opinionated framework with regard to file names. The framework (irrelevant here) wanted to see upper-case-first filenames. This got me thinking.
On a case-insensitive file system, say extFAT or HFS+ (specifically n... |
A case-insensitive filesystem just means that whenever the filesystem has to ask "does A refer to the same file/directory as B?" it compares the names of files/directories ignoring differences in upper/lowercase (exactly what upper/lowercase differences count depends on the filesystem—it's non-obvious once you get bey... | How do case-insensitive filesystems display both upper and lower case file names? |
1,350,390,457,000 |
When I search man pages, the search is case sensitive, but only with regard to upper case letters. E.g., x will match x and X whereas X only matches x. This is the man-db version of man, used on fedora derived systems by default and available on others. man man says the default pager is less -s. $LESS is not defin... |
Man is calling Less; the only control at the man level is choosing which options to call Less with.
Less's search case-sensitivity is controlled by two options.
If -I is in effect, then searches are case-insensitive: either a or A can be used to match both a and A.
If -i is in effect but not -I, then searches are cas... | Can I force `man` to do lower case sensitive matching? |
1,350,390,457,000 |
I have set GREP_OPTIONS="--ignore-case --color" in ~/.bashrc as I normally want grep to work case-insensitive. However, there are times when I need grep to actually search case-sensitive, but the man page doesn´t suggest a param for this.
How can I achieve this?
|
I probably would define an alias with my options, e.g.:
alias grep="grep --ignore-case --color"
as this would only affect interactive programs and not scripts. You could then just run \grep or /bin/grep to run it without any options.
If you want to keep using GREP_OPTIONS you can just unset it for your commandline, e... | grep: Ignoring GREP_OPTIONS to search case-sensitive |
1,350,390,457,000 |
I'm trying to see if a certain python-library is installed by grepping the output of pip list. If I try this
pip list | grep -q $package, it works fine. If I try pip list | grep -qi $package, I get the following error output
pi@pibox:~ $ pip list | grep -i -q pyyaml
Traceback (most recent call last):
File "/usr/bin/... |
With the -q flag the grep program will stop immediately when the first line of data matches.
However pip may still be trying to send data into the pipe. It will receive a SIGPIPE. And that causes the error traceback.
With the -i flag it's possible that the grep process is stopping sooner (earlier match), before pip ... | Broken pipe when grepping output, but only with -i flag |
1,350,390,457,000 |
One answer to this question mentions the UNIX 03 certification of OSX. Now AFAIK the standard file system of OSX is/was HFS, which "saves the case of a file that is created or renamed but is case-insensitive in operation" (i.e. it's case-preserving but case-insensitive).
Does the UNIX certification or POSIX require a ... |
According to the POSIX specification:
The system may provide non-standard extensions. These are features not
required by POSIX.1-2008 and may include, but are not limited to:
--snip--
Non-conforming file systems (for example, legacy file systems for which _POSIX_NO_TRUNC is false, case-insensitive file systems, or... | Does the UNIX standard require case-sensitive filesystems? |
1,350,390,457,000 |
I need to enable the case insensitive filesystem feature (casefold) on ext4 of a Debian 11 server with a backported 6.1 linux kernel with the required options compiled in.
The server has a swap partition of 2GB and a big ext4 partition for the filesystem, which it also boots from. I only have ssh access as root and ca... |
I like your approach; it's clean in that it doesn't require modification of the data on your main system.
And, yes, I think that if you want to run tune2fs then by a large margin, the easiest solution is to run that from a running Linux, so that there's no real way around having to run it when the main file system isn... | How to change the casefold ext4 filesystem option of the root partition, if I only have ssh access |
1,350,390,457,000 |
This syntax prints "linux" when variable equals "no":
[[ $LINUX_CONF = no ]] && echo "linux"
How would I use regular expressions (or similar) in order to make the comparison case insensitive?
|
Standard sh
No need to use that ksh-style [[...]] command, you can use the standard sh case construct here:
case $LINUX_CONF in
([Nn][Oo]) echo linux;;
(*) echo not linux;;
esac
Or naming each possible case individually:
case $LINUX_CONF in
(No | nO | NO | no) echo linux;;
(*) echo not ... | bash - case-insensitive matching of variable |
1,350,390,457,000 |
I'm trying to use a regular expression in the man page of Bash by using less.
I press / in less to enter a pattern, and I type z and press the Enter. I expected it to not match upper-case z (Z), but it does.
How do I make it not match Z? What kind of regular expressions are these that are not case sensitive?
|
It's explained in the man page for less.
The default action for REs is to ignore case if there are no uppercase characters present, but to act case-sensitively otherwise.
There are three modes available within less:
Case context dependent: a search or RE without uppercase characters is considered to be case-insensiti... | Using regular expressions in "less" |
1,350,390,457,000 |
I saw that kernel 5.2 got handling of ext4 case-insensitivity per directory by flipping a +F bit in inode.
This EXT4 case-insensitive file-name lookup feature works on a
per-directory basis when an empty directory is enabled by flipping the
+F inode attribute.
https://www.phoronix.com/scan.php?page=news_item&px=... |
First you need recent enough software:
Linux kernel >= 5.2 for the kernel-side support in EXT4
userland tools: e2fsprogs >= 1.45 (eg: on Debian 10 which ships only version 1.44 this requires buster-backports). Provides among others mke2fs (alias mkfs.ext4), tune2fs and chattr.
UPDATE:
e2fsprogs >= 1.45.7 needed to a... | How to enable new in kernel 5.2 case-insensitivity for ext4 on a given directory? |
1,350,390,457,000 |
Looking around I have found out the following about /etc/resolv.conf valid formatting:
Trailing whitespace is allowed
Leading whitespace is NOT allowed
DNS records are case insensitive, though you may have weird issues in applications that lowercase everything
However, I can't find anywhere whether the resolv.conf k... |
They are certainly case sensitive in the glibc resolver libraries. Note the use of strncmp (case sensitive compare) rather than strncasecmp (case insensitive compare) in the MATCH function within glibc res_init.c.
This code is responsible for reading + parsing the /etc/resolv.conf file.
#define MATCH(line, name) \
... | Are keywords in resolv.conf case sensitive? |
1,350,390,457,000 |
I use the Git Bash on Windows for numerous bash tasks exceeding the Git use. It works well over years, but I cannot turn of the case-insensitive behavior. Auto-complete is cumbersome this way.
I tried the flag
shopt -u nocasematch
in the .bashrc as described in solution #3 but it does not resolve the issue.
Neither s... |
You need to revert two settings, nocaseglob and nocasematch:
The documentation (man bash) writes,
nocaseglob If set,bash matches filenames in a case-insensitive fashion when performing pathname expansion […]
nocasematch If set, bash matches patterns in a case-insensitive fashion when performing matching while e... | How can I turn off git bash for Windows case-insensitive behavior? |
1,350,390,457,000 |
Recently i face inconvenient when using bash auto complete with ignore case.
Let's say i have this directories:
[xiaobai@xiaobai test]$ l
total 20K
3407873 drwx------. 60 xiaobai xiaobai 4.0K May 25 17:17 ../
3409017 drwxrwxr-x. 2 xiaobai xiaobai 4.0K May 25 17:35 hello/
3681826 drwxrwxr-x. 2 xiaobai xiaobai 4.0K Ma... |
There is a workaround for your problem.
Try:
bind 'set completion-ignore-case on'
bind 'TAB:menu-complete'
bind 'set menu-complete-display-prefix on'
bind 'set show-all-if-ambiguous on'
Type cd h,Tab. Line expands to cd hello.
Then type _, Tab. Line expands to cd Hello_StackOverflow
Press Tab,Tab. Line expands to cd ... | bash - ignore case but disallow autocomplete if ambiguous |
1,350,390,457,000 |
I have a file that contains information as so:
20 BaDDOg
31 baddog
42 badCAT
43 goodDoG
44 GOODcAT
and I want to delete all lines that contain the word dog. This is my desired output:
42 badCAT
44 GOODcAT
However, the case of dog is insensitive.
I thought I could use a sed command: sed -e "/dog... |
Try grep:
grep -iv dog inputfile
-i to ignore case and -v to invert the matches.
If you want to use sed you can do:
sed '/[dD][oO][gG]/d' inputfile
GNU sed extends pattern matching with the I modifier, which should make the match case insensitive but this does not work in all flavors of sed. For me, this works:
sed ... | delete line that contains a case insensitive match |
1,350,390,457,000 |
With NTFS you can enable or disable case sensitivity. Is there a way to do it with ext4 in Linux?
|
There are patches currently under development to implement case insensitivity for ext4.
https://lwn.net/Articles/762826/
https://marc.info/?l=linux-ext4&m=154430575726827&w=2
They were included in the Linux 5.2 kernel, and also require e2fsprogs-1.45 to work. See How to enable new in kernel 5.2 case-insensitivity for... | Is it possible to disable ext4 case sensitivity? |
1,350,390,457,000 |
Is it possible for bash to find commands in a case-insensitive way?
eg. these command lines will always run python:
python
Python
PYTHON
pyThoN
|
One way is to use alias shell builtin, for example:
alias Python='python'
alias PYTHON='python'
alias Python='python'
alias pyThoN='python'
For a better approach, the command_not_found_handle() function can be used as described in this post: regex in alias.
For instance, this will force all the commands to lowercase:... | bash case-insensitive commands matching |
1,350,390,457,000 |
I have a directory that contains the backup of many computers using NTFS file system.
/backup/REP1/database
/backup/REP2/database
I now want to scp from the backup file server to the database server, both are running Ubuntu 14.
Inside the backup directories are Visual FoxPro files that are not all the same case, but ... |
Here's how I would approach it:
Create a function that generates globs for filenames based on the requirement (any character could show up as upper- or lower-case).
Modify the loop to have scp use the glob as the remote filename, and the already lower-cased filename as the local filename.
This will create the same o... | How to copy with scp a file that case is unknown via bash script |
1,350,390,457,000 |
So I've been playing around with filesystem and wondered about listing the files in /etc that contains only upper-case letters in their names. I commanded
ls *[A-Z]*
But the console shows the files containing lower chars too.
I want to use only ls command. Is the console program locale dependent?
What is the underl... |
[A-Z] doesn't mean upper case. It means letters from A to Z, which may include lower-case letters. Usually you should use [[:upper:]] instead. (This works in Bash even without extglob.)
What characters [A-Z] matches depends on your locale.
You have clarified that you want to show all filenames that contain at least o... | Using wildcard in 'ls' command to find files containing uppercase letters only |
1,350,390,457,000 |
In a script:
aptitude search "?description($1)"
... can that be made case-sensitive?
|
aptitude uses the POSIX regcomp() / regexec() API from the system's C library to do regexp matching and calls regcomp() with the REG_ICASE | REG_EXTENDED flags, so you get mostly the same as grep -iE¹, and there's no builtin support for turning case-insensitivity off.
Now, if you're willing to spend a bit of effort, t... | Can we make an aptitude search case-sensitive? |
1,350,390,457,000 |
I have been asked by the data owner to copy a specific folder (and its large amount of subfolders and files) via FTPS to our cloud storage provider. I am using LFTP for that, and the upload worked well until I hit a snag.
There are several folders with multiple files that have the same filename except for case. For e... |
The bash script below loops through the files in the current directory, looking for duplicate filenames case insensitively. If a match is found, it looks to create a "Duplicates" folder that doesn't exist already, then moves the duplicate file into that directory.
The outer loop is there in order to re-compute the fil... | Move files that have the same case-insensitive filename |
1,350,390,457,000 |
When you do it it says file already exists.
example output:
rename 'y/A-Z/a-z/' *
Totemic-1.12.2-0.11.6.jar not renamed: totemic-1.12.2-0.11.6.jar already exists
TreeChoppin-1.12.2-1.0.0.jar not renamed: treechoppin-1.12.2-1.0.0.jar already exists
UniDict-1.12.2-2.9.3.jar not renamed: unidict-1.12.2-2.9.3.jar already... |
I'm assuming this has something to do with case-insensitive filenames, so if rename checks if the target file exists, it sees the original and stops to avoid destroying it.
The Perl rename on my system has this option which looks like it could work here:
-f, -force
Over write: allow existing files to be ov... | rename 'y/A-Z/a-z/' * doesn't work on windows subsystem for linux (wsl) |
1,350,390,457,000 |
I have "|" delimited text data, and want to transform a column values
$ cat infile
Mark|father
Jason|SOn
Jose|son
Steffy|daugHter
I want to search for (father|son|daughter) case insensitively and substitute any case of father to Father, any case of son to Son, any case of daughter to Daughter
So outfile should look l... |
I'd use a hash lookup instead of a regexp comparison and *sub() for efficiency and robustness (in case you decide to use a string that contains regexp metachars or backreferences or can be a substring of some other string):
$ cat tst.awk
BEGIN {
FS = "|"
split("Father|Son|Daughter",tmp)
for (i in tmp) {
... | awk case insensitive with gsub |
1,350,390,457,000 |
I have a file on RedHat with the data below:
$ cat hello.txt
mumdfw2as123v USER=wladmin MOUNTPOINT=/apps
MUMFW2as97v.mrshmc.com USER=wladmin MOUNTPOINT=/apps
MUMFW3AS65V USER=user MOUN... |
Here's a simple approach:
$ awk -F'[ ]' '{$1=tolower($1)}1' file
mumdfw2as123v USER=wladmin MOUNTPOINT=/apps
mumfw2as97v.mrshmc.com USER=wladmin MOUNTPOINT=/apps
mumfw3as65v USER=user ... | convert only the first column in a file to lower case |
1,350,390,457,000 |
I am working on restructuring the folder structure of few existing folders.
So if there are any folders missed i will have to add it.
First am checking if the directory exists or not with if command, if not present am creating one. As it is case sensitive, am ending up creating same folder again.
Example : A Folder ... |
Instead of
if [ -d abc ] ; then
echo 'Directory exists'
use
if /bin/ls -d [aA][bB][cC]/ &> /dev/null ; then
echo 'Directory exists'
| Case insensitive directory search? |
1,350,390,457,000 |
Why do :
$ echo -e 'Q\ns\nV' | sort
outputs
Q
s
V
without changing the order of my list (taking in account the lower/uppercase ?)
|
In most languages, s sorts before V regardless of the case.
Sorting depends on localisation settings (LANG and LC_* variables).
You could use: LC_ALL=C sort if you wanted to sort according to the byte value order, but that may not do what you want if you're in a multi-byte locale.
If you want to sort in the order of y... | `echo -e 'Q\ns\nV' | sort` doesn't sort |
1,350,390,457,000 |
Context: macOS Catalina (zsh)
This script is to process all JPEG files. This script does not process .JPG files, however it does process .jpg files.
top=/Users/user/Desktop/
for file in $top/**/*.jp*g(NDn.); do #selects filetypes: .jpg .jpeg
mogrify -auto-orient \
-gravity northWest \
-fo... |
Especially for your case where the glob is $top/**/*.jpg, I would not turn the caseglob option off (same as turning nocaseglob on¹) globally, as that affects all path components in glob patterns:
$ top=a zsh +o caseglob -c 'print -rC1 -- $top/*.jpg'
a/foo.jpg
a/foo.JPG
a/FOO.jpg
a/FOO.JPG
A/foo.jpg
A/foo.JPG
A/FOO.jp... | zsh case-insensitive globbing |
1,350,390,457,000 |
Cygwin is case-insensitive in the manner of Windows, e. g.:
$ touch ABC; rstr=$(openssl rand -base64 12); echo $rstr; echo $rstr > AbC; cat abc
dGRMOHqqoy0/nc96
dGRMOHqqoy0/nc96
$ ls | grep -i abc
ABC
The cases of characters in a file or directory name are stored but ignored when doing operations on it.
ABC, AbC and... |
In zsh, and with the extendedglob option on, you can do:
$ set -o extendedglob
$ printf '%s\n' (#i)path/to/file
Path/to/FILE
To get the path/to/file with the stored case.
In ksh93:
$ printf '%s\n' ~(i)path/to/file
Path/to/FILE
(beware that if there's no match, that will expand to ~(i)path/to/file, ksh93 has no equiv... | Cygwin: get a path's stored capitalization |
1,350,390,457,000 |
Linux can format an (external) disk as HFS+, e.g.:
apt-get install gparted hfsprogs, then
gparted /dev/sdd, rightclick on the partition to format, choose HFS+, click Apply, quit; mount -t hfsplus /dev/sdd2 /mnt/foo.
But then you can't make both /mnt/foo/xyzzy and /mnt/foo/XYZZY, because gparted used macOS's default op... |
mkfs.hfs -s /dev/sdd2
from man mkfs.hfs:
-s Creates a case-sensitive HFS Plus filesystem. By default a
case-insensitive filesystem is created. Case-sensitive HFS
Plus file systems require a Mac OS X version of 10.3 (Darwin
7.0) or later.
| Format disk as HFS+, but case sensitive? |
1,350,390,457,000 |
I have a folder on my Linux system that is cross-synchronized with other computers, some of them with Windows. The problem is that in that folder there are files that are "case duplicates", i.e. their file name is same except that one or more characters are uppercase vs. lowercase. For the Linux system this isn't a pr... |
If you want to avoid re-inventing the wheel, you could use the mv command's built in ability to do automatic numbered backups; if your shell supports the case conversion natively that could be as simple as
for f in *; do mv --backup=numbered -- "$f" "${f,,}"; done
The default backup number format is .~1~, for example... | Batch rename "case duplicates" |
1,508,006,762,000 |
I have the following code that I run on my Terminal.
LC_ALL=C && grep -F -f genename2.txt hg38.hgnc.bed > hg38.hgnc.goi.bed
This doesn't give me the common lines between the two files. What am I missing there?
|
Use comm -12 file1 file2 to get common lines in both files.
You may also needs your file to be sorted to comm to work as expected.
comm -12 <(sort file1) <(sort file2)
From man comm:
-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
Or using grep command you need to ad... | Common lines between two files [duplicate] |
1,508,006,762,000 |
I was trying to find the intersection of two plain data files, and found from a previous post that it can be done through
comm -12 <(sort test1.list) < (sort test2.list)
It seems to me that sort test1.list aims to sort test1.list in order. In order to understand how sort works, I tried sort against the following file... |
Per the comm manual, "Before `comm' can be used, the input files must be sorted using the collating sequence specified by the `LC_COLLATE' locale."
And the sort manual: "Unless otherwise specified, all comparisons use the character collating sequence specified by the `LC_COLLATE' locale.
Therefore, and a quick test co... | Issues of using sort and comm |
1,508,006,762,000 |
I’m writing something that deals with file matches, and I need an inversion operation. I have a list of files (e.g. from find . -type f -print0 | sort -z >lst), and a list of matches (e.g. from grep -z foo lst >matches – note that this is only an example; matches can be any arbitrary subset (including empty or full) o... |
If your comm supports non-text input (like GNU tools generally do), you can always swap NUL and nl (here with a shell supporting process substitution (have you got any plan for that in mksh btw?)):
comm -23 <(tr '\0\n' '\n\0' < file1) <(tr '\0\n' '\n\0' < file2) |
tr '\0\n' '\n\0'
That's a common technique.
| Invert matching lines, NUL-separated |
1,508,006,762,000 |
I have two files with tab-separated values that look like this:
file1:
A 1
B 3
C 1
D 4
file2:
E 1
B 3
C 2
A 9
I would like to find rows between files 1 and 2 where the string in column 1 is the same, then get the corresponding values. The desired output is a single file that looks like this:
... |
GNU coreutils includes the command join that does exactly what you want if line sorting in the result is irrelevant:
join <(sort file1) <(sort file2)
A 1 9
B 3 3
C 1 2
If you want the tabs back, do:
join <(sort file1) <(sort file2) | tr ' ' '\t'
A 1 9
B 3 3
C 1 2
Or use the t option to join.
(<() aka pro... | Find common elements in a given column from two files and output the column values from each file |
1,508,006,762,000 |
I have two files, (no blank lines/Spaces/Tabs)
/tmp/all
aa
bb
cc
hello
SearchText.json
xyz.txt
/tmp/required
SearchText.json
and the end output I want is : (all uncommon lines from /tmp/all)
aa
bb
cc
hello
xyz.txt
I have tried below commands :-
# comm -23 /tmp/required /tmp/all
SearchTex... |
As an alternative to comm, consider grep:
grep -vxFf /tmp/required /tmp/all
This asks for the lines in /tmp/all that do not (-v) exist in the file (-f) /tmp/required. To avoid interpreting any line in /tmp/all as a regular expression, I added the "fixed strings" -F flag. In addition, we want to force the entire line ... | bash remove common lines from two files |
1,508,006,762,000 |
From my understanding I want to use comm -23 file1 file2. file1 is the result of find and file2 is cut -c43- list. Is it possible I can write this as 1 line and not use any files (except the one I have named list)?
|
Process substitution is your friend here:
$ comm -23 <(find /dir -name 'something') <(cut -c43- list)
The format <(command) applies a temp file descriptor to the command and the whole <( ) is used as a file input to comm (or any other command).
See more about process substitution here . Also check man bash :
Process... | How can I use comm in this way? |
1,508,006,762,000 |
I am looking from something which gives me an output of comm -3 on two sorted outputs (line-by-line comparison, only additional/missing lines from either side) but which looks more like the output from diff -y, e.g. in that it uses the whole width.
file1:
bar/a
bar/feugiat
bar/libero
bar/mauris
bar/scelerisque
bar/urn... |
You could pipe to:
expand -t "$((${COLUMNS:-$(tput cols)} / 2))"
Or for the angle brackets:
awk -v cols="${COLUMNS:-$(tput cols)}" '
BEGIN {width = cols/2-1; space = sprintf("%*s", width, "")}
/^\t/ {print space ">", substr($0, 2); next}
{printf "%-*s<\n", width, $0}'
If your tput doesn't output the number of ... | Naive line-by-line comparison like "comm -3" but looking like "diff -y" |
1,508,006,762,000 |
Is the output of comm guaranteed sorted? In my simple examples they are and that makes sense to me (how I think comm works); however, I need to comm very large files and worried that comm might do some black magic for very large files.
Also, can someone point me to the source of comm? I've never been able to find t... |
Yes, if your input lines are ordered in the current collating sequence. From POSIX comm STDOUT documentation:
If the input files were ordered according to the collating sequence of
the current locale, the lines written shall be in the collating
sequence of the original lines.
If you guaranteed your input sorted,... | Is comm output guaranteed sorted? |
1,508,006,762,000 |
I have a script that's supposed to get the list of files of two directories, get differences and execute some code for certain files.
These are the commands to get the file lists:
list_in=$(find input/ -maxdepth 1 - type f | sed 's/input\///' | sort -u);
list_out=$(find output/ -maxdepth 1 - type f | sed 's/output\///... |
The kernel recognizes certain file formats that it can execute natively. This includes at least one binary format. Additionally, files that begin with #! (shebang) are considered scripts; for example, if a file is located at /path/to/script and begins with #!/bin/bash then the kernel executes /bin/bash /path/to/script... | comm fails on bash variable input |
1,508,006,762,000 |
I need to select specific data's from log files.
I need two scripts:
I need to select all IP addresses that only visited /page1
I need to select all IP addresses that visited /page1 but never visited /page2
I have my desired logs in a .tar file. I want them extracted into a folder, and then I will use the script to ... |
awk '/^\/page1?/ {print $1}' /path/to/access.log | sort -u > result.txt
If you want a count of each unique IP, change sort -u to sort | uniq -c
If you want to match only the request-path field of the log (rather than the entire line) against /page1:
awk '$7 ~ /^\/page1?/ {print $1}' /path/to/access.log | sort -u > re... | Find IP addresses visiting /page1 but not /page2 from nginx access logfile |
1,508,006,762,000 |
I'd like to write a simple script for finding the intersection of multiple files (the common lines among all files), so after reading some here (link) i tried to write a bash script, which unfortunately fails for me.
what am i doing wrong?
RES=$(comm -12 ${1} ${2})
for FILE in ${@:3}
do
RES=$(comm -12 $FILE ${... |
When you dereference RES in:
comm $FILE ${RES}
the content of RES replaces ${RES}. But comm expects a filename as argument, so for instance if $RES contains hello comm tries to open a file named hello.
Instead you could use a temporary file to store the common lines during the process:
tmp=$(mktemp --tmpdir)
tmp2=$... | How to find the intersection of multiple files (not necessarily two files)? |
1,508,006,762,000 |
I want to extract common number present in all file. I have 1000 file in folder. I Want to compare all file number and find out common number in 1000 file. I have used below code:
for ((i=2;i<=10000;i++))
do
comm -12 --nocheck-order a.txt "$i".txt > final.txt
mv final.txt file.txt
done
But it is only over writting ... |
Assuming each number can only appear once in a file:
$ awk '{c[$1]++} END{for (i in c) if (c[i] == (ARGC-1)) print i}' a.txt {1..2}.txt
3
6
7
| how to find common number from multiple file? |
1,508,006,762,000 |
I'm migrating to Linux, and I need to convert the following Windows cmd command:
fc file1.txt file2.txt | find /i "no se han encontrado diferencias" > nul && set equal=yes
I think fc can be replaced by diff or comm, find with grep, but I don't how to do the && part, maybe an if statement...
|
Taking a guess as to what those Windows commands do, I'd say the equivalent in a POSIX sh script would be:
equal=no
cmp -s file1 file2 && equal=yes
which would set the equal variable to yes if the two files can be read and have identical content (byte-to-byte).
As an alternative to cmp -s, on some systems including L... | Linux equivalent of windows cmd command |
1,508,006,762,000 |
when i want to find duplicate lines between two files i use this command
comm -12 <(sort file1.txt) <(sort file2.txt)
or
sort file1.txt file2.txt | awk 'dup[$0]++ == 1'
But, how do I find duplicate lines in multiple files within folders. example:
mainfolder
folder1
file1-1.txt
file1-2.txt
etc
folder2... |
You could do this (if no files have a tab caracter in their names):
grep -T -r . mainfolder | sort -k 2 | uniq -D -f 1
The recursive grep will output each line prefixed by the filename it is in. Then you sort based on all the fields but the first one. Finally uniq outputs just the duplicated lines, skipping the first... | How do I find duplicate lines in multiple files within folders |
1,508,006,762,000 |
I have a list of IDs (sorted) in two files and I ran the comm command to compare them, but it seems to miss out one lines common to both files. Why is that?
File1:
1
2
3
4
5
6
7
8
9
11
12
13
15
16
17
18
19
20
21
22
File2:
16
18
21
23
705
707
709
711
712
826
827
839
846
847
848
872
873
874
875
891
Comm output: $> com... |
comm should tell you that one of the files isn’t sorted:
comm: file 1 is not in sorted order
It expects the files to be sorted using the current locale’s collation order (as determined by LC_COLLATE); it won’t accept numerical order.
To compare the files, you can pre-sort them (lexicographically as you point out):
co... | Why does the output of comm fail to show common records? |
1,508,006,762,000 |
File 1:
happy
sad
calm
palm
File 2:
palm
dream
calm
I want to compare the two files and display only those line that are common in both the files, but I want to maintain the order of File 2. My output should be:
palm
calm
I know I can use comm after sorting the files but I want to maintain the order. Is there any w... |
Use grep:
$ grep -Ff f1 f2
palm
calm
man grep:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings (instead of regular
expressions), separated by newlines, any of which is to be
matched.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. If ... | Compare two files line by line without comm (I need to maintain order of file 1) |
1,508,006,762,000 |
I want to compare two UTF-8 encoded text file. Can Linux command diff and comm handle these encoding?
|
Why not?
2 text files in Russian
$ file -i test1.txt test2.txt
test1.txt: text/plain; charset=utf-8 ... | Can linux command comm handle UTF-8 encoded text files? |
1,508,006,762,000 |
I have two files:
one generated using find command in a folder to list files, sorting them numerically and writing to a file,
and the other generated by a python script, which is not sorted, so I explicitly sort it numerically.
The problem is that my sort output only has two columns and is as follows:
500016
500... |
You are almost certainly right that additional characters on each line are causing corresponding lines to fail to match exactly. Those additional characters might have the form of carriage-return characters from Windows-style line terminators, space or tab characters, or possibly other non-printing characters. For e... | comm command behaving strangely |
1,508,006,762,000 |
I'd like to print a list of lines where the first word in two files is identical, and the rest of the words are not. Some complicated mess with comm, grep and cut would be possible, but hopefully there's a simpler way.
Edit: I've managed to slap together some working code. Example tests:
$ cat file1
a 1 E
b 2 F
c 3 G
... |
Assuming that both file1 and file2 are sorted (otherwise join won't work):
diff -u file1 file2 |
grep -E "^[+-]($(echo $(join -o0 file1 file2) | tr ' ' '|'))"
Explanation:
The join command will output the join field that occurs in both files (i.e. the first word of the line which is the same in both files), one on ... | Diff similar lines |
1,508,006,762,000 |
Why
I have two folders that should contain the exact same files, however, when I look at the number of files, they are different. I would like to know which files/folders are present in one, not the other. My thinking is I will make a list of all the files and then use comm to find differences between the two folders.... |
You don't need any of that, just use diff -qr dir1 dir2. For example:
$ tree
.
├── dir1
│ ├── file1
│ ├── file3
│ ├── file4
│ ├── file6
│ ├── file7
│ ├── file8
│ └── subdir1
│ ├── dsaf
│ ├── sufile1
│ └── sufile3
└── dir2
├── file1
├── file2
├── file3
├── file4
├── f... | Recursively list path of files only |
1,508,006,762,000 |
Over in an answer to a different question, I wanted to use a structure much like this to find files that appear in list2 that do not appear in list1:
( cd dir1 && find . -type f -print0 ) | sort -z > list1
( cd dir2 && find . -type f -print0 ) | sort -z > list2
comm -13 list1 list2
However, I hit a brick wall because... |
GNU comm (as of GNU coreutils 8.25) now has a -z/--zero-terminated option for that.
For older versions of GNU comm, you should be able to swap NUL and NL:
comm -13 <(cd dir1 && find . -type f -print0 | tr '\n\0' '\0\n' | sort) \
<(cd dir2 && find . -type f -print0 | tr '\n\0' '\0\n' | sort) |
tr '\n\0' '\0\... | Using comm with NULL-terminated records |
1,508,006,762,000 |
I have 2 different files-
File 1
2
4
6
8
10
12
File 2
2
3
5
6
10
12
I want to compare 2 files and get the output data which is in File 1 but not in File 2-
Output
4
8
I am using below command but not getting desired output-
comm -23 file1 file2
|
For comm to work properly, both files have to be sorted lexicographically, not numerically. You may sort your files before calling comm using
sort -o file1 file1
sort -o file2 file2
Then:
$ comm -23 file1 file2
4
8
Or, you may sort the files at the same time as you call comm, if your shell supports process substit... | Comparing Data between 2 different files in Unix |
1,508,006,762,000 |
Good day everyone,
I know there are a lot of similar questions already answered, but I can't find a satisfying answer and it drives me nuts.
I have two files which both contain hostnames : one that holds all the ones opened to the Internet, the other logs all the scan results of ALL our hosts, opened to Internet or no... |
Not being able to presort the files isn’t a problem:
comm -13 <(sort fileA) <(sort fileB)
This gives
1199.com
1299.com
www2.1329.com
with your examples, assuming each host is on a separate line. -13 tells comm to drop column 1 (lines unique to the first file) and 3 (lines common to both files), leaving only lines un... | Print only what is exclusive to a file compared to another in Bash |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.