Tag Archive for: Bash

How to find where things are installed in Linux?

You just need to use which command, for example lets find the installation path for Node.js

which node

This will return in my case:

/home/myusername/n/bin/node

Best way to install Node.js and NPM

Node.js strongly recommend using a Node version manager like n to install Node.js and npm. They do not recommend using a Node installer, since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally.

Install n directly from Github:

curl -L https://bit.ly/n-install | bash

Then check your versions (remember than node comes with npm)

node --version && npm --version

Note: if you are already having problems, first remove everything related with Node.js and NPM

Resize a bunch of images at the same time using a Bash loop

You can take advantage of Bash and ImageMagick to quickly do processing of many images.

for file in *.jpg; do convert $file -resize 1000 resized-$file; done

But it could be even easier using the command mogrify from the same library:

HOW TO RESIZE MULTIPLE IMAGES AT ONCE

How to copy all your Node projects to your external drive?

Use rsync and exclude node_modules:

rsync -rv --exclude=node_modules my_projects /media/my_name/Seagate\ Expansion\ Drive/

-rv stand for recurse into directories and increase verbosity (see more info while copying)

Renaming Files in a folder to Sequential Numbers with a Prefix

First of all, we have to order our files using ls -v and concatenate them to a standar output with cat -n. From this ouput we read the sequence (n) and the name of each file (f). Finally, we rename the files using mv, adding a prefix and the sequence (n)

ls -v | cat -n | while read n f; do mv "$f" "prefix$n.jpg"; done

If we want to add a zero pad (p) to our sequence (n) we can do it easily with printf.

ls -v | cat -n | while read n f; do printf -v p %03d $n; mv "$f" "prefix$p.jpg"; done