$ ls -lrta
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.
How to list files in current directory?
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
Compress a file
$ gzip <filename>
un-compress a zipped file
$ gunzip <filename>
Look into a compressed file without decompressing it
$ gzcat <filename>
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.
List all processes with given name
$ ps -elf | grep java
This command lists all the processes that have name 'java' in it.
Kill a process by process id
$ sudo kill -9 <pid>
List all processes with memory and cpu usage
$ top $ htop
Manage services using systemctl
Start a service
$ sudo systemctl start golo-feedback.service
Stop a service
$ sudo systemctl stop golo-feedback.service
Check status of a service
$ sudo systemctl status golo-feedback.service
Enable service to start on system startup
$ sudo systemctl enable golo-feedback.service
Reload service information from filesystem
$ sudo systemctl daemon-reload
Top articles in this category:
- DevOps interview questions - Basic Concepts, Microservices, Databases, AWS
- Scp send & receive files on unix
- Difference between Forward Proxy and Reverse Proxy Server
- Upgrade MySQL from 5.7 to 8 on Ubuntu 18.04
- Upgrade Jenkins on Ubuntu 18.04 LTS
- Install RabbitMQ and Erlang 23 on Ubuntu 20
- Permanent swap space in Ubuntu
Recommended books for interview preparation:
Find more on this topic:
Dev Ops Automation - Ubuntu OS, Centos, MySql, MongoDB, Java, AWS Infrastructure.
Last updated 1 week ago