Codementor Events

Must-Know Linux commands - productivity hack

Published Feb 14, 2025
Must-Know Linux commands - productivity hack

As a developer, I prefer Linux over other operation systems. These commands are my secret weapons for maximizing productivity. And maybe even introduce you to some new ways of thinking about how you interact with your system.

Download files from online source

Eventually we have to download a file from Internet. I hope we all see a download page that looks like these.

Screenshot 2025-02-13 at 9.42.01 PM.png
Screenshot 2025-02-13 at 9.41.47 PM.png

Do you notice the checksums they share for each file, and what do you usually do?
I used to ignore the checksum, because I don't know how important it is.
Someone can hack the website, put a malware file to replace the original file. This happens before with a linux distribution called Linux Mint.

Since I knew this security issue, I started using this command to generate the checksum for any file I download from Internet

$ shasum -a 256 ruby_source.tar.gz
136490b8115951c556980f0e05c14d5918407a32f53d8bfca4bbe9449443dfd7  ruby_source.tar.gz

By compare this checksum string (SHA256) with the string posted in the website, I can rest asure that the file I have is safe to use.

Create files and directories

Create files and directories is a common task. I believe everyone knows the command touch and mkdir for this purpose. But do you know with the option -p will allow the mkdir creating the non-existing middle layer directory. From the command's man page, it describes:

$ mkdir -p cow/horse/monkey
Create a directory named cow/horse/monkey, creating any non-existent intermediate directories as necessary

If the horse directory doesn't exist, it will create the horse before monkey, without the parameter -p, the mkdir returns an error code instead.

$ mkdir cow/horse/monkey
mkdir: cow/horse: No such file or directory

Create many files with the same pattern

For example, you need to create 1000 files with filename following log_20250212_001.log, log_20250212_002.log, ..., log_20250212_1000.log. There are a few ways to do so without typing the command 1000 times. However, I believe the simpliest solution is

$ touch files/log_20250212_{001..1000}.log

Sync files between 2 machines

Rsync is a powerful command to sync data. I have 2 laptops, and I often have to sync the data between 2 laptops. An option is to use git, but I don't like the idea to push the local data to Github as I want to sync the credential information as well (good practice: don't push any credential file to Github). Rsync is the command I use for this purpose:

$ rsync -cav --exclude=node_modules --exclude=target ~/my_works kvin@archcraft:/home/kvin/backup

This blog post is the easiest way to learn about rsync command imo.

Create a local git

Github is the one of the online storage for source code. The free plan is extremely generous. However, I am paranoid that they could use my code to train their bots. If you do some fun/experiment code, you may not want to push these project to Github. If you have a spare server, or even in the same machine, you can config a git remote to push your code to.

$ git init --bare

After this step, you can set the remote URL for your project to the path of this local remote as follow

$ git remote add origin /tmp/remote

NOTE: Don't use tmp like this example, the data in this tmp directory is clean up eventually by the OS.

Recap

In this post, I have share a few Linus commands that I'm using intensively for my daily work. I hope you found some of these helpful! There are, of course, many more out there, but these are the ones I find very interestingly useful. What are your favorite Linux commands? Share them in the comments!

Discover and read more posts from K'vin
get started