- In bash, to show the common lines between two files:
comm -12 <( sort file1 ) <( sort file2 )
- Count the number of lines in a file:
wc -l file
- Grep exclude lines containing a word or words:
grep -v "word" file
grep -v -e "word1" -e "word2" file
- Find files in a tree containing specific text:
grep -rnw '/path/to/somewhere/' -e 'pattern'
- Find the top 20 largest files in a directory (recursively) – ignoring “Permission denied”:
du -a /dir/ 2> /dev/null | sort -n -r | head -n 20
- Check if a port is listening (without telnet):
nc -zv <ip> <port>
nc -zv <ip> <port1> <port2>
nc -zv <ip> <port>-<range>
- Find a file (or pattern) recursively in a directory, ignoring “Permission denied”:
find /dir -name "*ogging.xml" -print 2>/dev/null
find /dir -regex "pattern" 2>/dev/null
- Run a specific command through SSH, and attach a pseudo-terminal:
ssh user@host -t command
-- e.g. command = "bash" to force run a specific shell, regardless of user default
- Zip files into multiple fixed-size zip files, and re-join into single zip file:
zip -s50m mzip.zip <files>
zip -F mzip.zip --out single-file.zip
- Combine lines from multiple text files randomly:
sort -R file1.txt file2.txt file3.txt -o output.txt