30 interesting commands for the Linux shell (thediligentdeveloper.com)
from learnbyexample@programming.dev to linux@lemmy.ml on 25 May 04:18
https://programming.dev/post/30978584

#linux

threaded - newest

deathbird@mander.xyz on 25 May 04:40 next collapse

Actually yeah, those are.

naught101@lemmy.world on 25 May 07:02 next collapse

Nice.

eugenia@lemmy.ml on 25 May 07:13 collapse

…and renice.

vort3@lemmy.ml on 25 May 07:35 next collapse

Looks like the site is down or blocked in my country.

Could anyone please be so nice and copy paste those commands here?

ClusterBomb@lemmy.blahaj.zone on 25 May 08:01 collapse

  1. Supervise command (run every 2s)
watch "ls -larth"
  1. Kill program using one port
sudo fuser -k 8000/tcp
  1. Limit memory usage for following commands
ulimit -Sv 1000       # 1000 KBs = 1 MB
ulimit -Sv unlimited  # Remove limit
  1. Rename selected files using a regular expression
rename 's/\.bak$/.txt/' *.bak
  1. Get full path of file
readlink -f file.txt
  1. List contents of tar.gz and extract only one file
tar tf file.tgz
tar xf file.tgz static
  1. List files by size
ls -lS
  1. Nice trace route
mtr google.com
  1. Find files tips
find . -size 20c             # By file size (20 bytes)
find . -name "*.gz" -delete  # Delete files
find . -exec echo {} \;      # One file by line
./file1
./file2
./file3
find . -exec echo {} \+      # All in the same line
./file1 ./file2 ./file3
  1. Print text ad infinitum
yes
yes hello
  1. Who is logged in?
w
  1. Prepend line number
ls | nl
  1. Grep with Perl like syntax (allows chars like \t)
grep -P "\t"
  1. Cat backwards (starting from the end)
tac file
  1. Check permissions of each directory to a file

It is useful to detect permissions errors, for example when configuring a web server.

namei -l /path/to/file.txt
  1. Run command every time a file is modified
while inotifywait -e close_write document.tex
do
    make
done
  1. Copy to clipboard
cat file.txt | xclip -selection clipboard
  1. Spell and grammar check in Latex
detex file.tex | diction -bs

You may need to install the following: sudo apt-get install diction texlive-extra-utils.

  1. Check resources’ usage of command
/usr/bin/time -v ls
  1. Randomize lines in file
cat file.txt | sort -R
cat file.txt | sort -R | head  # Pick a random sambple

# Even better (suggested by xearl in Hacker news):

shuf file.txt
  1. Keep program running after leaving SSH session

If the program doesn’t need any interaction:

nohup ./script.sh &

If you need to enter some input manually and then want to leave:

./script.sh
<Type any input
vort3@lemmy.ml on 25 May 09:44 next collapse

Thank you very much!

etchinghillside@reddthat.com on 25 May 18:03 collapse

You the best.

scrion@lemmy.world on 25 May 08:58 next collapse

Most people will run a post 2.6 kernel, so prlimit will be available as an interesting alternative to ulimit.

bizdelnick@lemmy.ml on 25 May 10:52 next collapse

The most interesting command for the Linux shell is known as Barmin patch.

sxan@midwest.social on 25 May 10:57 next collapse

This is a good list.

There are three kinds of Linux commands:

  • commands I use frequently
  • commands I’ve never seen or don’t know about. There’s almost nothing in standard POSIX that falls in this category, and a lot of OSS that does. E.g., I use to always reach for fuser until I realized it’s not a base install on many distros, so I switched to lsof which is is, and is also both more powerful and harder to use.
  • commands I’ve seen before but use so infrequently I forget they exist, or what they’re called. This is sadly a larger set than I’d like.

Some of these in this list are the third kind.

thingsiplay@beehaw.org on 25 May 15:32 collapse

Fantastic list. I just want add one to this sublist. I use these often:

  1. Find files tips
find . -maxdepth 1 -type f -printf '%f\n'

-printf ‘%f\n’: This is a function to print in a formatted manner, typically used in C or other languages. %f means here print the filename only, without directory or slashes. And add a newline off course, but you could also print it by space enclosed between quotes: “%f” I prefer this over executing separate echo process.

-type f: This will limit the output depending on the filetype you define. Here f means files only. This can have multiple types too, in example directories or executables.

-maxdepth 1: Do not search subdirectories, only look in current directory like ls does. You could specify more depth too. And there is even -mindepth 2 in example, if you want to skip some top level directories and only search somewhere deep. This makes sense if you have organized structure of directories in example.