ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Operating Systems

Commonly Used UNIX / Linux Commands for different situations

Updated on May 15, 2017

Whether you are a seasoned or newbie System Administrator, this compilation of UNIX / Linux commands can help you in dealing with different tasks.

"Tux" The official Linux mascot. Created by: Larry Ewing
"Tux" The official Linux mascot. Created by: Larry Ewing

Practical uses of awk command

awk – is a pattern scanning and text processing language. The awk command stands for the name of its authors “Aho,Weinberger, and Kernighan”. Aside from being a unix command, awk is also considered as programming language.


Sample file contains below items:

cat jobclass.txt
cat jobclass.txt

Search for lines with specific pattern

awk '/Melee/' jobclass.txt

awk '/Agi/' jobclass.txt

Show specific rows only

awk '{print $1,$4}' jobclass.txt

Show specific rows only without white spaces

awk '{print $1$4}' jobclass.txt

Combine pattern and row filtering

awk '/Int/ {print $2}' jobclass.txt

awk '/Int/ {print $2,$4}' jobclass.txt

Use conditional statement

awk '{if ($1 > 9) print $1,$2}' jobclass.txt

Set different field separator

Sample below are separated by comma instead of white space.

We use optional command -F to indicate that comma will be used as field separator.

awk -F ',' '/Range/ {print $1,$2}' jobclass2.txt

awk -F ',' '/Range/ {print $1,$3}' jobclass2.txt

Use AND for pattern searching

awk '/Melee/ && /Str/' jobclass.txt

Use OR for pattern searching

awk '/Melee/ || /Range/' jobclass.txt

Use NOT for pattern searching

awk '!/Range/' jobclass.txt

Use awk together with other command

A quick Trivia: awk can be written as a stand alone script.



Practical uses of sed for text substitute

sed – used for filtering and text transforming. Sed stands for stream editor.


Sample file contains below items:

Substitute text

sed 's/Agi/Dex/' jobclass.txt

Substitute white space

sed 's/\s/,/g' jobclass.txt

Remove specific pattern

sed 's/Warlock/ /g' jobclass.txt

Remove lines with specific pattern

sed '/int/d' jobclass.txt

Remove blank lines

Sample jobclass3.txt has blank lines next to every lines with text.

sed '/^$/d' jobclass3.txt

Combine sed with other unix command

ls -l | sed 's/geekinbluejeans/user/g'

Commonly used UNIX / Linux Commands

Practical cheat sheet for your reference.

UNIX is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, developed in the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

source: https://en.wikipedia.org/wiki/Unix

Linux is a Unix-like and mostly POSIX-compliant computer operating system (OS) assembled under the model of free and open-source software development and distribution. The defining component of Linux is the Linux kernel, an operating system kernel first released on 5 October 1991 by Linus Torvalds.

source: https://en.wikipedia.org/wiki/Linux




Check partition

fdisk -l


Check for Disk Space

Recommended command for checking disk space usage in Linux
df -h

It is also possible to specify.
df -h /var

Compress / Archive file using tar

tar -cvf name_of_archive.tar file_to_compress
or
tar -cvf name_of_archive.tar directory_to_compress

Usually, you are going to compress multiple files.
tar -cvf name_of_archive.tar file1 file2 file3


Extract a tar file

tar -xvf file_name.tar


View the content of tar file

tar -tvf file_name.tar


Use current server date and time for labeling

Year month day format
`date +%Y%m%d`

Time format

`date +%T`

Year month day with time format
`date +%Y%m%d%T`

Where:
%Y - year
%m - month
%d - day

eg.
touch filename.`date +%Y%m%d%T`


Show only directory information using ls

ls -ld directory_name

eg.
ls -ld MY_DIRECTORY


Look for domain name server of an IP address

nslookup ip_address

eg.
nslookup 8.8.8.8


Show information regarding drivers and hardware

dmesg

Clear message befor next reboot
dmesg -c


View available memory using dmesg

dmesg | grep Memory


Installing package

For Redhat base Linux
rpm -ivh package_file
eg.
rpm -ivh google-chrome.rpm

For Debian base Linux
dpkg -i package_file
eg.
dpkg -i google-chrome.deb

For Solaris
pkgadd -d package_file
eg.
pkgadd -d afio-2.5-sol10-sparc

List all installed package

For Redhat base Linux
rpm -qa


Identify whether a particular package is installed

For Redhat base Linux
rpm -qa | grep package_name
eg.
rpm -qa | grep 'mysql'

rpm -q package_name
eg.
rpm -q mysql-lib


Identify which package does a file belong to

For Redhat base
rpm -qf file_name
eg.
rpm -qf /usr/bin/mysqlaccess


Show information about installed package

For Redhat base
rpm -qi package_file
eg.
rpm -qi google-chrome


List all the files in the package

For Redhat base
rpm -qlp package_file
eg.
rpm -qlp ovpc-2.1.10.rpm

Upgrading a package

For Redhat base
rpm -Uvh package_file
eg.
rpm -Uvh google-chrome.rpm


Uninstall a package

rpm -ev MySQL-client


List all Ports

netstat -a

List all tcp ports
netstat -at

List all udp ports
netstat -au


Look for domain name server of an IP address

nslookup ip_address
eg.
nslookup 8.8.8.8


Show how long is your Unix / Linux system is running

uptime


List all running services

service --status-all
eg.
service --status-all | less
service --status-all | grep vmtoolsd


Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.