138
votes
Accepted
Linux - Is there a way to prevent/protect a file from being deleted even by root?
Yes, you can change the attributes of the file to read-only.
The command is:
chattr +i filename
And to disable it:
chattr -i filename
From man chattr:
A file with the i attribute cannot be ...
- 10.5k
85
votes
Linux - Is there a way to prevent/protect a file from being deleted even by root?
Burn it to a CD. Put the CD in a CD-ROM drive and access it from there.
- 1,344
53
votes
Accepted
nginx split large configuration file
You are probably looking for Nginx's include function:
http://nginx.org/en/docs/ngx_core_module.html#include
You can use it like this:
server {
listen 80;
server_name example.com;
[…]
...
- 678
46
votes
Accepted
Linux mv file with long name
for a single file try
mv dir1/dir2/dir3/file.{txt,txt.old}
where the X{a,b} construct expand to Xa Xb, you can have a preview using
echo dir1/dir2/dir3/file.{txt,txt.old}
to see if it fit your ...
- 1,359
37
votes
How can I retrieve a directory (folder) from Ubuntu Server 14.04 VM without FTP, SCP, or NFS
As well as saying all the things it doesn't have, what about saying the things it does have? How big is the folder and how much free disk space is there?
Assuming you have no access to the CLI at all,...
- 5,696
29
votes
Linux - Is there a way to prevent/protect a file from being deleted even by root?
Create a file system image.
Mount the image.
Copy the file to the mounted image.
Unmount the image and remount it as read-only.
Now you can't delete it.
Example:
# dd if=/dev/zero of=readonly.img bs=...
- 391
27
votes
Perform rsync while following sym links
You need both -L and -K if you have symlinks on both sides, e.g. you already had your 1st rsync done and want to update the backup using rsync.
-L, --copy-links transform symlink into ...
- 371
25
votes
Accepted
Systemd drop-in fails to create PID file
The PIDFile= setting does not create a PID file. That is still up to the service itself to do, the same as it has been for the last 40 years. Rather, this option tells systemd where to find an ...
- 240k
22
votes
Perform rsync while following sym links
Just ran into this problem. And if you want rsync to treat symlinked directories as directories, you want the K option
rsync -K /files/ user@server:/files/
- 341
15
votes
Copying a large directory tree locally? cp or rsync?
This thread was very useful and because there were so many options to achieve the result, I decided to benchmark few of them. I believe my results can be helpful to others have a sense of what worked ...
- 251
14
votes
How to move files between two S3 buckets with minimum cost?
Old topic, but this is for anyone investigating the same scenario. Along with the time it took me, for 20,000+ objects. Running on AWS Linux/Centos, each object being images for the most part, along ...
- 279
14
votes
Systemd drop-in fails to create PID file
Regrettably, systemd won't create a PID file for a non-forking service even if you specify a PIDFile= line in the service's unit file. But you may be able to cheat with an ExecStartPost= line, such as:...
- 331
12
votes
Comparing owners and permissions of content of two folders?
Find and stat:
find . -exec stat --format='%n %A %U %G' {} \; | sort > listing
Run that in both directories then compare the two listing files.
Saves you from the evils of Perl...
- 121
10
votes
Accepted
What is fastest way to copy a sparse file? What method results in the smallest file?
From the above benchmarking, it looks like using dd on our target hardware with a blocksize of 64K gives us the best overall result considering the copy time and bloat:
dd if=srcFile of=dstFile iflag=...
- 403
8
votes
How to view hidden files using Linux `find` command
It's better to use iname (case insensitive).
I use this find command to search hidden files:
find /path -type f -iname ".*" -ls
Extracted from: http://www.sysadmit.com/2016/03/linux-ver-archivos-...
- 81
8
votes
Get total files size from a file containing a file list
du -c `cat filelist.txt` | tail -1 | cut -f 1
-c adds line "total size";
tail -1 takes last line (with total size);
cut -f 1 cuts out word "total".
- 181
8
votes
nginx split large configuration file
You can create site folders with
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
# And then split your large your_config.conf file into smaller files into sites-available/ with:
...
- 2,399
8
votes
Bash one-liner to atomically create a file if it doesn't exist
Stealing an answer from various comments and links to [SO]. It seems there is a POSIX compliant method that doesn't involve mkdir as I mentioned in my original answer below
set -o noclobber # or set -...
- 115k
7
votes
How do I do Multihop SCP transfers between machines?
It's possible and relatively easy, even when you need to use certificates for authentication (typical in AWS environments).
The command below will copy files from a remotePath on server2 directly into ...
- 181
7
votes
Linux - Is there a way to prevent/protect a file from being deleted even by root?
You should create multiple hard links to the file as well. These should be in various locations that regular users can't access.
This way, even if they do manage to override your chattr protection, ...
- 87
7
votes
Linux - Is there a way to prevent/protect a file from being deleted even by root?
Linux has so-called bind-mount option which is rather powerful and useful feature to know:
% cd $TMP && mkdir usebindmountluke && cd usebindmountluke
% echo usebindmountluke > ...
- 9,305
7
votes
Debian - how to prevent global read access for all files?
In my debian all files, even the system ones have permissions rw-r--r--, so it means that all users can view ANY file even some system configuration or database files and so on.
Unless you fiddled ...
- 6,848
7
votes
How can I get docker build to overwrite a file?
I experienced this too, but after much testing discovered that I had a typo in one of my COPY directives' destination paths.
Double-check where those files are really going
-COPY nginx.conf /etc/...
- 215
6
votes
How do I do Multihop SCP transfers between machines?
This isn't scp (which OP requested), but I found it super simple to use rsync to copy from local to remote over a single hop with:
rsync -v -e 'ssh -A -t user@jumpserver ssh -A -t user@...
6
votes
Windows Server 2008 R2 max open files limit
Windows have limits on the number of Open File Handles.It will be around 16,711,680 on 64 bit machines and on 32 bit machines it will be 16,744,448.
64 BIT
32 BIT
This is the reference Microsoft ...
- 181
6
votes
How to move files between two S3 buckets with minimum cost?
The AWS CLI provides a way to copy one bucket to another in parallel processes. Taken from https://stackoverflow.com/a/40270349/371699:
The following commands will tell the AWS CLI to use 1,000 ...
- 205
6
votes
Accepted
Move a specific number of files to folders from a large pool of files
To answer what you want exactly, this will move 5,000 files into folders, starting with 1 and continuing until it runs out of files to move. Your last folder will most likely have less than 5,000 ...
- 68.4k
6
votes
How can I retrieve a directory (folder) from Ubuntu Server 14.04 VM without FTP, SCP, or NFS
The virtual machine disk is hopefully stored in a way that is backed up regularly - so you can restore the backup to a new location and then use the VM disk as a second disk in a new VM.
If there are ...
- 663
6
votes
Accepted
Can I validate a large file download piecemeal over http
On the server side, you can use dd and md5sum to checksum each chunk of the file:
#!/bin/bash
FILENAME="$1"
FILESIZE=`stat --printf="%s" $FILENAME`
CHUNKSIZE=536870912 # 512MB
CHUNKNUM=0
while ! grep ...
- 5,302
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
files × 670linux × 160
windows × 68
filesystems × 46
directory × 32
windows-server-2008 × 26
backup × 25
rsync × 25
ubuntu × 23
unix × 23
apache-2.2 × 22
centos × 21
permissions × 20
windows-server-2003 × 19
find × 19
copy × 19
bash × 17
upload × 17
nginx × 16
mysql × 16
php × 14
command-line-interface × 14
ftp × 13
file-sharing × 13
synchronization × 12