"А так можно было?" - подумал я увидя такую конструкцию:
user@server:~$ mv /etc/postfix/{canonical,sender_relay,sasl_passwd} /etc/postfix/private/
Или так (переимновать без ввода полного пути)
user@server:~$ mv /etc/postfix/main.cnf{,.back}
Или так (создать копию без повторного ввода всего пути)
user@server:~$ cp /etc/postfix/main.cnf{,.back}
user@server:~$ ls /etc/postfix/main*
/etc/postfix/main.cf /etc/postfix/main.cf.back /etc/postfix/main.cf.db /etc/postfix/main.cf.proto /etc/postfix/main.cf.proto.db /etc/postfix/main.cf.save
С того момента я каждый раз тратил много времени на попытку вспомнить конструкцию и вот решил устаканить в своей голове фигурные скобки в консоли линукс-подобных систем. При повседневных операциях бывает необходимо повторить одно действие несколько раз и как же бесит когда не можешь упростить. Перейдем к примерам - скопировать из каталогов несколько разных файлов можно разными способами:
user@server:~$ ls ~/test
folder_1 folder_2 file_1 file_2 file_1_bak file_2_bak
user@server:~$ cp ~/test/file_1 ~/test/file_1_bak /new_folder
user@server:~$ ls /new_folder
file_1 file_1_bak
user@server:~$ rm /new_folder/*
user@server:~$ cp ~/test/file_1* /new_folder
user@server:~$ ls /new_folder
file_1 file_1_bak
user@server:~$ rm /new_folder/*
user@server:~$ cp ~/test/file_{1,1_bak} /new_folder
user@server:~$ ls /new_folder
file_1 file_1_bak
user@server:~$ rm /new_folder/*
user@server:~$ cp ~/test/file_1{,_bak} /new_folder
user@server:~$ ls /new_folder
file_1 file_1_bak
Создать несколько директорий
user@server:~$ mkdir ~/test/folder_1 ~/test/folder_2 ~/test/folder_3
user@server:~$ ls ~/test
folder_1 folder_2 folder_3
user@server:~$ rm -r ~/test/*
user@server:~$ mkdir ~/test/{folder_1,folder_2,folder_3}
user@server:~$ ls ~/test
folder_1 folder_2 folder_3
user@server:~$ rm -r ~/test/*
user@server:~$ mkdir ~/test/folder_{1,2,3}
user@server:~$ ls ~/test
folder_1 folder_2 folder_3
Создать несколько директорий с поддерикторией
user@server:~$ mkdir ~/test/folder_1 ~/test/folder_2 ~/test/folder_3
user@server:~$ mkdir ~/test/folder_1/subfolder_1 ~/test/folder_2/subfolder_1 ~/test/folder_3/subfolder_1
user@server:~$ ls ~/test
folder_1 folder_2 folder_3
user@server:~$ ls ~/test/*
folder_1:
subfolder_1
folder_2:
subfolder_1
folder_3:
subfolder_1
user@server:~$ rm -r ~/test/*
user@server:~$ mkdir ~/test/folder_{1,2,3}
user@server:~$ mkdir ~/test/*/subfolder_1
user@server:~$ ls ~/test/*
folder_1:
subfolder_1
folder_2:
subfolder_1
folder_3:
subfolder_1
user@server:~$ rm -r ~/test/*
user@server:~$ mkdir -p ~/test/folder_{1,2,3}/subfolder_1
user@server:~$ ls ~/test/*
folder_1:
subfolder_1
folder_2:
subfolder_1
folder_3:
subfolder_1
user@server:~$ rm -r ~/test/*
user@server:~$ mkdir -p ~/archive/year_20{0,1}{0,1,2,3,4,5,6,7,8,9}/mounth_{1,2,3,4,5,6,7,8,9,10,11,12}/day_{1,8,15,22,29}
user@server:~$ tree ~/archive
/root/archive/
├── year_2000
│ ├── mounth_1
│ │ ├── day_1
│ │ ├── day_15
│ │ ├── day_22
│ │ ├── day_29
│ │ └── day_8
│ ├── mounth_10
│ │ ├── day_1
│ │ ├── day_15
│ │ ├── day_22
│ │ ├── day_29
│ │ └── day_8
│ ├── mounth_11
│ ├── ....
│ └── mounth_9
│ ├── day_1
│ ├── day_15
│ ├── day_22
│ ├── day_29
│ └── day_8
├── ....
└── year_2019
├── ....
└── mounth_9
├── day_1
├── day_15
├── day_22
├── day_29
└── day_8
1460 directories, 0 files
Последним представлен фокус c созданием структуры каталогов из 1460 папок, одной строчкой
И такой фокус можно проделывать с многими командами, например в du,rm,cp,touch,mkdir и т.д.
user@server:~$ du -chs ~/archive/year_201*/mounth_{1,2,3}/day_{1,29}
du -chs ~/archive/year_201*/mounth_{1,2,3}/day_{1,29}
4.0K /root/archive/year_2010/mounth_1/day_1
4.0K /root/archive/year_2011/mounth_1/day_1
4.0K /root/archive/year_2012/mounth_1/day_1
4.0K /root/archive/year_2013/mounth_1/day_1
4.0K /root/archive/year_2014/mounth_1/day_1
4.0K /root/archive/year_2015/mounth_1/day_1
4.0K /root/archive/year_2016/mounth_1/day_1
4.0K /root/archive/year_2017/mounth_1/day_1
4.0K /root/archive/year_2018/mounth_1/day_1
4.0K /root/archive/year_2019/mounth_1/day_1
4.0K /root/archive/year_2010/mounth_1/day_29
4.0K /root/archive/year_2011/mounth_1/day_29
4.0K /root/archive/year_2012/mounth_1/day_29
4.0K /root/archive/year_2013/mounth_1/day_29
4.0K /root/archive/year_2014/mounth_1/day_29
4.0K /root/archive/year_2015/mounth_1/day_29
4.0K /root/archive/year_2016/mounth_1/day_29
4.0K /root/archive/year_2017/mounth_1/day_29
4.0K /root/archive/year_2018/mounth_1/day_29
4.0K /root/archive/year_2019/mounth_1/day_29
4.0K /root/archive/year_2010/mounth_2/day_1
4.0K /root/archive/year_2011/mounth_2/day_1
4.0K /root/archive/year_2012/mounth_2/day_1
4.0K /root/archive/year_2013/mounth_2/day_1
4.0K /root/archive/year_2014/mounth_2/day_1
4.0K /root/archive/year_2015/mounth_2/day_1
4.0K /root/archive/year_2016/mounth_2/day_1
4.0K /root/archive/year_2017/mounth_2/day_1
4.0K /root/archive/year_2018/mounth_2/day_1
4.0K /root/archive/year_2019/mounth_2/day_1
4.0K /root/archive/year_2010/mounth_2/day_29
4.0K /root/archive/year_2011/mounth_2/day_29
4.0K /root/archive/year_2012/mounth_2/day_29
4.0K /root/archive/year_2013/mounth_2/day_29
4.0K /root/archive/year_2014/mounth_2/day_29
4.0K /root/archive/year_2015/mounth_2/day_29
4.0K /root/archive/year_2016/mounth_2/day_29
4.0K /root/archive/year_2017/mounth_2/day_29
4.0K /root/archive/year_2018/mounth_2/day_29
4.0K /root/archive/year_2019/mounth_2/day_29
4.0K /root/archive/year_2010/mounth_3/day_1
4.0K /root/archive/year_2011/mounth_3/day_1
4.0K /root/archive/year_2012/mounth_3/day_1
4.0K /root/archive/year_2013/mounth_3/day_1
4.0K /root/archive/year_2014/mounth_3/day_1
4.0K /root/archive/year_2015/mounth_3/day_1
4.0K /root/archive/year_2016/mounth_3/day_1
4.0K /root/archive/year_2017/mounth_3/day_1
4.0K /root/archive/year_2018/mounth_3/day_1
4.0K /root/archive/year_2019/mounth_3/day_1
4.0K /root/archive/year_2010/mounth_3/day_29
4.0K /root/archive/year_2011/mounth_3/day_29
4.0K /root/archive/year_2012/mounth_3/day_29
4.0K /root/archive/year_2013/mounth_3/day_29
4.0K /root/archive/year_2014/mounth_3/day_29
4.0K /root/archive/year_2015/mounth_3/day_29
4.0K /root/archive/year_2016/mounth_3/day_29
4.0K /root/archive/year_2017/mounth_3/day_29
4.0K /root/archive/year_2018/mounth_3/day_29
4.0K /root/archive/year_2019/mounth_3/day_29
240K total
Посчитали объем каталогов в разных локациях.
Комментариев нет:
Отправить комментарий