ADVERTISEMENT

Linux Commands ❯ ls

ls

List information about the files and directories.
syntax:

ls [OPTION]... [FILE]...
  • ls my_dir*
    list the contents of the directories starting with my_dir
  • ls my_file*
    list all the files starting with my_file in the current directory
  • ls -a
    print all the files and directories including the hidden ones starting with dot(.)
  • ls -A
    print all the files and directories including the hidden ones starting with dot(.) except the entries denoting the current directory(.) and parent directory(..)
  • ls -C
    list directory contents in a column format
  • ls -d my_dir*
    list all the directories starting with my_dir but not their contents.
  • ls -d -l */
    list only the directories under the current directory
  • ls -g
    print the entries in the long list format without owner information
  • ls -G -g
    print the entries in the long list format without owner and group information
  • ls -h -l
    list the files and directories with human readable sizes
  • ls -i -l
    list contents of current directory with the index number(inode) for each files and sub directories
  • ls -l
    print the entries in the long list format
  • ls -m
    print the entries in the comma separated format
  • ls -o
    print the entries in the long list format without group information
  • ls -p
    append / indicator to directories
  • ls -p -l | grep -v /
    list only the files under the current directory
  • ls -p -l | grep /
    list only the directories under the current directory
  • ls -R
    List the files and directories in current directory and recursive to the child directories
  • ls -r -Sl
    list the files and directories sorted in the ascending size order
  • ls -S -l
    list the files and directories sorted in the descending size order
  • ls -s
    list the files and directories with the allocated space for each
  • ls -t
    list the files and directories sorted by the modification time.newest appear first.
  • ls -t -r
    list the files and directories sorted by the modification time.oldest appear first.
  • ls -U
    list entries in directory order without any sorting
  • ls -X
    list the files and directories sorted alphabetically by extension