Thursday, June 11, 2015

Files and folders with ls

This article aims at deep insight of file listing command in Linux with relevant examples.

$ls
$echo *

above commands will list the files and folders

$echo */

will list only directories

list all the files within a directory including hidden files aka (.) dot files

# ls -a

 list all the files within a directory including hidden files, but do not list implied ‘.’ and ‘..’

#ls -A

Print the content of a directory in long format listing

#ls -l

Example:

drwxr-xr-x  5 muthu linuxinterest      4096 Sep 30 11:31 Binary

Here, drwxr-xr-x is file permission for owner, group and world. Owner has Read(r), Write(w) and Execute(x) permission. The group to which this file belongs has Read(r) and Execute(x) permission but not Write(w) permission, same permission implies for the world that have access to this file.

The Initial ‘d‘ means its a Directory.
Number ‘5‘ represents Symbolic Link.
The File Binary belongs to user muthu and group linuxinterest      .
Sep 30 11:31 represents the date and time it was last modified

print the content of directory in long format listing, showing hidden/dot files

#ls -la

Setting up the alias for 'ls -l' as 'll'

Add alias ll='ls -l'to .bashrc

logout and login then try by issueing the commad ll

listing the name of the files without the name of its owner, when used with switch (-g)

#ls -g

listing the name of files in long listing format without the name of group it belongs, when used with switch (-G) along with switch (-l).

#ls -Gl

Print the size of files and folders in the current directory, in human readable format

#ls -hl or #ls -hs (small h and small s)

if switch (-h) output size in power of 1024, that is standard, What else power values are supported in ls command

There exist a switch -si which is similar to switch -h. The only difference is switch -si uses power of 1000 unlike switch -h which uses the power of 1024.

#ls -si

print the contents of a directory separated with comma

#ls -m

Example:

 muthu, kumar, linux, test

Print the contect in reverse order

#ls -rl

print the sub-directories recursively

#ls -R

sort the files based upon the size

#ls -S

To sort the files based upon size in descending order with the smallest file listed at first and largest at last

#ls -Sr

 List the contents of a directory with no additional information appearing one file per line

acheieved this by using one 1

#ls -l

Example:

muthu
kumar
test
linux

No comments:

Post a Comment