In
Now lets say you want to get count of files which is listed by
Now you shoud the count of files listed by the first command. This method of using 2 commands is
#linux #sysadmin #ls #wc #command #bash #terminal
ls
you can list files by using regex pattern as below:ls data.subtitle_*
*
is gready and list all the files that start with data.subtitle_
.Now lets say you want to get count of files which is listed by
ls
command. For that you can use wc -l
as follow:ls data.subtitle_* | wc -l
Now you shoud the count of files listed by the first command. This method of using 2 commands is
piping commands
, which is in fact separated by |
(pipe)#linux #sysadmin #ls #wc #command #bash #terminal
1. List all Open Files with lsof Command
> lsof
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 253,0 4096 2 /
init 1 root rtd DIR 253,0 4096 2 /
init 1 root txt REG 253,0 145180 147164 /sbin/init
init 1 root mem REG 253,0 1889704 190149 /lib/libc-2.12.so
FD
column stands for File Descriptor
, This column values are as below:-
cwd
current working directory-
rtd
root directory-
txt
program text (code and data)-
mem
memory-mapped fileTo get the count of open files you can use
wc -l
with lsof
like as follow:lsof | wc -l
2. List User Specific Opened Files
lsof -u alireza
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1838 alireza cwd DIR 253,0 4096 2 /
sshd 1838 alireza rtd DIR 253,0 4096 2 /
#linux #sysadmin #lsof #wc #file_descriptor