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
Print text ad infinitum
yes
yes hello
Who is logged in?
w
Prepend line number
ls | nl
Grep with Perl like syntax (allows chars like \t)
grep -P "\t"
Cat backwards (starting from the end)
tac file
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
Run command every time a file is modified
while inotifywait -e close_write document.tex
do
make
done
Copy to clipboard
cat file.txt | xclip -selection clipboard
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.
Check resources' usage of command
/usr/bin/time -v ls
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
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 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.
Run a command for a limited time
timeout 10s ./script.sh
# Restart every 30 minutes
while true; do timeout 30m ./script.sh; done
Combine lines from two sorted files
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 long file in files with same number of lines
split -l LINES -d file.txt output_prefix
Flush swap partition
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
Fix ext4 file system with problems with its superblock
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.
Actually yeah, those are.
Most people will run a post 2.6 kernel, so prlimit will be available as an interesting alternative to ulimit.
Looks like the site is down or blocked in my country.
Could anyone please be so nice and copy paste those commands here?
It is useful to detect permissions errors, for example when configuring a web server.
You may need to install the following: sudo apt-get install diction texlive-extra-utils.
# Even better (suggested by xearl in Hacker news):
If the program doesn't need any interaction:
If you need to enter some input manually and then want to leave:
Of course, you can also use screen or tmux for this purpose.
# Restart every 30 minutes
Prints these three columns:
With options -1, -2, -3, you can remove each of these columns.
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:
To join, shuffle, select, etc. pdftk is a great tool:
You can also manipulate the content with cpdf:
# Write random data, encode it in base64 and monitor how fast it is being sent to /dev/null
Thank you very much!
You the best.
This is a good list.
There are three kinds of Linux commands:
fuseruntil I realized it's not a base install on many distros, so I switched tolsofwhich is is, and is also both more powerful and harder to use.Some of these in this list are the third kind.
Nice.
...and renice.
The most interesting command for the Linux shell is known as Barmin patch.