Tạo file không thể xóa trên Linux?

vobach.nhan

New member
** Cách tạo một tệp có thể bị xóa trên Linux **

** tl; dr: **

1. Tạo một tệp với lệnh sau: `Touch /tmp /understable.txt`
2. Làm cho tệp chỉ đọc với lệnh sau: `Chmod 444 /tmp /underselable.txt`
3. Gắn hệ thống tệp với lệnh sau: `Mount -o Remount, RO /`

** Phiên bản dài: **

Bạn có thể tạo một tệp có thể bị xóa trên Linux bằng cách làm theo các bước sau:

1. Tạo một tệp với lệnh sau:

`` `
Touch /tmp/undeletable.txt
`` `

2. Làm cho tệp chỉ đọc với lệnh sau:

`` `
Chmod 444 /tmp/undeletable.txt
`` `

3. Gắn hệ thống tệp với lệnh sau:

`` `
gắn kết -o respount, ro /
`` `

Bây giờ, tập tin `/TMP/không thể chịu đựng được.txt` có thể bị xóa.Nếu bạn cố gắng xóa nó, bạn sẽ nhận được thông báo lỗi sau:

`` `
RM: Không thể xóa ‘/tmp/undeletable.txt, không được phép hoạt động
`` `

** '\' trong dòng thứ hai trở đi có nghĩa là gì? **

Backslash (`\`) trong dòng thứ hai trở đi là một ký tự thoát.Nó bảo vỏ để giải thích các nhân vật sau đây theo nghĩa đen.Ví dụ: lệnh sau sẽ tạo một tệp có tên là `understable.txt` trong thư mục`/tmp`:

`` `
Touch /tmp/undeletable.txt
`` `

Tuy nhiên, lệnh sau sẽ tạo một tệp có tên `\ tmp \ understable.txt` trong thư mục hiện tại:

`` `
Chạm vào \ tmp \ không thể chịu đựng được.txt
`` `

** Tôi có thể đặt tệp này vào Windows không? **

Có, bạn có thể đặt tệp này vào Windows.Tuy nhiên, Windows won có thể đọc hoặc ghi vào tệp.Nếu bạn cố gắng mở tệp, bạn sẽ nhận được thông báo lỗi sau:

`` `
Windows không thể truy cập tệp ‘/tmp/undeletable.txt.Truy cập bị từ chối.
`` `

** Mẹo thưởng: **

Bạn cũng có thể tạo một tệp có thể bị xóa bằng cách sử dụng lệnh sau:

`` `
dd if =/dev/zero của =/tmp/undeletable.txt bs = 1 Count = 1024
`` `

Lệnh này sẽ tạo một tệp có tên `/tmp/undeletable.txt` dài 1024 byte.Tệp sẽ được lấp đầy bằng các số không, do đó, nó đã giành được bất kỳ dữ liệu hữu ích nào.Tuy nhiên, tệp vẫn sẽ chỉ được đọc và có thể bị xóa.
=======================================
**How to create a file that can’t be deleted on Linux**

**TL;DR:**

1. Create a file with the following command: `touch /tmp/undeletable.txt`
2. Make the file read-only with the following command: `chmod 444 /tmp/undeletable.txt`
3. Mount the file system with the following command: `mount -o remount,ro /`

**The long version:**

You can create a file that can’t be deleted on Linux by following these steps:

1. Create a file with the following command:

```
touch /tmp/undeletable.txt
```

2. Make the file read-only with the following command:

```
chmod 444 /tmp/undeletable.txt
```

3. Mount the file system with the following command:

```
mount -o remount,ro /
```

Now, the file `/tmp/undeletable.txt` can’t be deleted. If you try to delete it, you’ll get the following error message:

```
rm: cannot remove ‘/tmp/undeletable.txt’: Operation not permitted
```

**What does the '\' in the second line onwards mean?**

The backslash (`\`) in the second line onwards is a escape character. It tells the shell to interpret the following character literally. For example, the following command will create a file named `undeletable.txt` in the `/tmp` directory:

```
touch /tmp/undeletable.txt
```

However, the following command will create a file named `\tmp\undeletable.txt` in the current directory:

```
touch \tmp\undeletable.txt
```

**Can I put this file into Windows?**

Yes, you can put this file into Windows. However, Windows won’t be able to read or write to the file. If you try to open the file, you’ll get the following error message:

```
Windows cannot access the file ‘/tmp/undeletable.txt’. Access is denied.
```

**Bonus tip:**

You can also create a file that can’t be deleted by using the following command:

```
dd if=/dev/zero of=/tmp/undeletable.txt bs=1 count=1024
```

This command will create a file named `/tmp/undeletable.txt` that is 1024 bytes long. The file will be filled with zeros, so it won’t contain any useful data. However, the file will still be read-only and can’t be deleted.
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top