When I started learning linux ,for listing files and directory I firsts learnt the command ls.
ls command is widely in linux and Unix like operating system.It is a system command which by default shipped with operating system.Today I am sharing the 4 commands by which you can list file and directories.On other hand you can also say alternate of ls commands.
Note: ls commands has many flags and it make the ls command very strong and useful.The given below information is for reference to understand other options available instead of ls command.
To list files and directories below given command can be used
(1) ls : list directory contents and bydefault do listing in alphabetical order.It is preferred to use ls command and is available in all linux and Unix like operating system.
example:
list the file (simply using ls command ,no flag is used)
linux@tuxworld:/tmp$ ls CRX_75DAF8CB7768 pulse-2L9K88eMlGn7 qtsingleapp-smplay-ca73-3ea-lockfile unity_support_test.0 orbit-linux pulse-NlEgkniQzH6U ssh-jILc18mdYgH9 plugtmp pulse-PKdhtXMmr18n tmpMUt_t8 linux@tuxworld:/tmp$
list the file and dir along with information (Using -l option)
linux@tuxworld:/tmp$ ls -l total 28 drwx------ 2 linux linux 4096 Sep 9 08:59 CRX_75DAF8CB7768 drwx------ 2 linux linux 4096 Jan 1 1970 orbit-linux drwx------ 2 linux linux 4096 Sep 8 19:02 plugtmp drwx------ 2 lightdm lightdm 4096 Sep 4 08:36 pulse-2L9K88eMlGn7 drwx------ 2 linux linux 4096 Sep 4 08:36 pulse-NlEgkniQzH6U drwx------ 2 root root 4096 Sep 4 08:36 pulse-PKdhtXMmr18n -rw-rw-r-- 1 linux linux 0 Sep 7 08:49 qtsingleapp-smplay-ca73-3ea-lockfile drwx------ 2 linux linux 4096 Sep 4 08:36 ssh-jILc18mdYgH9 -rw------- 1 linux linux 0 Sep 4 08:36 tmpMUt_t8 -rw-rw-r-- 1 linux linux 0 Sep 4 08:36 unity_support_test.0 linux@tuxworld:/tmp$
list ALL file and dir as well as hidden files (hidden files name start with dot example .testfile)
linux@tuxworld:/tmp$ ls -la total 76 drwxrwxrwt 15 root root 16384 Sep 9 12:01 . drwxr-xr-x 27 root root 4096 Jul 21 19:25 .. drwx------ 2 linux linux 4096 Sep 8 19:08 .com.google.Chrome.tR19ls drwx------ 2 linux linux 4096 Sep 9 08:59 CRX_75DAF8CB7768 drwx------ 2 linux linux 4096 Sep 4 08:36 .esd-1002 drwx------ 2 lightdm lightdm 4096 Sep 4 08:36 .esd-104 drwxrwxrwt 2 root root 4096 Sep 4 08:36 .ICE-unix drwx------ 2 linux linux 4096 Jan 1 1970 orbit-linux drwx------ 2 linux linux 4096 Sep 8 19:02 plugtmp drwx------ 2 lightdm lightdm 4096 Sep 4 08:36 pulse-2L9K88eMlGn7 drwx------ 2 linux linux 4096 Sep 4 08:36 pulse-NlEgkniQzH6U drwx------ 2 root root 4096 Sep 4 08:36 pulse-PKdhtXMmr18n -rw-rw-r-- 1 linux linux 0 Sep 7 08:49 qtsingleapp-smplay-ca73-3ea-lockfile drwx------ 2 linux linux 4096 Sep 4 08:36 ssh-jILc18mdYgH9 -rw-rw-r-- 1 linux linux 0 Sep 9 12:01 .testfile -rw------- 1 linux linux 0 Sep 4 08:36 tmpMUt_t8 -rw-rw-r-- 1 linux linux 0 Sep 4 08:36 unity_support_test.0 drwx------ 2 linux linux 4096 Sep 7 08:03 .vbox-linux-ipc -r--r--r-- 1 root root 11 Sep 4 08:36 .X0-lock drwxrwxrwt 2 root root 4096 Sep 4 08:36 .X11-unix linux@tuxworld:/tmp$
(2) dir: Similar to DOS version, dir command is also available in Linux and Unix like O.S. Almost similar to ls command
examples:
list file and directory
linux@tuxworld:/tmp$ dir CRX_75DAF8CB7768 pulse-2L9K88eMlGn7 qtsingleapp-smplay-ca73-3ea-lockfile unity_support_test.0 orbit-linux pulse-NlEgkniQzH6U ssh-jILc18mdYgH9 plugtmp pulse-PKdhtXMmr18n tmpMUt_t8 linux@tuxworld:/tmp$
list files and directory with information
linux@tuxworld:/tmp$ dir -l
total 28
drwx—— 2 linux linux 4096 Sep 9 08:59 CRX_75DAF8CB7768
drwx—— 2 linux linux 4096 Jan 1 1970 orbit-linux
drwx—— 2 linux linux 4096 Sep 8 19:02 plugtmp
drwx—— 2 lightdm lightdm 4096 Sep 4 08:36 pulse-2L9K88eMlGn7
drwx—— 2 linux linux 4096 Sep 4 08:36 pulse-NlEgkniQzH6U
drwx—— 2 root root 4096 Sep 4 08:36 pulse-PKdhtXMmr18n
-rw-rw-r– 1 linux linux 0 Sep 7 08:49 qtsingleapp-smplay-ca73-3ea-lockfile
drwx—— 2 linux linux 4096 Sep 4 08:36 ssh-jILc18mdYgH9
-rw——- 1 linux linux 0 Sep 4 08:36 tmpMUt_t8
-rw-rw-r– 1 linux linux 0 Sep 4 08:36 unity_support_test.0
linux@tuxworld:/tmp$
list ALL files and directory with all info(including hidden files and dir)
linux@tuxworld:/tmp$ dir -la total 76 drwxrwxrwt 15 root root 16384 Sep 9 12:05 . drwxr-xr-x 27 root root 4096 Jul 21 19:25 .. drwx------ 2 linux linux 4096 Sep 8 19:08 .com.google.Chrome.tR19ls drwx------ 2 linux linux 4096 Sep 9 08:59 CRX_75DAF8CB7768 drwx------ 2 linux linux 4096 Sep 4 08:36 .esd-1002 drwx------ 2 lightdm lightdm 4096 Sep 4 08:36 .esd-104 drwxrwxrwt 2 root root 4096 Sep 4 08:36 .ICE-unix drwx------ 2 linux linux 4096 Jan 1 1970 orbit-linux drwx------ 2 linux linux 4096 Sep 8 19:02 plugtmp drwx------ 2 lightdm lightdm 4096 Sep 4 08:36 pulse-2L9K88eMlGn7 drwx------ 2 linux linux 4096 Sep 4 08:36 pulse-NlEgkniQzH6U drwx------ 2 root root 4096 Sep 4 08:36 pulse-PKdhtXMmr18n -rw-rw-r-- 1 linux linux 0 Sep 7 08:49 qtsingleapp-smplay-ca73-3ea-lockfile drwx------ 2 linux linux 4096 Sep 4 08:36 ssh-jILc18mdYgH9 -rw-rw-r-- 1 linux linux 0 Sep 9 12:01 .testfile -rw------- 1 linux linux 0 Sep 4 08:36 tmpMUt_t8 -rw-rw-r-- 1 linux linux 0 Sep 4 08:36 unity_support_test.0 drwx------ 2 linux linux 4096 Sep 7 08:03 .vbox-linux-ipc -r--r--r-- 1 root root 11 Sep 4 08:36 .X0-lock drwxrwxrwt 2 root root 4096 Sep 4 08:36 .X11-unix linux@tuxworld:/tmp$
(3) printf : printf command is used for formatted output but by using switches it can list the directories and files
example:
list the files and dir horizontally
linux@tuxworld:/tmp$ printf "%s" * CRX_75DAF8CB7768orbit-linuxplugtmppulse-2L9K88eMlGn7pulse-NlEgkniQzH6Upulse-PKdhtXMmr18nqtsingleapp-smplay-ca73-3ea-lockfilessh-jILc18mdYgH9tmpMUt_t8unity_support_test.0linux@tuxworld:/tmp$ linux@tuxworld:/tmp$
list the files and dir vertically by using n (new line)
linux@tuxworld:/tmp$ printf "%s n" * CRX_75DAF8CB7768 orbit-linux plugtmp pulse-2L9K88eMlGn7 pulse-NlEgkniQzH6U pulse-PKdhtXMmr18n qtsingleapp-smplay-ca73-3ea-lockfile ssh-jILc18mdYgH9 tmpMUt_t8 unity_support_test.0 linux@tuxworld:/tmp$
list files and directory including hidden files
linux@tuxworld:/tmp$ printf "%s n" * .* CRX_75DAF8CB7768 orbit-linux plugtmp pulse-2L9K88eMlGn7 pulse-NlEgkniQzH6U pulse-PKdhtXMmr18n qtsingleapp-smplay-ca73-3ea-lockfile ssh-jILc18mdYgH9 tmpMUt_t8 unity_support_test.0 . .. .com.google.Chrome.tR19ls .esd-1002 .esd-104 .ICE-unix .testfile .vbox-linux-ipc .X0-lock .X11-unix linux@tuxworld:/tmp$
(4) echo: echo is used to display line of contents.
list files and dir
linux@tuxworld:/tmp$ echo * CRX_75DAF8CB7768 orbit-linux plugtmp pulse-2L9K88eMlGn7 pulse-NlEgkniQzH6U pulse-PKdhtXMmr18n qtsingleapp-smplay-ca73-3ea-lockfile ssh-jILc18mdYgH9 tmpMUt_t8 unity_support_test.0 linux@tuxworld:/tmp$
list files and dir (including hidden)
linux@tuxworld:/tmp$ echo * .* CRX_75DAF8CB7768 orbit-linux plugtmp pulse-2L9K88eMlGn7 pulse-NlEgkniQzH6U pulse-PKdhtXMmr18n qtsingleapp-smplay-ca73-3ea-lockfile ssh-jILc18mdYgH9 tmpMUt_t8 unity_support_test.0 . .. .com.google.Chrome.tR19ls .esd-1002 .esd-104 .ICE-unix .testfile .vbox-linux-ipc .X0-lock .X11-unix linux@tuxworld:/tmp$