Terminal, Shell, or Console secrets from a supercoder!  

Find out the best Terminal, Shell, or Console commands and rule the dev world!

December 2, 2022

By: Heberlyn

Your wishes are our commands!

People say there are no shortcuts to success. But this is not the case in devslife!

We asked one of our expert coders to share some secrets and we’ve gathered these command tips, especially for you!

1. Detect as quickly as a flash! 

It’s no news that servers often have high storage consumption problems. But how fast you can solve these inconveniences does make a difference!

Using du -h –max-depth=1 [DIRECTORY] | sort -h command can be a quick way to detect the folder or file that’s causing problems!  

This command lists files from smallest to largest. It makes it easier to find errors, such as files that are writing code by mistake or those announcing failures, among others!

Take a look at this example of a list of folders in the project/path, and see how they are sorted from smallest to largest:

root@project-production:~# du -h --max-depth=1 project/ | sort -h
12K     project/helpers
36K     project/db_init
632K    project/data
134M    project/wordpress_folder1
147M    project/wordpress_folder2
161M    project/wordpress_folder3
273M    project/project
713M    project/
root@project-production:~#

2. Make searches as easy as pie!   

Simplify quests by using this popular command! 

Use grep [options] search_word [FILE] to look for words in files and directories.  

For example, if you have a database error, make a search query using the word database and check the results. 

This command has plenty of other helpful options! 

In this example, by searching install on a file (in this case, Dockerfile), grep displays all the lines containing the word, giving you an idea of what installations might be running.  

root@project-production:~/project/project/docker/php# grep install Dockerfile
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev
RUN docker-php-ext-install soap
#RUN pecl install mcrypt && docker-php-ext-enable mcrypt
root@project-production:~/project/project/docker/php#

3. Make a heavy file seem as light as a feather! 

Waiting for all eternity until a heavy file opens is such a bug! But why open lines and lines of code when you only need to check just a few?

Use tail -n100 command to read the file and open the lines you need! 

For example, when reading a file (in this case, Dockerfile) you can display only the first 10 lines and then the last 20.

root@project-production:~/project/project/docker/php# tail -n10 Dockerfile
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev
RUN set -ex && apk --no-cache add libxml2-dev
RUN docker-php-ext-install soap

#RUN apk add --no-cache gcc
#RUN apk add --no-cache autoconf
#RUN pecl install mcrypt && docker-php-ext-enable mcrypt

RUN apk update
root@project-production:~/project/project/docker/php# tail -n20 Dockerfile
FROM php:7.2-fpm-alpine

WORKDIR /var/www/html

RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev
RUN set -ex && apk --no-cache add libxml2-dev
RUN docker-php-ext-install soap

#RUN apk add --no-cache gcc
#RUN apk add --no-cache autoconf
#RUN pecl install mcrypt && docker-php-ext-enable mcrypt

RUN apk update
root@project-production:~/project/project/docker/php#

Loved these commands? We have more tips waiting for you! Check out these well-kept HTML secrets for better coding!


✍️ This article was written by our copywriter, Sofia, in collaboration with our DEV expert, Heberlyn.