Top.Mail.Ru

How to copy hidden files in Linux

How to copy hidden files in Linux

In Linux, files and directories whose names begin with a dot are considered hidden. There are many such objects in the home directory and in folders with sites: configurations, service files, caches. Sometimes you need to transfer them along with the rest of the data — and there are nuances here.

One file with a dot in the name is copied as usual. Problems begin when you want to “take everything” with the * template: by default it does not see names starting with a dot. This was done on purpose so as not to affect official records. and .. and not create unwanted recursion when copying.

Let’s look at the main copying methods

Option #1 — link to “all contents” via /.

This command will copy both regular and hidden items from the source directory to the target folder.

cp -r app/. backup

The -r switch is needed for recursive copying of directories, and the / suffix. makes it clear that we are talking specifically about the contents of the app.

Option No. 2 — copying the directory “as is” without a nested level

The following command will make backup a copy of app rather than backup/app.

cp -rT app backup

The -T flag specifies to treat backup as a target object, and not as a destination directory for “nested” copying; -r — for working with folders.

Option #3 — if you only need hidden files

In this case, you can explicitly refer to the dotted name pattern:

cp app/.* backup

Important: do not add -r here. The pattern .* includes . And ..; with recursion, the command will try to go one level higher in the directory tree, which can easily result in additional complications.

These techniques cover all the typical scenarios: copying a single file with a dot, moving the entire contents of a directory with hidden items, and selectively sending only «dot» files. Use the option that best suits your needs.

CONTENT:

Similar

All news

Похожее

Все новости

Adaxa Suite: подробный обзор ERP-системы корпоративного класса

Adaxa Suite — комплексная ERP-платформа для компаний, которым уже тесно в рамках простых учётных систем, но которые при этом не готовы идти в сторону дорогих корпоративных решений уровня SAP или Oracle. Изначально продукт создавался для среднего бизнеса, которому нужна большой набор функций, сквозная автоматизация процессов и надёжная архитектура без чрезмерной стоимости владения. Архитектура и техническая […]

Как заказать дополнительные IP-адреса на UFO.Hosting: пошаговая инструкция

По мере роста проекта одного IP-адреса может стать недостаточно. Это типичная ситуация для компаний, которые масштабируют инфраструктуру, запускают новые сервисы или разделяют внутренние процессы. В UFO.Hosting подключение дополнительных IP-адресов выполняется через биллинговую панель и занимает всего несколько минут. Важно: возможность для заказа дополнительных IP-адресов доступна для тарифов VPS начиная с Haedus. Зачем нужны дополнительные IP-адреса […]