Friday, 8 November 2013

ls : List out files

The ls command lists all files in the current directory.

This is the most basic command in UNIX which is used to display what are the files present in the diredtory you are present right now. Meaning changes little bit with various options when combined with ls command.

The syntax for the ls command is:

ls [options] [names]

Options

ls -l

Shows you file information in seven columns:

1.    File type and Permissions: First character specifies file type and the rest 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and others.
      First character represent:
  • -    normal file
  • d    directory
  • s    socket file
  • l     link file
     For example, -rw-r----- indicates it is an ordinary file and having read-write permission for user, read permission for group, and no permission for others.
2.    Links: Second field specifies the number of links for that file. 1 indicates only one link to this file.
3.    Owner: Third field specifies owner name of the file. 
4.    Group: Fourth field specifies the group name of the file. 
5.    Size: Fifth field specifies the size of file.
6.    Last modified date & time: Sixth field specifies the date and time of the last modification of the file.
     For example, ‘Jun 13 15:27′ specifies the last modification time of the file.
7.    File name: The last field is the name of the file. 

ls -x
list all the files in multiple columns, widthwise listing.
ls –a
list out all the files including hidden files along with . (dot) and .. (double dot).
ls -A
list out all the files excluding hidden files along with . (dot) and .. (double dot).
ls -F
list out all the files in such a way that file names end with either / or * or @
/ at the end means directory file
* at the end means executable file
@ at the end means link file
ls –r
list out in reverse order alphabetically or *ASCII collating sequence
ls -R
Recursive order – means list our files from subdirectories also if any.
ls -lS
Decreasing order of their size
ls - t
According to their modification time as newest file first.
ls -i
Shows i-node number of the files
ls – d <dir_name>
List out dir_name if it is a directory.
ls -u
List out according to their access time.
ls -m
List out file names separated by comma.
ls –p
Display direstory with / at the end of filename.
ls -1
ls | paste -
list file names in one column.
ls | paste - - -
list out all files in 3 columns.

2 comments:

  1. ASCII Colating sequence - number first, uppercase alphabet, lowercase alphabet

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete