unix

Remove containers by image name

拈花ヽ惹草 提交于 2020-12-26 11:44:53
问题 I mistakenly created a bunch of containers which I now want to remove. I can list them with: docker container ls -aq -f "ancestor=portainer/portainer" How can I "pipe" these container IDs to docker container rm ? What doesn't work: docker ls -aq -f "ancestor=portainer/portainer" | docker container rm docker container rm $(docker ls -aq -f "ancestor=portainer/portainer") docker rm `docker ls -aq -f "ancestor=portainer/portainer"` 回答1: Try this: docker container ls -aq -f "ancestor=portainer

Remove containers by image name

不打扰是莪最后的温柔 提交于 2020-12-26 11:44:09
问题 I mistakenly created a bunch of containers which I now want to remove. I can list them with: docker container ls -aq -f "ancestor=portainer/portainer" How can I "pipe" these container IDs to docker container rm ? What doesn't work: docker ls -aq -f "ancestor=portainer/portainer" | docker container rm docker container rm $(docker ls -aq -f "ancestor=portainer/portainer") docker rm `docker ls -aq -f "ancestor=portainer/portainer"` 回答1: Try this: docker container ls -aq -f "ancestor=portainer

How to check if a file is executable in go?

久未见 提交于 2020-12-25 15:35:51
问题 How would I write a function to check whether a file is executable in Go? Given an os.FileInfo , I can get os.FileInfo.Mode() , but I stall out trying to parse the permission bits. Test case: #!/usr/bin/env bash function setup() { mkdir -p test/foo/bar touch test/foo/bar/{baz.txt,quux.sh} chmod +x test/foo/bar/quux.sh } function teardown() { rm -r ./test } setup import ( "os" "path/filepath" "fmt" ) func IsExectuable(mode os.FileMode) bool { // ??? } func main() { filepath.Walk("test", func

How to check if a file is executable in go?

我与影子孤独终老i 提交于 2020-12-25 15:32:22
问题 How would I write a function to check whether a file is executable in Go? Given an os.FileInfo , I can get os.FileInfo.Mode() , but I stall out trying to parse the permission bits. Test case: #!/usr/bin/env bash function setup() { mkdir -p test/foo/bar touch test/foo/bar/{baz.txt,quux.sh} chmod +x test/foo/bar/quux.sh } function teardown() { rm -r ./test } setup import ( "os" "path/filepath" "fmt" ) func IsExectuable(mode os.FileMode) bool { // ??? } func main() { filepath.Walk("test", func

How to check if a file is executable in go?

烈酒焚心 提交于 2020-12-25 15:28:13
问题 How would I write a function to check whether a file is executable in Go? Given an os.FileInfo , I can get os.FileInfo.Mode() , but I stall out trying to parse the permission bits. Test case: #!/usr/bin/env bash function setup() { mkdir -p test/foo/bar touch test/foo/bar/{baz.txt,quux.sh} chmod +x test/foo/bar/quux.sh } function teardown() { rm -r ./test } setup import ( "os" "path/filepath" "fmt" ) func IsExectuable(mode os.FileMode) bool { // ??? } func main() { filepath.Walk("test", func

How to check if a file is executable in go?

天大地大妈咪最大 提交于 2020-12-25 15:25:21
问题 How would I write a function to check whether a file is executable in Go? Given an os.FileInfo , I can get os.FileInfo.Mode() , but I stall out trying to parse the permission bits. Test case: #!/usr/bin/env bash function setup() { mkdir -p test/foo/bar touch test/foo/bar/{baz.txt,quux.sh} chmod +x test/foo/bar/quux.sh } function teardown() { rm -r ./test } setup import ( "os" "path/filepath" "fmt" ) func IsExectuable(mode os.FileMode) bool { // ??? } func main() { filepath.Walk("test", func

How to check if a file is executable in go?

断了今生、忘了曾经 提交于 2020-12-25 15:24:47
问题 How would I write a function to check whether a file is executable in Go? Given an os.FileInfo , I can get os.FileInfo.Mode() , but I stall out trying to parse the permission bits. Test case: #!/usr/bin/env bash function setup() { mkdir -p test/foo/bar touch test/foo/bar/{baz.txt,quux.sh} chmod +x test/foo/bar/quux.sh } function teardown() { rm -r ./test } setup import ( "os" "path/filepath" "fmt" ) func IsExectuable(mode os.FileMode) bool { // ??? } func main() { filepath.Walk("test", func

How to escape the ampersand character while using sed

♀尐吖头ヾ 提交于 2020-12-24 08:47:06
问题 I want to replace all single quotes in a string with two single quotes using sed. But when the string contains the & character, the sed command is not replacing single quotes that come after that. How can I escape the & character so that the single quotes after it are still replaced? 回答1: You don't need to escape anything in the input : $ echo "123 ' foo & b'ar" | sed "s/'/''/g" 123 '' foo & b''ar However, in the 'replacement' part of the s command & has a special meaning: it means 'match'.

UNIX C send() errno 14

早过忘川 提交于 2020-12-15 06:51:35
问题 I have this code: void caller() { char buffer[20][20]; int sd; ... send(sd, buffer[7], 5, 0); } Now I have this code: void funct(int sd, char **buffer) { send(sd, buffer[7], 5, 0); } void caller() { char buffer[20][20]; int sd; ... funct(sd, buffer); } To simplify suppose that instead of ... I have an initialization of socket UDP and connection with the server to use send instead of sendto. I don't understand why the second code generates on send an error and errno is set with value 14, but

How to implement grep in bash scripting? [duplicate]

我的梦境 提交于 2020-12-13 18:14:13
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find