159
submitted 2 days ago by marighost@piefed.social to c/linux@lemmy.ml

I've been setting up a new Proxmox server and messing around with VMs, and wanted to know what kind of useful commands I'm missing out on. Bonus points for a little explainer.

Journalctl | grep -C 10 'foo' was useful for me when I needed to troubleshoot some fstab mount fuckery on boot. It pipes Journalctl (boot logs) into grep to find 'foo', and prints 10 lines before and after each instance of 'foo'.

you are viewing a single comment's thread
view the rest of the comments
[-] harsh3466@lemmy.ml 9 points 2 days ago
find /path/to/starting/dir -type f -regextype egrep -regex 'some[[:space:]]*regex[[:space:]]*(goes|here)' -exec mv {} /path/to/new/directory/ \;

I routinely have to find a bunch of files that match a particular pattern and then do something with those files, and as a result, find with -exec is one of my top commands.

If you're someone who doesn't know wtf that above command does, here's a breakdown piece by piece:

  • find - cli tool to find files based on lots of different parameters
  • /path/to/starting/dir - the directory at which find will start looking for files recursively moving down the file tree
  • -type f - specifies I only want find to find files.
  • -regextype egrep - In this example I'm using regex to pattern match filenames, and this tells find what flavor of regex to use
  • -regex 'regex.here' - The regex to be used to pattern match against the filenames
  • -exec - exec is a way to redirect output in bash and use that output as a parameter in the subsequent command.
  • mv {} /path/to/new/directory/ - mv is just an example, you can use almost any command here. The important bit is {}, which is the placeholder for the parameter coming from find, in this case, a full file path. So this would read when expanded, mv /full/path/of/file/that/matches/the/regex.file /path/to/new/directory/
  • \; - This terminates the command. The semi-colon is the actual termination, but it must be escaped so that the current shell doesn't see it and try to use it as a command separator.
this post was submitted on 16 Dec 2025
159 points (98.2% liked)

Linux

57274 readers
239 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 6 years ago
MODERATORS