Исключить колонки при выводе ls -l с помощью awk

Допустим вам нужно вывести только список содержимого в определенной директории. Для этого достаточно воспользоваться awk.



Обычный вывод
[root@serevr var]# ls -l
total 1866396
-rw-------   1 root root  14728021 Jul 23 03:01 backupctl-billmgr.log
-rw-------   1 root root    384259 Jun 17 17:34 billfix.log
-rw-------   1 root root    215236 May 11  2016 billimport.log
-rw-------   1 root root  18028971 Jul 23 07:45 billmaintain.log
-rw-r--r--   1 root root    780433 Jul 23 07:26 billmgr.auth.log
-rw-r--r--   1 root root      1178 Oct 28  2018 billmgr.gdpr_url
-rw-r--r--   1 root root 459246598 Jul 23 07:45 billmgr.journal
-rw-r--r--   1 root root  92874507 Jul  8 09:44 billmgr.journal.tar.gz
-rw-------   1 root root  16761484 Jul 23 07:46 billmgr.log
-rw-r--r--   1 root root      4721 Jun  7 12:30 billmgr.long.log
-rw-r-----   1 root root         5 Jul 20 23:57 billmgr.pid
-rw-r--r--   1 root root     48922 Mar 10  2017 billmgr.pricelist
-rw-r--r--   1 root root       902 May 17  2016 billmgr.ses
-rw-r--r--   1 root root      3461 Jun 17 17:33 billmgr.version_date.xml
-rw-------   1 root root  13865847 Jul 23 07:00 checkip.log
-rw-------   1 root root      3492 Jul 23 03:51 core_acme_sh.log
-rw-r--r--   1 root root         0 Apr  4  2016 core.auth.log
-rw-r--r--   1 root root   7935854 Jul 23 07:45 core.journal
-rw-------   1 root root  32919151 Jul 23 07:45 core.log
-rw-r--r--   1 root root       100 May  6  2019 core.long.log
-rw-r-----   1 root root         4 Jul 20 02:10 core.pid
-rw-r--r--   1 root root      3696 Jun 17 17:35 core.version_date.xml
-rw-------   1 root root   2376169 Jul 23 06:30 counter.log
drwxr-xr-x   2 root root      4096 Apr 29  2016 dashboard
-rw-r--r--   1 root root         2 Jun 27  2019 expire_logs_value
-rw-------   1 root root       622 Aug  6  2018 fgsmsgate.log
-rw-r--r--   1 root root      1986 Jun 17 17:34 fixlist_billmgr
-rw-r--r--   1 root root       202 May 19 17:35 fixlist_core
-rw-r--r--   1 root root       295 May 19 17:35 fixlist_ipmgr
-rw-------   1 root root   3772102 Jul 23 00:00 globalindex.log
-rw-------   1 root root   3462424 Jul 10 06:23 gwlocalmail.log
-rw-------   1 root root   1177476 Jul 23 07:40 gwremotemail.log
-rw-------   1 root root      1575 Jul 10 06:23 gwsmsc.log
-rw-------   1 root root  93925952 Jul 23 07:46 ihttpd.log
-rw-r-----   1 root root         5 Jul 20 02:06 ihttpd.pid
-rw-r--r--   1 root root      2264 Jul  5 15:13 ipmgr.auth.log
-rw-r--r--   1 root root  35411118 Jul 23 07:45 ipmgr.journal
-rw-------   1 root root  52259386 Jul 23 07:45 ipmgr.log
-rw-r--r--   1 root root       284 Jul 19  2019 ipmgr.long.log
-rw-r-----   1 root root         4 Jul 20 02:10 ipmgr.pid
-rw-r--r--   1 root root       385 Jul  5 15:28 ipmgr.ses
-rw-r--r--   1 root root      2581 Jun 17 17:35 ipmgr.version_date.xml
-rw-------   1 root root  25787711 May 23  2018 ispdns.log
-rw-------   1 root root   9232326 Jul 23 07:45 ispdns_slave.log
-rw-------   1 root root  12982572 Jul 23 07:10 licctl.log
drwxr-xr-x   2 root root     94208 Jul 23 06:55 logs
-rw-------   1 root root  83586265 Jul 23 07:45 longtask.log
-rw-r-----   1 root root  64522122 Jul 23 07:45 longtask.success
-rw-------   1 root root  73493820 Jun 17 17:33 mgrctl.log
-rw-------   1 root root      3509 Mar 25 05:44 mysql.log
-rw-------   1 root root    205720 Jun 17 17:35 mysqlstat.log
-rw-r-----   1 root root         7 Jun 17 17:35 mysqlstat_version
-rw-r--r--   1 root root         0 Feb  7  2017 new_license
drwxr-xr-x  46 root root      4096 Jul 23 05:23 notify
-rw-------   1 root root  72112741 Jul 23 07:46 ntemail.log
-rw-------   1 root root  62344725 Jul 23 07:46 ntinternal.log
-rw-------   1 root root  44881932 Jul 23 07:46 ntsms.log
-rw-r--r--   1 root root       385 Jul 22 18:31 pkgcheck.log
-rw-r--r--   1 root root   4790366 Jul 22 17:31 pkg.log
-rw-------   1 root root      1020 Sep 30  2016 pm2checkout.log
-rw-------   1 root root      7104 Jun 28  2019 pmaspayment.log
-rw-------   1 root root      1000 Sep 30  2016 pmassist.log
-rw-------   1 root root   8834784 Jul 23 04:30 pmauto.log
-rw-------   1 root root  87800934 Jul 23 07:45 pmbillmgr.log
-rw-------   1 root root  41738858 Jul 23 04:31 pmctl.log
-rw-------   1 root root   2328455 Jul 23 04:30 pmdnsmgr.log
-rw-------   1 root root   5836240 Jul 23 05:15 pmipmgr.log
-rw-------   1 root root  61477331 Jul 23 06:56 pmispmgr4.log
-rw-------   1 root root  67747309 Jul 23 07:25 pmispmgr5.log
-rw-------   1 root root      1002 Sep 30  2016 pmliqpay.log
-rw-------   1 root root  11939889 Jul 23 04:30 pmmanual.log
-rw-------   1 root root  86991761 Jul 23 06:40 pmnaunet.log
-rw-------   1 root root   6491210 Jul 23 06:00 pmnic.log
-rw-------   1 root root       990 Sep 30  2016 pmosmp.log
-rw-------   1 root root  33905556 Jun 11 15:26 pmpaymaster.log
-rw-------   1 root root     50539 Jul 20 23:59 pmpaypal.log
-rw-------   1 root root      3455 Jun 11 15:26 pmqiwi.log
-rw-------   1 root root     22823 Jan 27  2017 pmr01.log
-rw-------   1 root root     16249 Jul 20 23:58 pmresellerclub.log
-rw-------   1 root root    581784 Jul 20 23:59 pmrobokassa.log
-rw-------   1 root root    374211 Jul 20 23:59 pmruwire.log
-rw-------   1 root root       150 Jan  7  2019 pmsberbank.log
-rw-------   1 root root    177386 Jul 20 23:58 pmshellscripts.log
-rw-------   1 root root  45484032 Jul 20 23:58 pmvdsmgr.log
-rw-------   1 root root  98450725 Jul 23 06:54 pmvmmgr6.log
-rw-------   1 root root      5742 Jan 27  2017 pmvmmgr.log
-rw-------   1 root root      1026 Sep 30  2016 pmwebmoneyas.log
-rw-------   1 root root     20189 Jul 20 23:59 pmwebmoney.log
-rw-------   1 root root   6240775 Jul 23 07:45 pmyandexcheckout.log
-rw-------   1 root root      1032 Sep 30  2016 pmyandexmoney.log
-rw-------   1 root root    144253 Jul 12 23:27 pppayment.log
-rw-------   1 root root     90610 Jul 10 14:09 ppresult.log
-rw-------   1 root root         0 Dec  6  2018 qrcode.log
-rw-------   1 root root      4217 May 15 15:21 rkfail.log
-rw-------   1 root root    286244 Jul 22 23:28 rkpayment.log
-rw-------   1 root root    110667 Jul 22 23:48 rkresult.log
-rw-------   1 root root     91841 Jul 22 23:49 rksuccess.log
drwxr-xr-x 111 root root     24576 Jul 23 07:45 run
drwxr-xr-x   2 root root      4096 Feb  7  2017 shellscripts
drw-------   6 root root      4096 Jun 26  2019 slavestatus
drwxr-xr-x   2 root root      4096 Jul 23 07:45 sysinfostat
drwxr-x--- 163 root root      4096 Jul 21 19:45 ticket_attach
-rw-r--r--   1 root root         1 May 27 20:09 totp_cache_time
drwxr-xr-x   3 root root      4096 Apr  4  2016 upload
drwxr-xr-x   2 root root    204800 Jan  4  2020 usageinfo
drwxr-xr-x   2 root root      4096 Mar 17  2017 usagestat
-rw-------   1 root root   5560943 Jul 22 17:58 usagestat.log
drwxr-xr-x   2 root root     49152 Jul 23 04:08 userconf
-rw-------   1 root root   1659293 Jul 23 00:28 wmpayment.log
-rw-------   1 root root   1204985 Jul 23 00:34 wmresult.log
-rw-------   1 root root  27437399 Jul 20 23:57 xmlinstall.log
-rw-------   1 root root   1089691 Jul 22 21:05 ycpayment.log
-rw-------   1 root root    765321 Jul 22 21:07 ycresult.log

