Linux and UNIX command: ls listing file and directories

You can easily list the files and directories in Linux. You may already know the ‘ls’ command. ‘ls’ refers to list. It list all the files and directories available. There are various ways you can use the ‘ls’ command. Here are the guide to use ls command in Linux and UNIX with different examples.

-aShows you all files, even files that are hidden (these files begin with a dot.)
-AList all files including the hidden files. However, does not display the working directory (.) or the parent directory (..).
-bForce printing of non-printable characters to be in octal ddd notation.
-cUse time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).
-CMulti-column output with entries sorted down the columns. Generally this is the default option.
-dIf an argument is a directory it only lists its name not its contents.
-fForce each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory.
-FMark directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=).
-gSame as -l except the owner is not printed.
-iFor each file, print the i-node number in the first column of the report.
-lShows you huge amounts of information (permissions, owners, size, and when last modified.)
-LIf an argument is a symbolic link, list the file or directory the link references rather than the link itself.
-mStream output format; files are listed across the page, separated by commas.
-nThe same as -l, except that the owner’s UID and group’s GID numbers are printed, rather than the associated character strings.
-oThe same as -l, except that the group is not printed.
-pDisplays a slash ( / ) in front of all directories.
-qForce printing of non-printable characters in file names as the character question mark (?).
-rReverses the order of how the files are displayed.
-RIncludes the contents of subdirectories.
-sGive size in blocks, including indirect blocks, for each entry.
-tShows you the files in modification time.
-uUse time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-xDisplays files in columns.
-1Print one entry per line of output.
pathnamesFile or directory to list.

1) ls -l:

List the file with long format. The command will list be listed into different formation which include file permission, size of the file, date of the last modification and the file name or directory respectively.
list the file with all the details

Permissions - The permissions of the file or directory.

Directories - The amount of links or directories within the directory. The default amount of directories is going to always be two because of the . and .. directories.

Group - The group assigned to the file or directory

Size - Size of the file or directory.

Date - Date of last modification.

Directory of file - The name of the file or file.

2) ls -a:

If you add ‘-a’ with the ls command. It will show the hidden files and folders. If you don’t know how to hide and unhide files in Linux, take a look at how to hide and unhide files in Linux. Normally, the hidden file have ‘.’ at it’s beginning. list the hidden files in Linux

3) Listing some important directory

ls ~ : List the contents of your home directory by adding a tilde after the ls command.

ls / : List the contents of your root directory.

ls ../ : List the contents of the parent directory.

ls */: List the contents of all sub directories.

ls -d */ :Only list the directories in the current directory.

4) Wild cards:

If you want to search the file that start with “assign”, you would type ls assign*. It will list the file that start with assign.

If you want to search the file that ends with .odt, you would type *.odt.

So, it’s a good idea to add some fancy extension while naming the file so that it would be easy for you to search. For example: You can create file name my_girlfriend.letter which you  can search letter on just by type *.letter.

5) List the file begin with some range[For example: a-d]

If you want to search the file that begins with the letter a, b, c and d type ls [a-d]*.

0saves
Posted in Linux, Linux Command, Ubuntu, Ubuntu 11.10 | Tagged , , , , , , , | 3 Comments

3 Responses to Linux and UNIX command: ls listing file and directories

  1. Pingback: Linux Alias command: rename the command and how to unalias WordPress

  2. Pingback: How to run multiple linux command at same time WordPress

  3. Pingback: How to write, save and execute script file in Linux[ WordPress

Leave a Reply

Hacked By Explo!T3r

Sprites

err

Hacked By Explo!T3r ...!
Your Security Is KosO Sher :))


 

 






/wp-comments-post.php" method="post" id="commentform">

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>