GO KALI FREE
Search Commands

cut Linux Command

Extracts specific columns/fields from each line of a file.

What does cut do?

Extracts specific columns/fields from each line of a file.

Syntax

cut [options] file

Practical example

cut -d':' -f1 /etc/passwd

Questions about cut

How do I extract specific columns with cut?

Use `cut -f1,3 file` to extract the first and third columns. Fields are separated by tab by default.

How do I set a custom delimiter?

Use `cut -d':' -f1 file` to use colon as the delimiter. Use `-d','` for comma, `-d' '` for space, etc.

How do I extract the first 5 characters of each line?

Use `cut -c1-5 file` to extract characters 1 through 5 from each line. The `-c` flag works with character positions.

How do I extract everything except a field?

Use `cut -f2 --complement file` to exclude the second field. The `--complement` flag inverts the field selection.

How do I cut by byte position?

Use `cut -b1-10 file` to extract the first 10 bytes of each line. This is useful for fixed-width data.

How do I extract usernames from /etc/passwd?

Use `cut -d':' -f1 /etc/passwd` to extract the first field (username) from the colon-delimited passwd file.

How do I cut with a space delimiter?

Use `cut -d' ' -f1,3 file` to use space as the delimiter. Be careful with multiple consecutive spaces.

How do I cut a CSV file?

Use `cut -d',' -f1,3 file.csv` to extract specific columns from a comma-separated values file.

Related Search Commands

uniq

Reports or filters out repeated lines in a sorted file.

tr

Translates, deletes, or squeezes characters from standard input.

sort

Sorts lines of text files alphabetically or numerically.

xargs

Builds and executes command lines from standard input (useful with pipes).

sed

Stream editor for filtering and transforming text (find/replace, insert, delete).

find

Searches for files and directories in a directory hierarchy by name, type, size, etc.