I was going through the split command article on internet and came across this Linux command ls -lh | tail -n +2 for listing files. Is it any better than ls -ltrh (which shows almost the same listing)
Can somebody plz tell me the difference between ls -lh & ls -lh | tail -n +2
PS: I have checked man pages but still confused
22 Answers
tail -n +2 skips the first line (total file size).
$ ls -lh
total 79K
drwxr-xr-x 2 root root 4.0K Feb 28 15:05 bin
drwxr-xr-x 4 root root 3.0K Feb 28 15:05 boot
drwxr-xr-x 16 root root 4.3K Dec 3 06:43 dev
drwxr-xr-x 112 root root 4.0K Feb 28 15:06 etc
drwxr-xr-x 3 root root 4.0K Aug 29 2012 home $ ls -lh | tail -n +2
drwxr-xr-x 2 root root 4.0K Feb 28 15:05 bin
drwxr-xr-x 4 root root 3.0K Feb 28 15:05 boot
drwxr-xr-x 16 root root 4.3K Dec 3 06:43 dev
drwxr-xr-x 112 root root 4.0K Feb 28 15:06 etc
drwxr-xr-x 3 root root 4.0K Aug 29 2012 homeIt is better if there's some further processing that expects just the listing.
ls -dlh * will do the same thing.
ls -lh list all content. but ls -lh|tail -n +K, skip the first n - K line from first and list all remaining lines. Like
$ 6:18:39% ls -lh ~/logs
total 264K
-rw-rw-r-- 1 vijay vijay 76K Oct 27 17:13 angular-ui-bootstrap-0.4.0.jar
-rw-rw-r-- 1 vijay vijay 70K Feb 14 16:52 cloudbash_importdata
-rwxrwxr-x 1 vijay vijay 86 Feb 14 16:38 findjar.sh
drwxr-xr-x 4 vijay vijay 4.0K Jun 26 2013 META-INF
-rw-r--r-- 1 www-data root 87K Feb 28 18:13 nginx_access.log
-rw-r--r-- 1 www-data root 12K Feb 28 18:13 nginx_error.log
-rw-rw-r-- 1 vijay vijay 310 Feb 14 20:19 onlyimport $ 6:18:51% ls -lh ~/logs |tail -n +3
-rw-rw-r-- 1 vijay vijay 70K Feb 14 16:52 cloudbash_importdata
-rwxrwxr-x 1 vijay vijay 86 Feb 14 16:38 findjar.sh
drwxr-xr-x 4 vijay vijay 4.0K Jun 26 2013 META-INF
-rw-r--r-- 1 www-data root 87K Feb 28 18:13 nginx_access.log
-rw-r--r-- 1 www-data root 12K Feb 28 18:13 nginx_error.log
-rw-rw-r-- 1 vijay vijay 310 Feb 14 20:19 onlyimport $ 6:19:05% ls -lh ~/logs |tail -n +4
-rwxrwxr-x 1 vijay vijay 86 Feb 14 16:38 findjar.sh
drwxr-xr-x 4 vijay vijay 4.0K Jun 26 2013 META-INF
-rw-r--r-- 1 www-data root 87K Feb 28 18:13 nginx_access.log
-rw-r--r-- 1 www-data root 12K Feb 28 18:13 nginx_error.log
-rw-rw-r-- 1 vijay vijay 310 Feb 14 20:19 onlyimport