151

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'.

(page 2) 50 comments
sorted by: hot top controversial new old
[-] RavenofDespair@lemmy.ml 5 points 1 day ago

Not a command but the tab key for auto complete. This made it much easier for me.

[-] HiddenLayer555@lemmy.ml 9 points 1 day ago* (last edited 1 day ago)

parallel, easy multithreading right in the command line. This is what I wish was included in every programming language's standard library, a dead simple parallelization function that takes a collection, an operation to be performed on the members of that collection, and optionally the max number of threads (should be the number of hardware threads available on the system by default), and just does it without needing to manually set up threads and handlers.

inotifywait, for seeing what files are being accessed/modified.

tail -F, for a live feed of a log file.

script, for recording a terminal session complete with control and formatting characters and your inputs. You can then cat the generated file to get the exact output back in your terminal.

screen, starts a terminal session that keeps running after you close the window/SSH and can be re-accessed with screen -x.

Finally, a more complex command I often find myself repeatedly hitting the up arrow to get:

find . -type f -name '*' -print0 | parallel --null 'echo {}'

Recursively lists every file in the current directory and uses parallel to perform some operation on them. The {} in the parallel string will be replaced with the path to a given file. The '*' part can be replaced with a more specific filter for the file name, like '*.txt'.

[-] InFerNo@lemmy.ml 5 points 1 day ago

I can recommend tmux also as an alternative to screen

[-] ranzispa@mander.xyz 4 points 1 day ago

should be the number of hardware threads available on the system by default

No, not at all. That is a terrible default. I do work a lot on number churning and sometimes I have to test stuff on my own machine. Generally I tend to use a safe number such as 10, or if I need to do something very heavy I'll go to 1 less than the actual number of cores on the machine. I've been burned too many times by starting a calculation and then my machine stalls as that code is eating all CPU and all you can do is switch it off.

[-] qjkxbmwvz@startrek.website 8 points 1 day ago

nc is useful. For example: if you have a disk image downloaded on computer A but want to write it to an SD card on computer B, you can run something like

user@B: nc -l 1234 | pv > /dev/$sdcard

And

user@A: nc B.local 1234 < /path/to/image.img

(I may have syntax messed up--also don't transfer sensitive information this way!)

Similarly, no need to store a compressed file if you're going to uncompress it as soon as you download it---just pipe wget or curl to tar or xz or whatever.

I once burnt a CD of a Linux ISO by wgeting directly to cdrecord. It was actually kinda useful because it was on a laptop that was running out of HD space. Luckily the University Internet was fast and the CD was successfully burnt :)

[-] Valmond@lemmy.dbzer0.com 1 points 1 day ago

I'll go with a simple one here:

CTRL+SHIFT C/V for copy paste.

Or if it has to be terminal;

kill

😊

[-] kittenroar@beehaw.org 7 points 1 day ago

systemd-run lets you run a command under some limitations, ie

systemd-run --scope -p MemoryLimit=1000M -p CPUQuota=20% ./heavyduty.sh
load more comments (1 replies)
[-] eskuero@lemmy.fromshado.ws 9 points 1 day ago

echo 'dXIgbW9tCmhhaGEgZ290dGVtCg==' | base64 -d

load more comments (3 replies)
[-] Twakyr@feddit.org 1 points 1 day ago

