Linux Command Lines: Questions and Answers

Question 1:

How to move a list of files matching a certain regular expression to a specific folder?

ls | grep '^[0-9][0-9]\.4' | xargs {} mv {} some_folder

Question 2:

How to combine the contents of multiple files into a single file?

cat file1 file2 file3 >> bigfile

Question 3:

How to search for files matching a pattern at a certain folder recursively?

find /opt -name *.tar.gz


How to count the number of files present in a particular directory?

ls -l | grep '^-' | wc -l

One Minute Tutorial To Getting Started With VIM

Since you are here, you may already know what vim is. But, just in case you are not aware of it, it is a very  popular text editor that comes in really handy when working with text files in Linux.  If you don't want to know all the nitty-gritty details of vim and you are just looking for the bare minimums so you can actually start typing in vim, spare a minute of your life and read the rest.

One thing that you absolutely need to know about vim is that it has two modes: 'command' mode and the 'type' mode. When you are in the command mode, you can give commands to vim to do something for you. When you are in the 'type' mode, you just add texts to your file. When you first start a file with vim, it defaults to the neither of these modes which means you won't be able to type anything or give any command. If you want to type something, you have to change the mode to 'type' and similarly if you want give a command you need to change the mode to 'command'. And to exit a mode, you press 'esc' in your keyboard.

Pressing 'i' on your keyboard changes to 'type' mode and pressing 'esc' on your keyboard exits the 'type'. Pressing ':' on your keyboard changes to 'command' mode and pressing 'esc' exits the command mode. This is how you go back and forth between 'type' and 'command' mode.

Editing a vim file is just usual typing with the help of your keyboard. There is not much to it. There are a lot of commands that are available in vim that may be very useful but since this is an extremely brief introduction to vim, the only two commands you will need to get you typing are:

:q       quite vim

:w       save the file

:wq      save and quit the file

So now, fire up your Linux machine and practice what you just read. For example: <br>

Step 1: Create a test file

vim text.txt[If the file is not present in the directory, vim will create a new file, and if the file is present in the directory it will open the file]

Step 2: Type something. Remember you have to change the mode to 'type' mode by pressing 'i' on your keyboard before you can type anything.

Press i

Step 3: Save and quit the file

Press esc to exit 'type' mode

Press : to enter command mode

Type wq and press enter

Further reading to learn more useful commands:

vim commands cheat sheet