Filtering IO/File
head
head file.txt // display the first 10 lines of the file "file.txt"
head -n 20 file.txt // display the first 20 lines of the file "file.txt"
head -c 100 file.txt // display the first 100 bytes of the file "file.txt"
head -q file1.txt file2.txt file3.txt // display the first 10 lines of each of the three files, without printing their namestail
tail file.txt // display the last 10 lines of the file "file.txt"
tail -n 20 file.txt // display the last 20 lines of the file "file.txt"
tail -f logfile.txt // continuously display the last few lines of the file "logfile.txt" as new lines are added to it
tail -q file1.txt file2.txt file3.txt // display the last 10 lines of each of the three files, without printing their namesgrep
grep 'pattern' file.txt // Search for "pattern" in "file.txt"
grep -i 'pattern' file.txt // Search for "pattern" in "file.txt", ignoring case
grep -w 'pattern' file.txt // Search for the whole word "pattern" in "file.txt"
grep -v 'pattern' file.txt // Search for lines that do not contain "pattern" in "file.txt"
grep -c 'pattern' file.txt // Count the number of lines that contain "pattern" in "file.txt"
grep -n 'pattern' file.txt // Show the line numbers of the lines that contain "pattern" in "file.txt"
grep -r 'pattern' /path/to/dir // Recursively search through all files and directories in /path/to/dir for "pattern"pipe
find
more
less
cut
sort
Last updated