I like emerge --moo, just to See how larry is doing. Only gentoo tho :(

[-] sunoc@sh.itjust.works 12 points 1 day ago

I only recently started using C-r to search in the command history. Game changer!

[-] witness_me@lemmy.ml 9 points 1 day ago* (last edited 1 day ago)

Want an even bigger game changer? fzf combined with control-r.

Enjoy.

load more comments (7 replies)
[-] JoMiran@lemmy.ml 15 points 1 day ago* (last edited 1 day ago)

It isn't a command but an application. I cannot do my work without it.

screen
[-] crispycone@lemmy.zip 13 points 1 day ago

I prefer tmux, but yes. Both do a great job in helping me manage my terminal sessions.

[-] JoMiran@lemmy.ml 4 points 1 day ago
[-] kittenroar@beehaw.org 3 points 1 day ago* (last edited 1 day ago)

Scrolling in screen is superior to tmux imo

[-] wheezy@lemmy.ml 2 points 1 day ago

Scrolling is tmux is what I hate about it. I would prefer to use tmux since I'm use to it. But if someone can explain to me why I can't just use my scroll wheel on my mouse.

load more comments (1 replies)
load more comments (3 replies)
[-] eli@lemmy.world 1 points 1 day ago* (last edited 1 day ago)

There are a lot of great commands in here, so here are my favorites that I haven't seen yet:

  • crontab -e
  • && and || operators
  • ">" and >> chevrons and input/output redirection
  • for loops, while/if/then/else
  • Basic scripts
  • Stdin vs stdout vs /dev/null

Need to push a file out to a couple dozen workstations and then install it?

for i in $(cat /tmp/wks.txt); do echo $i; rsync -azvP /tmp/file $i:/opt/dir/; ssh -qo Connect timeout=5 $i "touch /dev/pee/pee"; done

Or script it using if else statements where you pull info from remote machines to see if an update is needed and then push the update if it's out of date. And if it's in a script file then you don't have search through days of old history commands to find that one function.

Or just throw that script into crontab and automate it entirely.

[-] fubarx@lemmy.world 4 points 1 day ago
[-] mat@jlai.lu 9 points 1 day ago

I'd say that journalctl is not only boot, but every service that runs on the computer has its logs collected through it, so you can use it as journalctl --grep="your regex". You can also add -k to check kernel logs, -b -n to check nth precedent boot or -b n to check the absolute nth boot. There is a lot that you can check with it and it is quite nice :)

Otherwise, I like eza as an ls replacement, or batcat as a human friendly cat

[-] smiletolerantly@awful.systems 11 points 1 day ago

Don't forget the almighty:

journalctl -fu <servicename>

And yes, I am always reading that as "fuck you, service".

[-] wheezy@lemmy.ml 2 points 1 day ago

Well now I'm aliasing this to jofu and remembering it as "jerk off fuck you"

load more comments (1 replies)
[-] utopiah@lemmy.ml 1 points 1 day ago
fabien@debian2080ti:~$ history  | sed 's/ ..... //' | sort | uniq -c | sort -n | tail
# with parameters
     13 cd Prototypes/
     14 adb disconnect; cd ~/Downloads/Shows/ ; adb connect videoprojector ;
     14 cd ..
     21 s # alias s='ssh shell -t "screen -raAD"'
     36 node .
     36 ./todo 
     42 vi index.js 
     42 vi todo # which I use as metadata or starting script in ~/Prototypes
     44 ls
    105 lr # alias lr="ls -lrth"
fabien@debian2080ti:~$ history  | sed 's/ ..... //' | sed 's/ .*//' | sort | uniq -c | sort -n | tail
# without parameters
     35 rm
     36 node
     36 ./todo
     39 git
     39 mv
     70 ls
     71 adb
     96 cd
    110 lr
    118 vi
[-] demonsword@lemmy.world 5 points 1 day ago

Something that really improved my life was learn to properly use find, grep, xargs and sed. Besides that, there are these two little 'hacks' that are really handy at times...

1- find out which process is using some local port (i.e. the modern netstat replacement):

$ ss -ltnp 'sport = :<port-number>'

2- find out which process is consuming your bandwidth:

$ sudo nethogs

[-] Ephera@lemmy.ml 3 points 1 day ago

I always just do ss -ltnp | grep <port-number>, which filters well enough for my purposes and is a bit easier to remember...

load more comments (1 replies)
[-] Sxan@piefed.zip 7 points 1 day ago

ripgrep has mostly replaced grep for me, and I am extremely conservative about replacing core POSIX utilities - muscle memory is critical. I also tend to use fd, mainly because of its forking -x, but its advantages over find are less stark þan rg's improvements over grep.

nnn is really handy; I use it for everything but the most trivial renames, copies, and moves - anyþing involving more þan one file. It's especially handy when moving files between servers because of þe built-in remote mounting.

load more comments (8 replies)
[-] TechnoCat@piefed.social 5 points 1 day ago

https://blog.sanctum.geek.nz/series/unix-as-ide/

# list all recursive files sorted by size  
$ fd -tf "" -x du -h | sort -h  
8.0K      ./asdfrc  
 20K      ./nvim/lua/lush_theme/bleak.lua  
 32K      ./alacritty.yml  
# find files by extension  
$ fd -e lua  
nvim/colors/bleak.lua  
nvim/init.lua  
nvim/lua/config/autocmds.lua  
# list found files in tree view  
$ fd -e lua | tree --fromfile  
.  
└── nvim  
    ├── colors  
    │   └── bleak.lua  
    ├── init.lua  
# Run "npm test" when a file changes in the src or test directories  
$ fd src test | entr -- npm test  
# find out how often you use each command  
history | cut -d " " -f 1 | sort | uniq -c | sort -n | tail -n 10  
  80 rm  
  81 lsd  
 107 asdf  
 136 npx  
 161 find  
 176 fd  
 182 cd  
 185 rg  
 247 brew  
 250 nb  
 465 npm  
 867 git  
[-] crispycone@lemmy.zip 6 points 1 day ago

Another one of my favorite is ctrl+r to quickly search for a previous command.

Then type in a word from the command you are looking for and then hit tab to find the right command if there is more than one with that word.

[-] emb@lemmy.world 5 points 1 day ago* (last edited 1 day ago)

I get a lot of mileage out of the line editing commands. I think they are Emacs based and optional... but like Ctrl k, Ctrl u, Ctrl a.

[-] __hetz@sh.itjust.works 2 points 1 day ago

I usually set vi mode to have vi(m)-like line editing but I've always liked Ctrl+u over Esc d d. Thankfully it still works even with vi mode enabled. Seems to also be implemented as a shortcut for a lot of login managers and in DEs for settings menus, dialog boxes and such.

load more comments (1 replies)
[-] Oinks@lemmy.blahaj.zone 4 points 1 day ago* (last edited 1 day ago)

I'm not much of a one-liner collector but I like this one:

vim +copen -q <(grep -r -n <search> .) 

which searches for some string and opens all instances in vim's quickfix list (and opens the quickfix window too). Navigate the list with :cn and :cn. Complex-ish edits are the obvious use case, but I use this for browsing logs too.

Neovim improves on this with nvim -q - and [q/]q, and plenty of fuzzy finder plugins can do a better version using ripgrep, but this basic one works on any system that has gnu grep and vim.

Edit:

This isn't exactly a command, but I can't imagine not knowing about this anymore:

$ man grep
/  -n       # double space before the dash!

brings you directly to the documentation of the -n option. Not the useless synopsis or any other paragraphs that mention -n in passing, but the actual doc for this option (OK, very occasionally it fails due to word wrap, but assuming the option is documented then it works 99% of the time).

[-] GaryGhost@lemmy.world 1 points 1 day ago

ps -ef | grep <process_name

Kill -9 proces id

I googled that -15 is better, I forgot what -9 even did, been using it for years.

[-] utopiah@lemmy.ml 2 points 1 day ago

Maybe I interest you in pgrep? pkill? killall?

load more comments (1 replies)
load more comments (1 replies)
[-] roran@sh.itjust.works 2 points 1 day ago
cd `pwd`

for when you want to stay in a dìr that gets deleted and recreated.

cat /proc/foo/exe > program
cat /proc/foo/fd/bar > file

to undelete still-running programs and files still opened in running programs

[-] marcie@lemmy.ml 2 points 1 day ago

rpm-ostree status

rpm-ostree reset

rpm-ostree rebase

idk i love rpm-ostree man

[-] hades@feddit.uk 4 points 1 day ago

fzf is great for quickly finding files e.g. in large code repositories.

tcpdump can help diagnose network issues.

[-] thagoat@piefed.thagoat.lol 4 points 1 day ago

Bash/ZSH aliases are invaluable for commands that you run often. I use micro as my terminal editor so I have alias m for micro and sm for sudo micro. Just 2 of maybe a dozen aliases I use. Docker has quite a large list of aliases with ZSH. Super super useful. 

[-] Auster@thebrainbin.org 3 points 1 day ago

(Fixed the bolding issue)

From a file I keep since I started using Linux near 5 years ago:

Display the RAM usage:
watch -n 5 free -m
Useful if you open way too much stuff and/or you're running on budget processing power, and don't want your computer freezing from 3 hours.
Also useful if you use KDE's Konsole integrated into the Dolphin file manager and you must for some reason not close the Dolphin window. You'd just need to open Dolphin's integrated Konsole (F4), run the command and without closing it, press F4 again to hide the Konsole.

Terminal-based file browser that sorts by total size:
ncdu
why is the cache folder 50 GB big?

Mass-check MD5 hashes for all files in the path, including subfolders:
find -type f \( -not -name "md5sum.txt" \) -exec md5sum '{}' \; > md5sum.txt
Change md5sum (and optionally the output file's name) for your favorite/needed hash calculator command.

For mounting ISOs and similar formats:
sudo mount -o loop path/to/iso/file/YOUR_ISO_FILE.ISO /mnt/iso

And unmounting the file:
sudo umount /mnt/iso
Beware there's no N in the umount command

For creating an ISO from a mounted disc:
dd if=/dev/cdrom of=image_name.iso

And for a folder and its files and subfolders:
mkisofs -o /path/to/output/disc.iso /path/from/input/folder

Compress and split files:
7z -v100m a output_base_file.7z input_file_or_folder

Changes the capslock key into shiftlock on Linux Mint (not tested in other distros):
setxkbmap -option caps:shiftlock
Was useful when the shift key from a previous computer broke and I didn't have a spare keyboard.

If you want to run Japanese programs on Wine, you can use:
LC_ALL=ja_JP wine /path/to/the/executable.exe
There are other options but this is one that worked the better for me so I kinda forgor to take note of them.

List all files in a given path and its subfolders:
find path_to_check -type f
Tip: add > output.txt or >> output.txt if you'd rather have the list in a TXT file.

Running a program in Wine in a virtual desktop:
wine explorer /desktop=session_name,screen_size /path/to/the/executable.exe

E.g.:
wine explorer /desktop=MyDesktop,1920x1080 Game.exe

Useful if you don't want to use the whole screen, there are integration issues between Linux, Wine and the program, or the program itself has issues when alt-tabbing or similar (looking at you, 2000's Windows games)

Download package installers from with all their dependencies:
apt download package_name
Asks for sudo password even when not running as sudo. Downloaded files come with normal user permissions thankfully. Also comes with an installation script but if you want to run it offline, iirc you need to change apt install in the script for dpkg -i.

If you use a program you'd rather not connect to the internet but without killing the whole system's connection, try:
firejail --net=none the_command_you_want_to_run

Or if you want to run an appimage:
firejail --net=none --appimage the_command_you_want_to_run

If you want to make aliases (similar to commands from Windows' PATH) and your system uses bash, edit the file $HOME/.bashrc (e.g. with Nano) and make the system use the updated file by either logging out and in, or running . ~/.bashrc

Python/Pip have some nifty tools, like Cutlet (outputs Japanese text as Romaji), gogrepoc (for downloading stuff from your account using GOG's API), itch-dl (same as gogrepoc but for Itch.io), etc. If you lack the coding skills and doesn't mind using LLMs, you could even ask one to make some simpler Python scripts (key word though: simpler).

If you want to run a video whose codec isn't supported by your system (e.g. Raspberrian which only supports H.264, up to 1080p):
ffmpeg -i input_video.mkv -map 0 -c:v libx264 -preset medium -crf 23 -vf scale=1920:1080 -c:a copy -c:s copy output_video.mkv

load more comments
view more: ‹ prev next ›
this post was submitted on 16 Dec 2025
151 points (98.1% liked)

Linux

57274 readers
692 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