$ ls -lrta
Basic Unix commands for every programmer
Carvia Tech | April 30, 2019 | 2 min read | 141 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:
- Install Artifactory OSS private maven repository
- Installing nginx on macOS Mojave using brew
- Install and upgrade Jenkins on Ubuntu
Find more on this topic:
Recommended books for interview preparation:
Enter your email address to subscribe to this blog and receive notifications of new posts by email.