12 TERMINAL COMMANDS

Every Web Developer Should Know

The terminal is one of the foremost vital productivity tools in a developer’s arsenal. Mastering it will have an awfully positive impact on your work flow, as several everyday tasks get reduced to writing a straightforward command and striking Enter. In this article we’ve ready for you a set of UNIX system commands that may assist you get the foremost out of your terminal. a number of them square measure inbuilt, others square measure free tools that square measure reliable and may be put in but a moment.

Curl

Curl may be a program line tool for creating requests over HTTP(s), FTP and dozens of different protocols you will haven’t detected concerning. It will transfer files, check response headers, and freely access remote information.

In net development curl is usually used for testing connections and dealing with RESTful APIs.

# Fetch the headers of a URL.
curl -I http://google.com
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.com/?gfe_rd=cr&ei=0fCKWe6HCZTd8AfCoIWYBQ
Content-Length: 258
Date: Wed, 09 Aug 2017 11:24:01 GMT

# Make a GET request to a remote API.
curl http://numbersapi.com/random/trivia
29 is the number of days it takes Saturn to orbit the Sun.

Curl commands can get much more complicated than this. There are tons of options for controlling headers, cookies, authentication,and more.

Tree

Tree may be a little instruction utility that shows you a visible illustration of the files during a directory. It works recursively, going over every level of nesting and drawing a formatted tree of all the contents. this fashion you’ll quickly skim and notice the files you’re trying to find.

tree
.
├── css
│ ├── bootstrap.css
│ ├── bootstrap.min.css
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ ├── glyphicons-halflings-regular.woff
│ └── glyphicons-halflings-regular.woff2
└── js
├── bootstrap.js
└── bootstrap.min.js

There is also the option to filter the results using a simple regEx-like pattern:

tree -P ‘*.min.*’
.
├── css
│ ├── bootstrap.min.css
├── fonts
└── js
└── bootstrap.min.js

Tmux

According to its Wiki, Tmux may be a terminal electronic device, that translated in human language would mean that it is a tool for connecting multiple terminals to one terminal session.

It helps you to switch between programs in one terminal, add split screen panes, and connect multiple terminals to a similar session, keeping them in adjust. Tmux is particularly helpful once functioning on a far off server, because it helps you to produce new tabs while not having to log in once more.

Disk usage – du

The du command generates reports on the area usage of files and directories. it’s terribly straightforward to use and may work recursively, rummaging every directory and returning the individual size of each file.

A common use case for du is once one in every of your drives is running out of area and you do not understand why. Victimization this command you’ll be able to quickly see what proportion storage every folder is taking, therefore finding the most important memory saver.

# Running this will show the space usage of each folder in the current directory.
# The -h option makes the report easier to read.
# -s prevents recursiveness and shows the total size of a folder.
# The star wildcard (*) will run du on each file/folder in current directory.

du -sh *

1.2G Desktop
4.0K Documents
40G Downloads
4.0K Music
4.9M Pictures
844K Public
4.0K Templates
6.9M Videos

There is also a similar command called df (Disk Free) which returns various information about the available disk space (the opposite of du).

Git

Git is far and away the foremost standard version system immediately. It’s one among the shaping tools of contemporary internet dev and that we simply could not leave it out of our list.

There area unit many third-party apps and tools on the market however most of the people choose to access unpleasant person natively although the terminal. The unpleasant person CLI is basically powerful and might handle even the foremost tangled project history.

Tar

Tar is the default Unix tool for working with file archives. It allows you to quickly bundle multiple files into one package, making it easier to store and move them later on.

tar -cf archive.tar file1 file2 file3

Using the -x option it can also extract existing .tar archives.

tar -xf archive.tar

Note that almost all alternative formats like .zip and .rar can’t be opened by tar and need alternative command utilities like unfasten.

Many trendy operating system systems run associate expanded version of tar (GNU tar) that may additionally perform file size compression:

# Create compressed gzip archive.
tar -czf file.tar.gz inputfile1 inputfile2

# Extract .gz archive.
tar -xzf file.tar.gz

If your OS doesn’t have that version of tar, you can use gzip, zcat or compress to reduce the size of file archives.

md5sum

Unix has many inbuilt hashing commands together with md5sum, sha1sum and others. These program line tools have varied applications in programming, however most significantly they’ll be used for checking the integrity of files.

For example, if you’ve got downloaded associate degree .iso file from associate degree untrusted supply, there’s some likelihood that the file contains harmful scripts. To form positive the .iso is safe, you’ll generate associate degree md5 or alternative hash from it.

md5sum ubuntu-16.04.3-desktop-amd64.iso

0d9fe8e1ea408a5895cbbe3431989295 ubuntu-16.04.3-desktop-amd64.iso

You can then compare the generated string to the one provided from the first author (e.g. UbuntuHashes).

Htop

Htop could be a a lot of powerful different to the intrinsic prime task manager. It provides a complicated interface with several choices for observation and dominant system processes.

Although it runs within the terminal, htop has excellent support for mouse controls. This makes it a lot of easier to navigate the menus, choose processes, and organize the tasks thought sorting and filtering.

 

Ln

Links in UNIX operating system square measure the same as shortcuts in Windows, permitting you to urge fast access to bound files. Links square measure created via the ln command and might be 2 types: arduous or symbolic. Every kind has totally different properties and is employed for various things (read more).

Here is associate example of 1 of the various ways that you’ll be able to use links. as an instance we’ve a directory on our desktop referred to as Scripts. It contains showing neatness organized bash scripts that we have a tendency to ordinarily use. on every occasion we wish to decision one in every of our scripts we’d need to do this:

~/Desktop/Scripts/git-scripts/git-cleanup

Obviously, this is isn’t very convinient as we have to write the absolute path every time. Instead we can create a symlink from our Scripts folder to /usr/local/bin, which will make the scripts executable from all directories.

sudo ln -s ~/Desktop/Scripts/git-scripts/git-cleanup /usr/local/bin/

With the created symlink we can now call our script by simply writing its name in any opened terminal.

git-cleanup

SSH

With the ssh command users will quickly hook up with a foreign host and log into its UNIX operating system shell. This makes it doable to handily issue commands on the server directly from your native machine’s terminal.

To establish a association you just got to specify the proper science address or URL. The primary time you hook up with a replacement server there’ll be some style of authentication.

ssh username@remote_host

If you want to quickly execute a command on the server without logging in, you can simply add a command after the url. The command will run on the server and the result from it will be returned.

ssh username@remote_host ls /var/www


some-website.com
some-other-website.com

There is a lot you can do with SSH like creating proxies and tunnels, securing your connection with private keys, transferring files and more.

Grep

Grep is the standard Unix utility for finding strings inside text. It takes an input in the form of a file or direct stream, runs its content through a regular expression, and returns all the matching lines.

This command comes in handy once operating with massive files that require to be filtered. Below we tend to use grep together with the date command to look through an oversized log file and generate a brand new file containing solely errors from nowadays.

// Search for today’s date (in format yyyy-mm-dd) and write the results to a new file.
grep “$(date +”%Y-%m-%d”)” all-errors-ever.log > today-errors.log

Another nice command for operating with strings is sed. It’s additional powerful (and additional complicated) than grep and may perform nearly any string-related task together with adding, removing or replacement strings.

Alias

Many OS commands, together with some featured during this article, tend to urge pretty long when you add all the choices to them. to create them easier to recollect, you’ll produce short aliases with the alias bash inbuilt command:

# Create an alias for starting a local web server.
alias server=”python -m SimpleHTTPServer 9000″

# Instead of typing the whole command simply use the alias.
server

Serving HTTP on 0.0.0.0 port 9000 …

The alias are offered as long as you retain that terminal open. to create it permanent you’ll add the alias command to your .bashrc file.

We will be happy to answer your questions on designing, developing, and deploying comprehensive enterprise web, mobile apps and customized software solutions that best fit your organization needs.

As a reputed Software Solutions Developer we have expertise in providing dedicated remote and outsourced technical resources for software services at very nominal cost. Besides experts in full stacks We also build web solutions, mobile apps and work on system integration, performance enhancement, cloud migrations and big data analytics. Don’t hesitate to get in touch with us!

Leave a Reply

Your email address will not be published. Required fields are marked *