New answers tagged

1

As @SatoKatsura pointed out in their comment, the (hacky) use of less is outputting to stderr, while grep reads from stdout. Though it is a poor solution to the actual task of finding dead symlinks, it can work by redirecting stderr to stdout: less ~/.nvm/versions/node/v5.5.0/lib/node_modules/* 2>&1 | grep "Not a file"


2

The wildcard has nothing to do with grep, all that grep sees is what is piped to it. The wildcard is expanded by the shell and the list of files it expands to is passed to less. So the issue has nothing at all to do with grep. That said, if you're looking for broken links, you can do: for f in /Users/raine/.nvm/versions/node/v5.5.0/lib/node_modules/*; do ...


0

The message from ldapsearch is being printed to the stderr stream, which is not being caught before the | while. If you had been trying to redirect it with just a >, that would explain why it wasn't working inside the loop. If you want to capture ldapsearch's error output, change your script to: #!/bin/bash for i in $(seq 20000); do ldapsearch -x -...


1

"But according to this logic, neither ps not less should appear in the output of ps." Yes, so your logic is wrong, because they both appear. When you run a command in a Un*x shell, very few (if any) actually run in the shell. A separate process is forked to run that command. When you pipe two commands together, both commands are launched in separate ...


-1

Use ps -ef | grep [l]ess to avoid less. [l]ess match less as regexp but not as fixed string.


11

The shell starts both, to establish the ends of the pipe, so ps sees itself as well as the process at the other end of the pipe.


3

Your command $ find . -name 'segment*' | xargs -n1 -P4 sh someFunction.sh has the effect that at most four copies of the someFunction.sh shell script will be started (-P 4) in parallel (new ones will be spawed as soon as the old ones are done), each one getting one filename as its argument (-n 1). This means that each invocation of your script will look ...


2

You could use something like this assuming someFunction.sh is in your working directory. find . -name 'segment*' -print0| xargs -0 -n1 -P4 ./someFunction.sh The -print0 and -0 allow for files with spaces in the name (A common problem). In my someFunction.sh I have #!/bin/bash echo "Arg: " $1 cat $1 Which simply echo's out the file name then ...


3

Your second command works, the issue is you are using bash or whatever shell that put all pipelines components in a subshell. myresult2 is properly set but the variable is immediately out of scope unless you stay in the same subshell like here: curl -L 'https://archive.org/wayback/available?url=stackoverflow.com' \ 2>/dev/null | { myresult2=$(...


4

You can use eval: $ set -a $ eval "$(command_that_generate_output)" $ set +a $ sh -c 'printf "%s\n" "$DATABASE_URL"' someurl


1

You can't pipe output from an interactive SQLite session because it's not a shell. | doesn't do in SQL what it does on a command line. What you probably need to do is something akin to sqlite3 /path/to/mydata.sqlite "select * from todos" | grep vim, which will execute the SQL, and grep the output as you appear to be trying to do.


2

tr is a command that does a character-by-character translation. e.g the following command will change the character e to an E $ echo hello | tr 'e' 'E' hEllo When you use 2016-05-25 you're telling the tr command to switch the characters 2 and 0 and 1 and the range 6-0... which is where it gets confused. The command you really want to use is sed: $ sed '...


0

RSYNC behavior over SFTP Without even compressing anything, you can replicate the directory structure to the other side using LFTP (name is misleading) and the mirror subsystem of LFTP. LFTP supports SFTP and the mirror subsystem supports nearly all the capabilities of rsync. It can also split up the transfer into as many connections as you want, to make ...


2

As @Patrick said, this problem is usually due to netcat exiting before the response has been given. You remedy that by adding -q 2 to the command line, i.e., tell netcat to hang around 2 seconds after detecting EOF on standard input. Obviously you can make it wait some other number of seconds as well.


19

That command opened the connection on file descriptor 3. So to close the connection, you need to close file descriptor 3. To do so: exec 3<&-


4

This is impossible in general. Once an application has emitted some output, the only place where this output is stored is in the memory of the terminal. To give an extreme example, if this is the 1970s the terminal is a hardcopy printer, the output isn't getting back into the computer without somebody typing it in. If the output is still in the scrolling ...


2

Only if the terminal application was storing the raw output to a file somewhere, as e.g. iTerm does with logging enabled, or some other logging application (autoexpect(1) or equivalent) was saving the output will that raw output be available. Usually this has to be setup in advance, and requires management, e.g. if someone leaves yes running for a while then ...


1

It is not exactly "pipe", but you can basically tell scp to copy specific FD (which can be pipe) from your host to the other. Simple bash command like this: (scp does not work as it needs a size in advance): scp <(tar cz files to compress) host:/path/to/new.file but it can work with pure ssh: tar cz files to compress | ssh host "cat > /path/to/new....


1

grep buffers output if it does not write to a terminal. You can use grep --line-buffered to output each line immediately. Consider: run slow output command and grep to terminal: $ for i in {1..3}; do > echo printing >&2 > echo to grep > sleep 1 > done | grep to printing to grep printing to grep printing to grep run slow output ...


2

dirsplit -H will give you some more info on the command, including an example of using it with find. find . -name "*.jpg" -printf "%s %p" | dirsplit -T- --size 100MB --expmode 1 -L -T- reads filelist from stdin in the form "filename filesize" -L creates hard links (it seems there is no copy option)



Top 50 recent answers are included