Elektrine lite

← Feed

@marighost@piefed.social

What are some of your most useful or favorite terminal commands?

2025-12-16 13:10 UTC

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

Replies (40)

  • @InFerNo@lemmy.ml 2025-12-16 22:28

    I use $_ a lot, it allows you to use the last parameter of the previous command in your current command mkdir something && cd $_ nano file chmod +x $_ As a simple example. If you want to create nested folders, you can do it in one go by adding -p to mkdir mkdir -p bunch/of/nested/folders Good explanation here: koenwoortman.com/…/q Sometimes starting a service takes a while and you’re sitting there waiting for the terminal to be available again. Just add --no-block to systemctl and it will do it on the background without keeping the terminal occupied. systemctl start --no-block myservice

    Open ##1336604

  • @JoMiran@lemmy.ml 2025-12-16 13:28

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

    Open ##1384890

  • @marighost I dont use Prox, but for various random linux commands.. ive got a wealth. :D in the journalctl vein. `journalctl -xeu ` ex: `journalctl -xeu httpd` Gives you the specific journal output for the given service. In this example. httpd. Also, `journalctl` is more than boot logs, its all of your logs from anything controlled by systemd. Mounts, services, timers, even sockets. For example. On my system, i have /var/home as a mount. `systemctl` and `journalctl` can give me info on it with: `systemctl status var-home.mount` journalctl -xeu var-home.mount You can see all of the mounts with. `systemctl list-units --type=mount` Or, see all of your services with `systemctl list-units --type=service` Or all of your timers with `systemctl list-timers` We do a weekly show on getting into linux terminals, commands, tricks, and share our experience.. It's called Into the Terminal. on the Red Hat Enterprise Linux youtube channel. I'll send you a link if you're interested.

    Open ##1384891

  • @mat@jlai.lu 2025-12-16 13:38

    with zsh, you can use it, and then press space to have the !! replaced by the previous command to be able to edit it :)

    Open ##1384898

  • Similar-ish for quickly editing last command: fc

    Open ##1384899

  • @furrowsofar@beehaw.org 2025-12-16 13:40

    Various uses of “find” in particular. “xargs” sometimes too. The capabilities of “bash” in general including scripting and the whole redirection, piping, and multiprocessing capabilities in particular.

    Open ##1384900

  • @fhein@lemmy.world 2025-12-16 13:50

    These aliases for zsh I use all the time. It’s part of the prezto configuration framework. setopt AUTO_CD # Auto changes to a directory without typing cd. setopt AUTO_PUSHD # Push the old directory onto the stack on cd. setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack. setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. setopt PUSHD_TO_HOME # Push to home directory when no argument is given. alias d='dirs -v' for index ({1..9}) alias "$index"="cd +${index}"; unset index Type d and enter to list all the directories you’ve recently been in, then type the number at the start of the line followed by enter to immediately cd there. Not sure if latest bash can do it the same thing, but some years ago I wrote a script to implement it there too. IIRC it might’ve been the automatic removal of duplicates in dir history that was missing.

    Open ##1384901

  • @hades@feddit.uk 2025-12-16 13:56

    Number one will forever and ever be strace

    Open ##1384902

  • @Bluegrass_Addict@lemmy.ca 2025-12-16 14:03

    woh

    Open ##1384903

  • @mat@jlai.lu 2025-12-16 14:03

    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

    Open ##1384904

  • @hades@feddit.uk 2025-12-16 14:17

    Also if you make a typo you can quickly fix it with ^, e.g. ls /var/logs/apache ^logs^log

    Open ##1384905

  • @hades@feddit.uk 2025-12-16 14:20

    tmux is based

    Open ##1384906

  • @hades@feddit.uk 2025-12-16 14:20

    fzf is great for quickly finding files e.g. in large code repositories. tcpdump can help diagnose network issues.

    Open ##1384907

  • @Ftumch@lemmy.dbzer0.com 2025-12-16 14:40

    Ctrl-z to suspend the running program. bg to make it continue running in the background. jobs to get an overview of background programs. fg to bring a program to the foreground.

    Open ##1384908

  • @JoMiran@lemmy.ml 2025-12-16 14:41

    What can I say. I’m old.

    Open ##1384909

  • @Sxan@piefed.zip 2025-12-16 14:55

    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 than rg’s improvements over grep. nnn is really handy; I use it for everything but the most trivial renames, copies, and moves - anything involving more than one file. It’s especially handy when moving files between servers because of the built-in remote mounting.

    Open ##1384912

  • @Bluegrass_Addict@lemmy.ca 2025-12-16 15:03

    lol I just wanted people to question what was said.

    Open ##1384913

  • @sunoc@sh.itjust.works 2025-12-16 15:21

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

    Open ##1384915

  • @Magister@lemmy.world 2025-12-16 15:29

    alias cd..='cd ..' alias ll='LC_COLLATE=C ls -alFh' alias ls='ls --color=auto'

    Open ##1384916

  • @Auster@thebrainbin.org 2025-12-16 15:54

    (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

    Open ##1384920

  • @emb@lemmy.world 2025-12-16 15:54

    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.

    Open ##1384921

  • @TechnoCat@piefed.social 2025-12-16 16:44

    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

    Open ##1384922

  • @Oinks@lemmy.blahaj.zone 2025-12-16 16:52

    I’m not much of a one-liner collector but I like this one: vim +copen -q .) 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).

    Open ##1384924

  • @eskuero@lemmy.fromshado.ws 2025-12-16 17:46

    echo 'dXIgbW9tCmhhaGEgZ290dGVtCg==' | base64 -d

    Open ##1384926

  • @demonsword@lemmy.world 2025-12-16 18:19

    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 = :' 2- find out which process is consuming your bandwidth: $ sudo nethogs

    Open ##1384928

  • @HiddenLayer555@lemmy.ml 2025-12-16 19:13

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

    Open ##1384933

  • @qjkxbmwvz@startrek.website 2025-12-16 19:28

    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 :)

    Open ##1384934

  • @kittenroar@beehaw.org 2025-12-16 19:51

    systemd-run lets you run a command under some limitations, ie systemd-run --scope -p MemoryLimit=1000M -p CPUQuota=20% ./heavyduty.sh

    Open ##1384937

  • @marighost@piefed.social 2025-12-16 20:06

    I could very easily, I’ve just only use rsync a handful of times for one-off files or small directories. Thinking of using it for several Tbs scares me 😅

    Open ##1384939

  • @Geodes_n_Gems@lemmy.ml 2025-12-16 20:10

    Running Wine is the command I’ve used the most probs, you can tell I haven’t touched the thing in months.

    Open ##1384940

  • @corsicanguppy@lemmy.ca 2025-12-16 20:33

    Journalctl | grep -C 10 'foo' was useful for me when I needed to troubleshoot some fstab mount fuckery on boot. Ha! Remember back when there was no fstab fuckery? Good times. But you have a massive init blob slowly eating other services and replacing them with shitty replicants like this embarrassment (ohai root NFS) and all of us Unix people are chuckling in our reduced-fuckery ‘hell’.

    Open ##1384941

  • @marcie@lemmy.ml 2025-12-16 20:45

    rpm-ostree status rpm-ostree reset rpm-ostree rebase idk i love rpm-ostree man

    Open ##1384943

  • @roran@sh.itjust.works 2025-12-16 21:29

    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

    Open ##1384945

  • @fubarx@lemmy.world 2025-12-16 22:16

    ripgrep

    Open ##1384950

  • @RavenofDespair@lemmy.ml 2025-12-17 00:27

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

    Open ##1384952

  • @GaryGhost@lemmy.world 2025-12-17 02:42

    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.

    Open ##1384954

  • @wheezy@lemmy.ml 2025-12-17 04:12

    I forget where I got it. But mine will do this if I double tap ESC after I sent the command without sudo. Very useful. I should probably figure out what it was I added to do this. Doesn’t issue the command. Have to hit enter. Useful to verify it’s the right command first. With the way bash history can work Id be worried about running sudo rm -rf ./* by mistake.

    Open ##1384957

  • @bigredgiraffe@lemmy.world 2025-12-17 04:49

    To add to this one, it also supports more than just the previous command (which is what !! means), you can do like sudo !453 to run command 453 from your history, also supports relative like !-5. You can also use without sudo if you want which is handy to do things like !ls for the last ls command etc. Okay one more, you can add :p to the end to print the command before running it just in case like !systemctl:p which can be handy!

    Open ##1384962

  • @harsh3466@lemmy.ml 2025-12-17 05:25

    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.

    Open ##1384963

  • @utopiah@lemmy.ml 2025-12-17 05:48

    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

    Open ##1384965