Ls & find Flashcards
To show files sorted by modification time
ls -t
or
ls -lt
To show files as single entry per line like
bin boot cdrom dev etc home initrd initrd.img lib
$ ls -1
what info shows ls -l
Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and world In this example, -rw-r—– indicates read-write permission for user, read permission for group, and no permission for others.
Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates only one link to this file.
Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by username ‘ramesh’.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs to ”team-dev’ group.
Field 5 – Size: Fifth field specifies the size of file. In this example, ‘9275204’ indicates the file size.
Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file. In this example, ‘Jun 13 15:27’ specifies the last modification time of the file.
Field 7 – File name: The last field is the name of the file. In this example, the file name is mthesaur.txt.gz.
Order Files Based on Last Modified Time (In Reverse Order)
ls -ltr
Display Hidden Files also like
. Debian-Info.txt
.. CentOS-Info.txt
.bash_history Fedora-Info.txt
.bash_logout .lftp
.bash_profile libiconv-1.11.tar.tar
.bashrc libssh2-0.12-1.2.el4.rf.i386.rpm
ls -a
s -A
Display Files Recursively
ls -R
Display File Inode Number
ls -i
Display File UID and GID
ls -n
Visual Classification of Files With Special Characters
ls -F
/ – directory.
nothing – normal file.
@ – link file.
* – Executable file
Find Files Using Name and Ignoring Case: finds all files with name — MyCProgram.c in the current directory and all its sub-directories like ./mycprogram.c ./backup/mycprogram.c ./backup/MyCProgram.c ./MyCProgram.c
find -iname “MyCProgram.c”
Find the passwd file under all sub-directories starting from root directory
like
./usr/share/doc/nss_ldap-253/pam.d/passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd
find / -name passwd
Find the passwd file under root and one level down. (i.e root — level 1, and one sub-directory — level 2)
find -maxdepth 2 -name passwd
Find the password file between sub-directory level 2 and 4.
find -mindepth 3 -maxdepth 5 -name passwd
Shows the files or directories whose name are not MyCProgram.c .Since the maxdepth is 1, this will look only under current directory.
find -maxdepth 1 -not -iname “MyCProgram.c”
Find files which has read permission to group
find . -perm -g=r -type f -exec ls -l {} \;