this post was submitted on 28 Nov 2023
25 points (100.0% liked)

Linux

48062 readers
707 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Again, please tell me if there is a better way to do this.

While testing docker, frequently I need to start/stop/rm containers. I got real sick of having to ls them and copy paste the container ID.

Using this alias, I just have to remember a single part of the name of the container, and I will get the container IDs that can then be included as part of another command:

$ alias dcl='_dcl(){ docker container ls -aq -f name="$1";}; _dcl'

$ dcl snikket
b3fcbc808cc9
1947885fbb24
054d67d2e8b9
d8fe9df5f61f

So now that I'm getting a list of IDs, I can easily, for example, pause all of them:

$ docker container pause $( dcl snikket )
Error response from daemon: container  is not running
Error response from daemon: container  is not running
Error response from daemon: container  is not running
Error response from daemon: container  is not running

The containers weren't actually running, but this shows the alias working.

dcl obviously stands for 'docker container ls'

you are viewing a single comment's thread
view the rest of the comments
[–] hanke@feddit.nu 5 points 11 months ago (2 children)

I often just do

docker ps | awk "{print $1}" | xargs docker stop

Add some filtering in there and you're golden

[–] crmsnbleyd@sopuli.xyz 2 points 11 months ago

This is what I do as well

[–] MangoPenguin@lemmy.blahaj.zone 2 points 11 months ago (2 children)

How tf do you remember that lol, I'm always amazed by CLI focused people being able to remember so much!

[–] hanke@feddit.nu 5 points 11 months ago

I think it has to do with creativity!

The CLI tools are just small simple tools. The power comes from having the understanding of how each tool works and how they can be combined.

I don't remember this string of commands, I know docker, awk and xargs. When I need this, that is the solution I always end up with.

[–] luthis@lemmy.nz 2 points 11 months ago

Dude, I use the CLI all day, every day and I can't freakin remember half the commands I need.

If it's something I use often, I'll make an alias even if it's just so I can run 'alias' in the terminal to get a list of things I use often.