Hot answers tagged

133

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 modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process ...


101

When copying to the local file system I always use the following rsync options: # rsync -avhW --no-compress --progress /src/ /dst/ Here's my reasoning: -a is for archive, which preserves ownership, permissions etc. -v is for verbose, so I can see what's happening (optional) -h is for human-readable, so the transfer rate and file sizes are easier to read (...


83

Burn it to a CD. Put the CD in a CD-ROM drive and access it from there.


52

Millions is a big number - I'll get back to that later. Regardless of your approach, the underlying mechanism needs to be copying directly from one bucket to another - in this way (since your buckets are in the same region) you do not incur any charge for bandwidth. Any other approach is simply inefficient (e.g. downloading and reuploading the files). ...


47

This is similar to what happens when you delete a file that another system has open on a NFS mount. The problem is that the file has been removed from the filesystem while its "link count" was >1, meaning that other processes are still holding it open. Log in to the system where the file physically resides. (no network mount) Execute lsof dir-name/....


45

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 need. note: that for multiple files mv dir1/dir2/dir3/file{1,2,3}.{txt,txt.old} is unlikely to expand to what you want. (this will expand to a mixed of file....


40

You're almost right. -mtime 365 will be all files that are exactly 365 days old. You want the ones that are 365 days old or more, which means adding a + before the number like this -mtime +365. You may also be interested in the -maxdepth 1 flag, which prevents you from moving items in sub directories. If you want to be sure that you are only moving files, ...


39

press ctrl + space on current directory and this will show it size. Also you can use visual select to apply this command on multiply items.


37

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, even from the console: If it's ESXi 5.0 or above, and the server has VMware Tools installed, use PowerCLI and the Copy-VMGuestFile cmdlet to copy files from ...


29

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=1024 count=1024 # mkfs.ext2 readonly.img # mkdir readonlyfolder # mount readonly.img readonlyfolder/ # echo "can't delete this" > readonlyfolder/permanent....


25

It seems like you might want to take a look at the --whole-file or -W switch. This is enabled by default if rsync is doing local filesystem copies, but I think the docs recommend its usage if the LAN speed is high and syncing over the network. Basically, it disables the rsync delta algorithm and just transfers the whole file if it believes it's different. ...


25

Set worker_rlimit_nofile 65535; in nginx.conf within the main context.


23

It depends on your filesystem. I'm going to assume it's ext4: The maximum number of files is global, not per directory, and it's determined by the number of inodes allocated when the filesystem was created. Try running the following command to see the number of inodes per filesystem. $ df -i Filesystem Inodes IUsed IFree IUse% Mounted on ...


22

You can change the default location on a per website/application basis by editing the Configuration section of the Web.config file. <system.web> <compilation tempDirectory="D:\MyTempFiles" /> </system.web> The application will re-compile and the files will be stored at this new location, after which you can safely remove the old ...


22

Sure, of course it's possible. dd if=/dev/mygroup-mylv | ssh 192.168.1.103 dd of=/dev/newvgroup-newlv Boom. Do yourself a favor, though, and use something larger than the default blocksize. Maybe add bs=4M (read/write in chunks of 4 MB). You can see there's some nitpicking about blocksizes in the comments; if this is something you find yourself doing ...


21

Better use the partclone utility instead: cd /home/partimag/YOURIMAGE/ touch hda2.img cat dir/hda2.ntfs-ptcl-img.gz.* | gzip -d -c | partclone.restore -C -s - -o hda2.img mount -o loop hda2.img /mnt See also CloneZilla FAQ Entry: "How can I restore those *-ptcl-img.* images into a file manually?"


21

Don't tar. Use rsync -av to preserve permissions while transfering the files. Though like tar, this does not preserve selinux context. Not that I would consider that important though.


20

It's strange nobody noted that cp has option -l: -l, --link hard link files instead of copying You can do something like % mkdir merge % cp -rl dir1/* dir2/* merge % rm -r dir* % tree merge merge ├── a │   ├── file1.txt │   ├── file2.txt │   ├── file5.txt │   └── file6.txt ├── b │   ├── file3.txt │   ├── file7.txt │   └── file8.txt └── c ├── ...


19

You can use systemtap to show all PIDs that are trying to use unlink() on the inode of .bashrc and .bash_profile files. Install systemtap and the debug symbols for your kernel. Create a file with name unlink.stap with the following content: probe syscall.unlink { printf ("%s(%d) unlink (%s) userID(%d)\n", execname(), pid(), argstr, uid()) } Then run ...


19

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; […] include conf/location.conf; } include also accepts wildcards so you could also write include include/*.conf; to include every *.conf file in the directory include.


18

Probably a trailing new-line character. For example, a file created in a text editor containing only an 'a' may actually contain 2 bytes: $ cat /tmp/test_text | hexdump -C 00000000 61 0a |a.| 00000002 However, using echo -n (no new line) gives us a size of 1 byte: $ echo -n 'a' > /tmp/test_text $ ls -l /tmp/...


17

Here's an optimized version, which shows the progress using pv and uses BS for bigger chunks and also uses gzip to reduce the network traffic. That's perfect when moving the data between slow connections like internet servers. I recommend to run the command inside a screen or tmux session. That way the ssh connection to the host from where you execute the ...


17

This might be what you're after. % rsync -avvz --times --stats --checksum --human-readable --acls \ --itemize-changes --progress \ --out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' \ /usr/include/glib-2.0 my-glib-copy/ The switches breakdown as follows: -avvz = archive, verbose x 2, compress --times = preserve modification ...


16

An extra byte is for the line end at the end of the file, it's quite common for Linux text editors to add this line end after the last line.


15

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/


14

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 existing PID file (if any). In most cases it's not required at all, as systemd will keep services in their own cgroups and does not need a PID file to keep track of ...


13

rsync Here is the rsync I use, I prefer cp for simple commands, not this. $ rsync -ahSD --ignore-errors --force --delete --stats $SRC/ $DIR/ cpio Here is a way that is even safer, cpio. It's about as fast as tar, maybe a little quicker. $ cd $SRC && find . -mount -depth -print0 2>/dev/null | cpio -0admp $DEST &>/dev/null tar This is ...


13

You can do that by combining loop devices and device mapper, thanks to "everything is a file". But with one limitation: The file size cannot be changed (as you cannot increase block devices by writing to them). So if you want to append data then you have to create a bigger block device and overwrite the appended dummy data. # for testing, Create 4 files ...


13

You probably want to buy more disk space, but assuming you don't, you could... pipe the tarball around rather than downloading it. newserver# ssh olduser@oldserver "cat /path/to/tarball" | tar xf - or if you don't have SSH access to your old server newserver# wget -O - http://oldserver/path/to/tarball | tar xf - or use rsync like Dennis said. Be ...


12

I believe something like this would work in busybox: du `cat filelist.txt` | awk '{i+=$1} END {print i}' I don't have the same environment as you, but if you encounter issues with spaces in filenames something like this would work too: cat filelist.txt | while read file;do du "$file" done | awk '{i+=$1} END {print i}' Edit 1: @stew is right in his post ...


Only top voted, non community-wiki answers of a minimum length are eligible