To find a string within a file, just run:
grep "search string" filename
Often, you will want to search multiple files, you can do that with the recursive flag:
grep -r "search string" ./
This will print the entire line containing the string. If you just want to print filenames, use the
grep -rl "search string" ./
Also, I'll leave this here as its bloody useful. Want to open all the files you've searched for with vim (or another text editor)?
vim $(grep -rl "search string" ./)
To find a filename, use
find ./ -name filename.
You can use wildcard characters as well. So for example to find all go files:
find . -name *go
If you want to take a look inside a large file,
less is your friend.
less won't open the entire file - so it doesn't use as much memory - however you can still navigate and search as you would with
vim or a similar tool.
To print a file to output (stdout), use
To watch the end of a file (useful for watching logs):
tail -f file.log
To just print the last few lines of a file:
For more info click here
To sort something, pipe it into sort.
cat a file then pipe it:
cat filename | sort
Let's say you've run the above sort command, and wish to find unique lines:
cat filename | sort | uniq
You may wish to count how many times each line is duplicated:
cat filename | sort | uniq -c
Now lets say you wish to count the number of unique lines in a file. You could run:
cat filename | sort | uniq | wc -l
To calculate the number of lines in a file:
cat filename | wc -l
du -sh ./*)
To view the size of a file, use
du -sh filename.
Combine this with
* to view the size of all files in the current directory.
The usage of various disks and partitions can be seend with
htop is a great tool for monitoring cpu and ram usage.