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.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: "https://hubpages.com/privacy-policy#gdpr"

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)