7 Useful macOS/Linux Commands
1. wc
Counting lines, words, and characters respectively. Character counting includes invisible chars.
Useful Flags
-l: count lines only.-w: count words only.-c: count characters only.
2. ls
Listing files and directories. ls automatically prints its output as a single column when its output is redirected.
e.g. to count the number of files in a directory:
ls | wc -lUseful Flags
-l: print output in a single column. This will also include other file attributes per file in the output.-C: print output in multiple columns. Pay attention – this flag name is uppercase!-a: include hidden files.
3. head
Peeking at the top of a file. Can be used to truncate long output from other commands.
e.g. list the first five files in a directory:
ls | head -n5Useful Flags
-n: specify how many lines to print. Defaults to 10.
4. cut
Prints specific columns from a text file.
Useful Flags
-f: the number of columns to print. This flag can accept a comma-separated string to print specific columns,-f1,3, or a dash-separated range, e.g.-f2-4.-d: specify the delimiter character, which is\tby default.-c: defines the character position of what constitutes a column. This flag can accept a comma-separated string to print specific columns or a dash-separated range.
5. grep
Finds patterns in files.
Useful Flags
-v: find matches that don’t contain this argument.-w: match full words only, not parts of words.
6. sort
Reorders the lines in a file (ascending order by default).
Useful Flags
-r: order in descending order.
7. uniq
Detects repeated adjacent lines in a file and removes the duplicates.
Useful Flags
-c: count occurrences.
8. sha256sum
I know the title said 7 commands but here’s an extra one on the house – outputs the SHA-256 checksum of a file.
Useful Flags
-b: treat the input as binary.


