UNIX/LINUX COMMAND CHEAT SHEET (Part 2)

Posted by

For part 1 of Unix/ Linux commands which includes file commands and process commands.  Click here.

SYSTEM COMMANDS:

COMMAND DESCRIPTION
shutdown Shuts down the machine.
reboot Restart the machine.
df Displays disk usage.
du

Displays directory space usage.

free

Displays memory and swap usage.

finger user

Displays info about user.

date

Displays current date and time.

FILTER COMMANDS:

COMMAND DESCRIPTION

find [starting_dir] -name “pattern” -print

Starts searching from the starting_dir for the name of the file(s) matching the pattern and prints it on the standard output.

find [starting_directory] – type [f|d] -print

Starts searching from the starting_directory for the file type: f=plain text, d=directory and prints it on the standard output.

find [starting_dir] -name “pattern” -exec ls -l {}\;

Starts searching from the starting_dir for the name of the file matching the pattern and executes the next command to display a long list of the files.

sort filename

Sorts the contents of a text file named as filename, line by line

sort -r filename

Reverse sort the contents of a text file named as filename, line by line (-r reverse)

sort -o output.txt file.txt

Sorts file.txt and stores the result in output.txt (-o output)

sort -c filename

To check if file named as filename is already sorted (-c check)

sort -n filename

To sort a file named as filename numerically (-n numeric sort)

wc filename Counts the words, newlines, or bytes of each input file named as filename

wc -l filename

Prints the newline counts on the standard output. (-l lines)

wc -m filename

Prints the character counts on the standard output. (-m chars)

wc -c filename Prints the byte counts on the standard output. (-c bytes)
wc -w filename Prints the word counts on the standard output.  (-w words)

split filename

Splits the file named as filename into multiple files with 1000 lines into each output file by default.

split  {filename}  {prefix_name} Splits the file named as filename and Creates split files with specified prefix_name.

split -l number_of_lines filename

Splits the file named as filename with the specified number of lines per output file.

cut -d “delimiter” filename

cuts the file named as filename by the delimiter.

paste filename

Displays the contents of file named as filename

paste file1 file2

By default, the paste command merges the files (file1,file2) in parallel. The paste command writes corresponding lines from the files as a tab delimited on the standard output.

uniq filename

Reports or filters out repeated lines in a file named as filename

uniq -c filename

Prefix lines with a number representing how many times they occurred. (-c count)

uniq -d filename

Displays only duplicated lines of the file on the standard output (-d repeated/duplicated)

nl filename

To number each line in the file and display the result to standard output.

FILE COMPARISON COMMANDS:

COMMAND DESCRIPTION

cmp file1 file2

If two files are different and where the first difference appears.

comm file1 file2

Display the differences in text files in a different format

diff file1 file2

Analyzes file1 and file2 and prints the lines that are different on the standard output.

diff -i file1 file2

Ignores the case(upper case or lower case) differences in file contents.

diff -y file1 file2

To display the differences between the files in a side by side view.

diff -b file1 file2

 Ignore white space differences.

diff -B file1 file2

 Ignore blank lines
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s