Pages

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

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.



Using WATCH command to see the updating files

To see the end of the file, we often use tail -n5 or tail (for 10 lines by default). When the file is in progress, we may want to keep on watching the end of the file. This can be done using WATCH command.

The use is as follow:

watch tail -n 12 filename.out
watch -n 2 tail -n 12 filename.out (to see last 12 lines and update every 2 seconds)
watch -n 5 tail -n 12 filename.out (to see last 12 lines and update every 5 seconds)



Commonly used Unix/Linux commands

Here are the mostly used command in command line. To see more details, click on each commad.
ls
grep
alias
reverse search
tab completion
disk space (du, df and quoto)
exctract files
compiling source code (configure, make and make install)
downloading link (wget and git clone)
editors (vim, emacs, atom, visual code, etc)
file conversion



ctrl C interrupts whatever is currently running.  (to come out if anything went wrong)
ctrl Z to put a foreground process into the background.
ctrl S suspends current terminal
ctrl Q resumes current terminal




Following passage is taken from Stanford's Micro and Nano Mechanics Group.
Here is a list of commands from wiki for UNIX/LINUX.

Check the size of the directory and file (and see the largest in terms of memory)

The command du can be used to check the space (disk usage)
To see the disk space
du -sh * 

To see the disk space and sort it
du -sh * | sort -nr 

To see the disk space and see the top 10 files 
du -sh * | sort -nr | head -n10

To see the disk space and see the top 10 files 
du -sh * | sort -nr | tail -n10

Explanation:

du -s *: Summarizes disk usage of all files
sort -nr: To sort numerically, in reverse order
head -n10: Display first 10 results
tail -n10: Displays last 10 results
h : For human-readable output

To list the top 10 largest files from the current directory, use the following command:
du . | sort -nr | head -n10
du -h . | sort -nr | head -n10 (human readable output)
du, sort -nr and head -n10 serves the same purpose.


To check the diskspace with the control of number of recursive directories.

du -h --max-depth=0 | sort -hr   (only current directory)

du -h --max-depth=1 | sort -hr   (Current directory and one directory depth)


Check free memory in the cluster/supercomputer/linux system


Try:
free -g    (to display the free disk size in GB)

You will get like this.

              total        used        free      shared  buff/cache   available
Mem:              7           6           0           0           1           0

Swap:             7           2           5

Options:
 -b, --bytes       show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega      show output in megabytes
 -g, --giga          show output in gigabytes
       --tera          show output in terabytes
 -h, --human    show human-readable output
       --si              use powers of 1000 not 1024
 -l, --lohi           show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds
 -c N, --count N     repeat printing N times, then exit
 -w, --wide          wide output

 --help     display this help and exit
 -V or --version  output version information and exit

This is a series of post on "High Performance Computing (HPC): Everything you need to know before working in a Linux Cluster Environment. To see more post on this series, click here: Important Things to Know to Work in Linux Cluster

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