Pages

Showing posts with label linux. Show all posts
Showing posts with label linux. 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.

configure, make, make install

Most of the linux/unix packages can be installed just by following three simple steps:

"configure, make and make install"

Try:

./configure
make
make install


If you are working in a cluster or workstation where you don't have sudo previleges, you just need to change the configure as follow. Remaining same.

Try:

./configure --prefix=/the/location/where/you/want/to/install/the/package
make
make install


Some codes use make -j . What is that?

Here is the explanation from "man" page of make.

-j [jobs], --jobs[=jobs]
"Specifies  the number of jobs (commands) to run simultaneously.  If there is more than one -j option, the last one is effective.  If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously."

Some other questions about make.

What is the difference between make and make all?

To List of things you need to work on HPC (for researchers)

For learning more, see
Make install but not to default directories
How to build: Configure and make


The 'ls' command in Linux/Unix

The 'ls' command in a Linux system can be used as follows.

To list only the files with no extension
ls !(*.*)              current all the subdirectories
ls -d !(*.*)         only in the current directory
ls -d !(*.tar)         only in the current directory
ls --ignore='*.tar'       without *.tar extension files
ls -I '*.*'
ls | grep -v  "\."      (using grep)

For a comprehensive list of bash commands usage, see here.



Combining PDF - the easiest way in Linux

To combine two or more .PDF files, one can use "pdfunite" application, which is installed in Ubuntu Linux by default.

To combine n number of files,

pdfunite file1.pdf file2.pdf file3.pdf outfile.pdf

Running  this command will combine all the files in to the outfile named outfile.pdf.


Linux tips series

To replace the last command with the same arguments

commandName !*  - for all arguments
commandName !$  - for the last argument
commandName !:N - for the Nth argument



Using grep recursively

grep -r "text_to_grep" .
grep -r --include "*.txt" "text_to_grep" .
grep --include="*.csv" -nRHI "text_to_grep" *


After compiling a code, you may search for the executable (if you have a number of files in that directory). In this case, you can use ls -ltr to list all the files as per the time they are created. For example, see blwo.

gfortran -o code.out code.f90

If you run above line you will get the executable code.out in the same directory. But to look at this file, you can type,

ls -ltr

This will list all the files with code.out at the end of the list. This is a quick check for checking whether the executable is created or not. This will be useful when you teach or create a tutorial on coding.


Use top command to check which jobs are running.
Suppose you submit a job to compute in Linux. If you are not sure whether the job is completed or not, use 'top' command to check.

Type on the terminal
top

Now, you will get list of jobs running on the computer.
Then press 1 to see the latest jobs on top.




Terminal browsers

It would be a challenging task to use only the terminal for browsing through the internet.
Here is the list for Terminal-based browser.
  1. lynx  
  2. w3m 
  3. googler (from Git repository)

The iterm 1 and 2 can be installed using apt-get and the source code for googler may be obtained from Git repository.


What is virtual box?

Virtual box is an application which can be used to operate different operating systems in the same hardware (without rebooting). You can have a number of operating systems, each running different applications.

If we want to test some applications, download and do it in virtual box.

Advantage: 
  • spyware, viruses and malware don't affect the main machine
  • the main would be clean
Presently, Oracle provides popular VirtualBox


Installing FreeDOS in VirtualBox.

Download FreeDOS.iso to your disk.


Jupyter Notebook error: AttributeError: type object 'IOLoop' has no attribute 'initialized'

AttributeError: type object 'IOLoop' has no attribute 'initialized'

This error may be due to the tornado==5.0* versions. Using Tornado 4.5.3 solves the problem.

To do this, try

pip3 uninstall tornado
pip3 install tornado==4.5.3
This solved my problem. Comment if this is useful to you.


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...