Pages

Showing posts with label linux tutorials. Show all posts
Showing posts with label linux tutorials. Show all posts

Using ls command (ls) to sort file names by number.

If you work with a lot of files, you often save the files with numbers for each system.

For example, 

1sample.out
2sample.out
3sample.out
4sample.out
......
......
......
......
10sample.out
11sample.out
12sample.out
.......
.......
Nsample.out

Suppose, you want to extract some information from these files in order from 1sample in order. If you type 'ls', the file 10sample.out will be listed first. You will get list as follow. So the extracted info will be different from what you expect as follow.

10sample.out
11sample.out
12sample.out
...... 
......
15sample.out
1sample.out
2sample.out
.....
.....
Nsample.out

To order file names based on the numbers in the file, use 'ls -v"

Now, the files will be ordered properly.

So, to list the files based on the numbers, use:

ls -v *.out    [to list files with extension .out]

This is a series of post on the "Efficient use of Linux" as well as "Linux Tips for beginners" series. To see all the post, click the link on the right side. 


Using ls command to list all the files in the current directory recursively:

Use:

ls -R

This will list all the files int he current directory recursively.

Accessing Ubuntu Bash files from Windows 10

How to access the files in the Ubuntu Bash update from the Windows 10.

The obvious way is through C:/ folder.

Here is the steps for doing that.

First you need to change the "Hidden folder" default option.
  1. Open File Explorer
  2. Select File --> Change folder and search options
  3. Click on View tab, and select Show hidden files, folders, and drives (if already selected, leave as it is)
  4. Click OK
Now, the hidden folders also will be visible. Remaining steps are
  1. Click on the folder directory address box, copy and paste: %localappdata%\lxss and Enter
  2. Now you will be in Bash directory: C:\Users\{username}\AppData\Local\lxss
  3. Now you can access files in home folder and subfolders.
You can create a Shortcut to this folder (right click on home folder and select create shortcut) and paste the short cut in Desktop or convenient location quick access.


Using Ubuntu Software Center in Windows 10 Ubuntu Bash Terminal

As we know, Windows 10 has optional update for Ubuntu Bash.
But, after installing, it may be efficient if software center is used.
To check if package is available, type:
software-center --version
To open from terminal
software-center
To display a package detail 
software-center <packagename>
To install from terminal
sudo apt-get install software-cente
(approximately, 600 MB of packages will be downloaded and may take few minutes to 10 minutes)

Check if a Python module installed or not

For a beginner, it may be confusing whether a particular module in Python (either 2.* or 3.*). The simple way to check (in terminal is ) to import the module you want.

In the terminal, first go to python2 or python3 prompt. Then import the module you want to check. For example, if I you want to check if Numpy is installed or not, type "import numpy". If installed, the python interpreter will import. Otherwise, error message will be displayed.

Now example.

For python2, try:

~$ python     [in the terminal]
Python 2.7.12 (default, Oct  8 2019 time stamp)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy     [Enter]
>>>
Here note that you get a new >>> prompt and this means that numpy is already installed.

Now, I want to check a module called pythran is installed or not.

~$ python
Python 2.7.12 (default, Oct  8 2019, time stamp)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pythran       [Enter]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pythran' is not defined
>>>
This error means that this particular module is not installed.

We are here to help you what we learn. Comment here if you need any help on this or any question related to this post.



Vim Usage (Linux Tutorial Series - 01)

Vim Usage

Here I describe simple comments related to "vim" editor and its efficient usage.

To start to edit the the file

        vim foo.txt

(I have set an alias for vim as follow: vi='vim'. Because of this alias i can use just "vi" instead of typing "vim". To learn on how to set alias, see this page of the blog)

This will open the file foo.txt if file exist. If the file does not exist, it will open an empty file with the name foo.txt.
To start edit, press 'i' character (which means insert mode)
Now, you are ready to add text and edit the text.


After completing the edit, press 'ESC' key and press ":" and then type 'wq'. This will write and quit the file.

These are the basics in Vim.

I have set alias vi="vim" so that I can can use vi instead of vim.

Now to use Vim efficiently, I use navigation commands often (these also very basic too).

To move line by line (ESC mode).

    k – move upwards
    j – move downwards
    l – move right side
    h – move left side


To move to the particluar line (nth line in ESC mode):

    10k - move 10 line upwards
    10j - move 10 lines downwards
    NG - Go to the Nth line of the file.
    G  - Go to the end of the file.
    gg  - Go to the beginning of the file.


Navigation in a line (ESC mode)

    e – go to the end of the current word.
    b – go to the previous (before) word.
    w – go to the next word.


To navigate through paragraph:

    { – go to the beginning of the current paragraph (press '{' key again to move to previous paragrph) 
    } – go to the end of the current paragraph (press '}' again to move to the end of the next paragraph)

To Search:

    /i – to search the patter (will find the next occurence.)
    * – to go to the next occurrence of the current word under the cursor.

Navigation from Command Line

    vim +N file.txt     - open file.txt and go to the Nth line
    vim +/pattern file.txt - open the file and find the first occurenc of the pattern.


To delete lines (in ESC mode)":

dd - delete the current line
u - undo 

Move to the next/previous black line: Use } and { to move between black lines.

To delete the rest of the line (after the cursor)
Shift + d (or d$)



Delete till a word or character
d/<word>  will do the job.
For example, if I want to delete until the world "end", I would type

:d/end

This would delete all the words/line until the word "end".


If this page is useful, please comment.
You can give your suggestions too to improve the blog.








You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...