30 interesting commands for the Linux shell
30 interesting commands for the Linux shell
30 interesting commands for the Linux shell – The Diligent Developer
30 interesting commands for the Linux shell
30 interesting commands for the Linux shell – The Diligent Developer
Most people will run a post 2.6 kernel, so prlimit will be available as an interesting alternative to ulimit.
Actually yeah, those are.
This is a good list.
There are three kinds of Linux commands:
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.Some of these in this list are the third kind.
Looks like the site is down or blocked in my country.
Could anyone please be so nice and copy paste those commands here?
watch "ls -larth"
sudo fuser -k 8000/tcp
ulimit -Sv 1000 # 1000 KBs = 1 MB ulimit -Sv unlimited # Remove limit
rename 's/\.bak$/.txt/' *.bak
readlink -f file.txt
tar tf file.tgz tar xf file.tgz static
ls -lS
mtr google.com
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
yes yes hello
w
ls | nl
grep -P "\t"
tac file
It is useful to detect permissions errors, for example when configuring a web server.
namei -l /path/to/file.txt
while inotifywait -e close_write document.tex do make done
cat file.txt | xclip -selection clipboard
detex file.tex | diction -bs
You may need to install the following: sudo apt-get install diction texlive-extra-utils.
/usr/bin/time -v ls
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
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 you want> <Ctrl-Z> # send process to sleep jobs -l # find out the job id disown -h jobid # disown job bg # continue running in the background
Of course, you can also use screen or tmux for this purpose.
timeout 10s ./script.sh
Restart every 30 minutes
while true; do timeout 30m ./script.sh; done
comm file1 file2
Prints these three columns:
Lines unique to file1. Lines unique to file2. Lines both in file1 and file2.
With options -1, -2, -3, you can remove each of these columns.
split -l LINES -d file.txt output_prefix
If a program eats too much memory, the swap can get filled with the rest of the memory and when you go back to normal, everything is slow. Just restart the swap partition to fix it:
sudo swapoff -a sudo swapon -a
sudo fsck.ext4 -f -y /dev/sda1 sudo fsck.ext4 -v /dev/sda1 sudo mke2fs -n /dev/sda1 sudo e2fsck -n <first block number of previous list> /dev/sda1
fallocate -l 1G test.img
To join, shuffle, select, etc. pdftk is a great tool:
pdftk *.pdf cat output all.pdf # Join PDFs together pdftk A=in.pdf cat A5 output out.pdf # Extract page from PDF
You can also manipulate the content with cpdf:
cpdf -draft in.pdf -o out.pdf # Remove images cpdf -blacktext in.pdf -o out.pdf # Convert all text to black color
Write random data, encode it in base64 and monitor how fast it is being sent to /dev/null
cat /dev/urandom | base64 | pv -lbri2 > /dev/null # pv options: # -l, lines # -b, total counter # -r, show rate # -i2, refresh every 2 seconds
apt-file update apt-file search dir/file.h
Thank you very much!
You the best.
Fantastic list. I just want add one to this sublist. I use these often:
- 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.
Nice.
...and renice.
The most interesting command for the Linux shell is known as Barmin patch.