Но нам нужно получить только список содержимого. Смотрим еще раз на верхний вывод и понимаем, что список содержимого находится в 9-й колонке.

Тогда достаточно сделать так
[root@server var]# ls -l | awk '{ print $9 }'

backupctl-billmgr.log
billfix.log
billimport.log
billmaintain.log
billmgr.auth.log
billmgr.gdpr_url
billmgr.journal
billmgr.journal.tar.gz
billmgr.log
billmgr.long.log
billmgr.pid
billmgr.pricelist
billmgr.ses
billmgr.version_date.xml
checkip.log
core_acme_sh.log
core.auth.log
core.journal
core.log
core.long.log
core.pid
core.version_date.xml
counter.log
dashboard
expire_logs_value
fgsmsgate.log
fixlist_billmgr
fixlist_core
fixlist_ipmgr
globalindex.log
gwlocalmail.log
gwremotemail.log
gwsmsc.log
ihttpd.log
ihttpd.pid
ipmgr.auth.log
ipmgr.journal
ipmgr.log
ipmgr.long.log
ipmgr.pid
ipmgr.ses
ipmgr.version_date.xml
ispdns.log
ispdns_slave.log
licctl.log
logs
longtask.log
longtask.success
mgrctl.log
mysql.log
mysqlstat.log
mysqlstat_version
new_license
notify
ntemail.log
ntinternal.log
ntsms.log
pkgcheck.log
pkg.log
pm2checkout.log
pmaspayment.log
pmassist.log
pmauto.log
pmbillmgr.log
pmctl.log
pmdnsmgr.log
pmipmgr.log
pmispmgr4.log
pmispmgr5.log
pmliqpay.log
pmmanual.log
pmnaunet.log
pmnic.log
pmosmp.log
pmpaymaster.log
pmpaypal.log
pmqiwi.log
pmr01.log
pmresellerclub.log
pmrobokassa.log
pmruwire.log
pmsberbank.log
pmshellscripts.log
pmvdsmgr.log
pmvmmgr6.log
pmvmmgr.log
pmwebmoneyas.log
pmwebmoney.log
pmyandexcheckout.log
pmyandexmoney.log
pppayment.log
ppresult.log
qrcode.log
rkfail.log
rkpayment.log
rkresult.log
rksuccess.log
run
shellscripts
slavestatus
sysinfostat
ticket_attach
totp_cache_time
upload
usageinfo
usagestat
usagestat.log
userconf
wmpayment.log
wmresult.log
xmlinstall.log
ycpayment.log
ycresult.log

Если у вас что-то не получается или есть вопросы, пишите в комментариях.

Просьба поделиться статьёй в социальных сетях. Больше ссылок, больше шансов найти эту информацию тем, кому она нужна.
+ 0 -

Добавить комментарий