explanation of the convention:
[] : values in square brackets are optional
... : means more elements of that type can be used
ls [option] ... [file] ... - list information about normal [file]s, by default if no options given, you are looking for the file in current directory and sort alphabetically.
for example this will display all files in directory /home/ishtar:
ls /home/ishtar
will show:
bin
Which means that in my home directory I only have one normal (not hidden) directory and no normal files. But really there's more there. For the rest of this entry I am assuming I am in directory /home/isthar so I don't need to specify it next time.Usually you would like to use several basic options for ls command. And there are more, but the most useful I find are those:
list all files but . and .. (these are in all directories and are used by the system, not much use to normal user).
ls -A
and now suddenly my home directory shows:.bash_history bin .fonts .mozilla .vimrc .bashrc .emacs .inputrc .profilebold=directory
.name_of_the_file=hidden file
List files in long format
ls -l
will display:total 4 drwxr-xr-x 2 ishtar users 4096 Feb 17 2014 binyou see here 7 columns, these are:
drwxr-xr-x file type (here d for directory) and permissions for group (3 letters following d) user (next three letters) and everyone else (last three letters) (w=write, x=execute, r=read, -=no rights)
2 number of hard links
ishtar owner name
users group name
4096 size in bytes
Feb 17 2014 timestamp
bin file/directory/link name
The first line that command produces is total 4 and it is showing you the number of 1kB blocks used by the files in the directory, non-recursively.
List files in long format, but do not list owner
ls -g
When listing files in long format, do not list group
ls -G
Sort by file size
ls -S
Sort by modification time
ls -t
Reverse sort order
ls -r
List one file per line
ls -1
Print sizes in human readable format (e.g., 1K 234M 2G), only makes sense if sizes are displayed, so for long formats only -l, -g and -G
ls -h
Do not sort; list entries in directory order. In combination with one_per_line format '-1', it will show files immediately and it has no memory limitations. Very useful if you're listing very large directories!
ls -U
You can use several options at the same time by combining them into a list starting with -, just like this:
ls -GgAh
This will show you long format list of files with no group and no ., .. directories and with sizes in human readable format:
-rw------- 1 53 Nov 7 13:13 .bash_history -rw-r--r-- 1 1.2K Feb 17 2014 .bashrc drwxr-xr-x 2 4.0K Feb 17 2014 bin -rw-r--r-- 1 1.6K Feb 17 2014 .emacs drwxr-xr-x 2 4.0K Feb 17 2014 .fonts -rw-r--r-- 1 861 Feb 17 2014 .inputrc drwxr-xr-x 2 4.0K Feb 17 2014 .mozilla -rw-r--r-- 1 1.1K Feb 17 2014 .profile -rw-r--r-- 1 849 Feb 17 2014 .vimrc
I usually create several aliases in my .bashrc file to speed up traversing through files using the following:
alias la='ls -A' alias ll='ls -lA' alias lbig='ll -Sh' alias lnew='ll -th'to create lbig command to find the biggest files, and lnew to find the newest ones. As you can see it is simple to combine aliases and options too, so in my system this:
lnew -rGwill display files ordered from the oldest to the newest and will not show me file owner group.
No comments:
Post a Comment