Basic Unix commands for every programmer

Upasana | April 30, 2019 | 2 min read | 377 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. DevOps interview questions - Basic Concepts, Microservices, Databases, AWS
  2. Scp send & receive files on unix
  3. Difference between Forward Proxy and Reverse Proxy Server
  4. Upgrade MySQL from 5.7 to 8 on Ubuntu 18.04
  5. Upgrade Jenkins on Ubuntu 18.04 LTS
  6. Install RabbitMQ and Erlang 23 on Ubuntu 20
  7. Permanent swap space in Ubuntu

Recommended books for interview preparation:

Find more on this topic: