Categories
Tools

Useful Linux Commands — Network and Compression

Spread the love

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.

export

The export command let us export variables to child processes.

For instance, we run:

export TEST="test"

to set the TEST variable to 'test' .

We can also reference another variable by using the $ in the expression on the right side.

For example, we run:

export PATH=$PATH:/new/path

to reference the existing value of the PATH environment variable on the right side.

tar

We can run the tar command to archive files.

To create a tar archive, we run:

tar -cf archive.tar file1 file2

to create a tar archive with the file1 and file2 files in the tar archive.

We can extract files from an archive in the current folder by running:

tar -xf archive.tar

And we can extract an archive into a specific directory with:

tar -xf archive.tar -C dir

x stands for extract and f means write files.

c means create.

The z option lets us create a gzip archive.

For instance, we run:

tar -czf archive.tar.gz file1 file2

to create a gzip archive with file1 and file2 inside.

And we can gunzip a gzip archive with:

tar -xf archive.tar.gz

traceroute

The traceroute command lists all the nodes traversed to reach a host.

For instance, we run:

traceroute google.com

to see where the packets go to reach Google.

ping

The ping command lets us ping a network host to see if it responds.

For instance, we run:

ping google.com

to see if Google is up.

We can continually ping it with the -c switch:

ping -c google.com

It stops pinging only when we press ctrl+c.

gunzip

The gunzip command lets us unzip a zip archive.

For instance, we can run:

gunzip filename.gz

to extract the files in the filename.gz file.

We can use the -c switch extract a file to a different filename:

gunzip -c filename.gz > bar

Then we extract filename.gz to the bar file.

gzip

The gzip command lets us create a compressed file.

For instance, we run:

gzip filename

to compress the filename file.

We can rename the gzipped file with the -c switch:

gzip -c filename > filename.gz

Then we compress the file into the filename.gz file.

The -k option also lets us change the name of the compressed file:

gzip -k filename

We can set the compression level with the -<number> switch.

For instance, we run:

gzip -1 filename

to compress filename with level 1 compression.

We can compress multiple file by adding the file names separated with spaces:

gzip file1 file2

We compress file1 and file2 with one gzip command.

Also, we can compress all files in a directory recursively with the -r switch:

gzip -r folder

The -v switch prints the compression percentage info.

The -d switch decompresses a file:

gzip -d filename.gz

Conclusion

We can compress files and folders, and do basic network tasks with some basic Linux commands.

Leave a Reply

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