Theophilus Ngaribvume

This is Where i Share my Experiences, Ideas, and Thoughts. One Post a Day.

Linux Commands That Can Improve Your Productivity?

25 May, 2021 - 5 min read

Linux Commands That Can Improve Your Productivity?

Sometimes it’s hard to be a programmer, the tasks you’ll have to do are sometimes repetitive and boring, especially if you don’t know much about the terminal.

1. Curl

Have you ever struggled to test your API endpoint?. Well, curl can help you test a URL endpoint. Curl can be used for determining whether your application can ping another service on a particular domain name, such as a database, or diagnosing if your web services are working as intented.

For example, Testing if your API can be riched from a frontend.

curl -I -s

The -I option shows the header information and the -s option silences the response body.

You can test your website API or healthy using Curl. However, if you want to test with curl and return JSON data, it will be well unreadable. So, we can use another python command to prettify the JSON response.

$ cat test.json | python -m json.tool { "properties": { "age": { "description": "Age years", "minimum": 0, "type": "integer" }, "firsn_Name": { "type": "string" }, "last_name": { "type": "string" } }, "required": [ "first_name", "last_name" ], "title": "Person", "type": "object" }

2. ls

ls lists files in a directory. It is also a handy tool in examining directory files permissions if used as ls -l

3. tail

The tail command displays the last part of a file. Imagine you want to check the nginx log file, you don’t really need to read the whole content of a file but rather the last part of recent request logs.

Try running

tail -f /var/log/httpd/access_log

The -f (follow) option is used to output the lines as they’re written to the file. Another option for tails is using the -n option which indicates the last lines you want to display.

4. cat

cat is used for printing the contents of a file. This is a handy command for checking files without the need to write the file.

5. grep

grep is a file pattern search tool.

6. env

env is used to check the environment variables in the system

$ env SHELL=/bin/bash SESSION_MANAGER=local/vibrus-HP-ProBook-450-G5:@/tmp/.ICE-unix/2331,unix/vibrus-HP-ProBook-450-G5:/tmp/.ICE-unix/2331 QT_ACCESSIBILITY=1 COLORTERM=truecolor XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg XDG_MENU_PREFIX=gnome- GNOME_DESKTOP_SESSION_ID=this-is-deprecated LANGUAGE=en_ZW:en

7. top

This command displays the top processes in your system. You can see which processes are running and how much memory are they using.

vibrus@nerdlify:~/$ top top - 20:25:32 up 2 days, 8:53, 1 user, load average: 0.84, 0.70, 0.70 Tasks: 332 total, 1 running, 330 sleeping, 0 stopped, 1 zombie %Cpu(s): 1.4 us, 0.8 sy, 0.0 ni, 97.5 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 15901.9 total, 1353.2 free, 3480.5 used, 11068.2 buff/cache MiB Swap: 2048.0 total, 2015.8 free, 32.2 used. 11401.5 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2193 vibrus 20 0 1270948 113132 65540 S 6.3 0.7 78:43.11 Xorg 2345 vibrus 20 0 5344148 370332 93132 S 3.6 2.3 73:22.17 gnome-s+ 60363 vibrus 20 0 823244 50580 39028 S 2.6 0.3 0:10.76 gnome-t+ 235 root -51 0 0 0 0 S 1.7 0.0 1:58.62 irq/128+ 67689 vibrus 20 0 36.6g 276528 114964 S 1.7 1.7 6:14.77 chrome 2444 vibrus 20 0 320608 7640 6576 S 1.0 0.0 0:06.43 gsd-hou+ 55215 vibrus 20 0 32.4g 118500 89604 S 0.7

8. df

This is a command you can run to check your disk space. Sometimes as a developer, you might get the need to check the free space in your system. When used with the -h option, this command will print the human-readable disk usage statistics.

vibrus@nerdlify:~/$ df -h Filesystem Size Used Avail Use% Mounted on udev 7.8G 0 7.8G 0% /dev tmpfs 1.6G 2.3M 1.6G 1% /run /dev/sda2 916G 99G 770G 12% / tmpfs 7.8G 109M 7.7G 2% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/loop0 99M 99M 0 100% /snap/core/11081

9. du

du is used to view information about file disk usage. This command can be issued with -h option for human readable details and also with -s for the file total size.

When run on ubuntu 20.04 this is what you'll get:

vibrus$nerdlify:~/$ du -sh * 1.7G android-studio-ide-201.7199119-linux 883M android-studio-ide-201.7199119-linux.tar.gz 5.1M anydesk_6.1.0-1_amd64.deb 73M google-chrome-stable_current_amd64.deb 137M local-5.4.1-linux.deb 85M mongodb-compass_1.26.1_amd64.deb 16K 63M Termius.deb

10. chmod

If you're a seasoned linux user you have encountered the permission denied error when you tried to run an application binary file. chmod can help you correct the permission of your file. If your application is you can correct the permission by running.

vibrus$nerdlify:~/$ chmod +x

+x is the option used to grand execution rights to the file.

11. history

As a server administrator you might have forgetten which command you issued an hour ago. The linux shell can help you navigate all the command history and find the ones usefull one since the start of the session.

Creator of Workly and Nerdlify, Currently working at Pindula.

© 2021, Theophilus Ngaribvume. All Rights Reserved.