Notifications
Clear all
Topic starter
10/03/2024 8:39 pm
This cheat sheet is aimed to assist you in finding files and content within files, as well as sorting data in various ways.
Command | Description |
---|---|
find /path -name 'filename' |
Search for files or directories within a specified path that match the given filename. |
find /path -type f -size +50M |
Find files larger than 50MB in a specific path. |
grep 'pattern' file |
Search for all lines in a file that match a specified pattern. |
grep -r 'pattern' /path |
Recursively search for a pattern within all files under a specified directory. |
grep -v 'pattern' file |
Search for all lines that do not match the pattern. |
grep -i 'pattern' file |
Perform a case-insensitive search. |
awk '/pattern/ {action}' file |
Search for a pattern in a file using AWK and perform an action on matching lines. |
sed -n '/pattern/p' file |
Search for a pattern in a file using SED and print the matching lines. |
sort file |
Sort the lines of a file in alphabetical order. |
sort -r file |
Sort the lines of a file in reverse order. |
sort -n file |
Sort the lines of a file numerically (useful for sorting lines that start with numbers). |
uniq file |
Filter out consecutive duplicate lines in a file. Typically used with sort to sort and then remove duplicates. |
uniq -c file |
Prefix lines by the number of occurrences. |
uniq -d file |
Only print duplicate lines. |
comm -12 file1 file2 |
Compare two sorted files and print only the lines that appear in both files. |
diff file1 file2 |
Compare files line by line and output the differences. |
sdiff file1 file2 |
Side-by-side comparison of file contents. |
locate filename |
Find files by name quickly using a database (updated with updatedb ). |
which command |
Locate a command and display its pathname or alias. |
find /path -perm 755 |
Find files with specific permissions. |
find /path -user username |
Find all files owned by a specific user. |
cut -d':' -f1 file |
Cut out the first field of each line in a file, fields are delimited by : . |
Tech Tinker reacted