Ls & find Flashcards

1
Q

To show files sorted by modification time

A

ls -t

or

ls -lt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

To show files as single entry per line like

bin
boot
cdrom
dev
etc
home
initrd
initrd.img
lib
A

$ ls -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what info shows ls -l

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Order Files Based on Last Modified Time (In Reverse Order)

A

ls -ltr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

ls -a

s -A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Display Files Recursively

A

ls -R

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Display File Inode Number

A

ls -i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Display File UID and GID

A

ls -n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Visual Classification of Files With Special Characters

A

ls -F

/ – directory.
nothing – normal file.
@ – link file.
* – Executable file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
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
A

find -iname “MyCProgram.c”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

find / -name passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Find the passwd file under root and one level down. (i.e root — level 1, and one sub-directory — level 2)

A

find -maxdepth 2 -name passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Find the password file between sub-directory level 2 and 4.

A

find -mindepth 3 -maxdepth 5 -name passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Shows the files or directories whose name are not MyCProgram.c .Since the maxdepth is 1, this will look only under current directory.

A

find -maxdepth 1 -not -iname “MyCProgram.c”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Find files which has read permission to group

A

find . -perm -g=r -type f -exec ls -l {} \;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Find all empty files (zero byte file) in your home directory and its subdirectory

A

find ~ -empty

17
Q

List all the empty files only in your home directory

A

find . -maxdepth 1 -empty

18
Q

Finding the Top 5 Big Files

A

find . -type f -exec ls -s {} \; | sort -n -r | head -5

19
Q

Finding the Top 5 Small Files

A

find . -type f -exec ls -s {} \; | sort -n | head -5