Basic Unix commands for every programmer

Carvia Tech | April 30, 2019 | 2 min read | 152 views | unix-concepts


Unix is great for programmers, it helps automate your day to day mundane tasks, its secure, it takes less resources, its free. Unix is a good choice for hosting your application if you are developing in Java.

Basic Commands

How to list files in current directory?

$ ls -lrta

Find Free Memory on Server

$ free -m

Find Free Disk Space

$ df -h

Search file in current directory and subdirectory whose name contains 'log'

$ find . -name 'log'

Find Exception in log files in current directory

$ grep 'Exception' log.txt
$ grep -i 'Exception' log.txt
$ grep -i 'exception' log.txt | wc -l

List all log files that contain the given token

$ grep -rl 'token' *.log

Tail last 200 lines of a log file*

$ tail -200f file.log

How to make a file executable

$ chmod +x filename.jar

File compression

  1. Compress a file

    $ gzip <filename>
  2. un-compress a zipped file

    $ gunzip <filename>
  3. Look into a compressed file without decompressing it

    $ gzcat <filename>

Unix Process

  1. Find a process running on given port, we can use any of the below two commands.

    $ sudo netstat -ltnp | grep -w '8080'
    $ sudo lsof -t -i:8080

    This information can be used to take further decision, like killing a program, etc.

  2. List all processes with given name

    $ ps -elf | grep java

    This command lists all the processes that have name 'java' in it.

  3. Kill a process by process id

    $ sudo kill -9 <pid>
  4. List all processes with memory and cpu usage

    $ top
    $ htop

Manage services using systemctl

  1. Start a service

    $ sudo systemctl start golo-feedback.service
  2. Stop a service

    $ sudo systemctl stop golo-feedback.service
  3. Check status of a service

    $ sudo systemctl status golo-feedback.service
  4. Enable service to start on system startup

    $ sudo systemctl enable golo-feedback.service
  5. Reload service information from filesystem

    $ sudo systemctl daemon-reload

Top articles in this category:
  1. Install Artifactory OSS private maven repository
  2. Installing nginx on macOS Mojave using brew
  3. Install and upgrade Jenkins on Ubuntu



Find more on this topic:
Dev Ops image
Dev Ops

Dev Ops Automation - Ubuntu OS, Centos, MySql, MongoDB, Java, AWS Infrastructure.

Last updated 1 month ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info