Knowledgebase

How to list and view details about files and folders via SSH

If you want to see such details as permissions, size, date of last modification of a file or folder on your hosting account, you can do it with the ls SSH command. If you execute just the ls command without any options, it will display the files and folders in the current working directory (folders are colored in blue by default). You won't see any additional details about the files and folders, just their names. To view more details use the -l option. For example:

ls -l

will list the files and folders in the current working directory, but each file and folder will be shown together with its size, permissions, time and date of last modification, owner and group. For example, the output will look something like this:


drwxr-xr-x  3 owner group 21401600 2012-03-23 09:54 example dir1
drwxr-xr-x  5 owner group        4096 2012-04-08 10:04 example_folder
drwxr-xr-x  2 owner group       4096 2012-03-30 03:09 exampledir2
drwxr-xr-x  2 owner group       4096 2012-03-30 04:00 exampledir3
-rw-r--r--   1 owner group       5689 2012-04-08 10:14 example.php
-rw-r--r--   1 owner group          53 2012-04-06 07:47 file.txt

First you'll see indicated whether the item is a directory or file (d for directory, - for file), followed immediately by the permissions for that file or folder. Then the owner and the group are listed; on your account these would be replaced with your actual master username. What follows is the size of the file/folder in bytes, then the date and time of the last modification performed to the file/folder, and finally the name. For instance, the last item in the above example list is a file named file.txt that is 53 bytes in size. Its permissions are rw-r--r-- (644), and it was last modified at the specified time and date.

If you want the size to be easier to understand (useful with larger directories and files), you can use the -h option. For example, if we execute the command ls -lh in the same current working directory, the output would look like this:


drwxr-xr-x  3 owner group  21M 2012-03-23 09:54 example dir1
drwxr-xr-x  5 owner group 4.0K 2012-04-08 10:04 example_folder
drwxr-xr-x  2 owner group 4.0K 2012-03-30 03:09 exampledir2
drwxr-xr-x  2 owner group 4.0K 2012-03-30 04:00 exampledir3
-rw-r--r--   1 owner group 5.6K 2012-04-08 10:14 example.php
-rw-r--r--   1 owner group   53 2012-04-06 07:47 file.txt 

In this case M stands for megabytes and K for kilobytes. If you want files that begin with a dot (like .htaccess files) also to be listed, use the -a option (e.g. ls -lha). In case you want to view the details just of a single file, type the name of the file after the command. For example:

ls -l file.txt

will show details about a file called file.txt that's in the current working directory. You can also list several files (e.g. ls -l file.txt example.php).

Was this answer helpful?

 Print this Article

Also Read