linux - sync two local directories - linux

I need to sync two local directories in linux.
For example /var/www and /www.
I heard about Rsync but I don't know how to use it.
Basically, when I put something in /var/www it needs to appear in /www and when I put something in /www it needs to appear in /var/www.

Could you not make a soft link of the two files, then when you load something into one directory it loads it into the other.
ln -s {target-filename} {symbolic-filename}
ln -s /var/www /www

Related

What is the meaning of the rm -fv command?? using it for csf installation

I want to know what exactly the following command means ??
rm -fv csf.tgz
I'm typing this command as the first step for installing csf on my virtualmin, but I dont know the exact meaning. I just now copied and pasted it.
rm -rf / – Deletes Everything!
Never use this command in your Linux computer because it deletes every file in your system.
sudo - sudo (Super User DO) is generally used as a prefix of some command that only superuser are allowed to run.
rm – Remove the following files.
-rf – Run rm recursively (delete all files and folders inside the specified folder) and force-remove all files without prompting you.
/ – Tells rm to start at the root directory, which contains all the files on your computer and all mounted media devices, including remote file shares and removable drives.

What are the linux commands to create a new folder & copy all the files & folders present in '/var/www/' into it to take backup of all code files?

Let me assure you that the operations I'm going to perform is on my live production server, so there is no scope for any error.
The server as well as my local machine are using Linux operating system only.
I'm able to login through the terminal on my machine with following command and entering the password :
root#32.77.491.13
Then again I typed in following command to go into the directory '/var/www' on the server :
cd /var/www
Now what I want to create is create a folder titled 'website_backup_19_02_2016' inside the folder 'var/www/'
In the newly created folder 'website_backup_19_02_2016' all the files and folders present in '/var/www/' should be copied (except the newly created folder 'website_backup_19_02_2016').
Can someone please provide me the exact set of command in sequential manner so that by executing them I can take backup of my website without any hassle.
You can issue below commands :-
1) Create directory
# mkdir /var/www/website_backup_19_02_2016
2) Copying files except website_backup_19_02_2016 directory. You can achive this using rsync tool.
# cd /var/www/
# rsync -av --progress * website_backup_19_02_2016/ --exclude website_backup_19_02_2016/
" * " --> for all your files and directories in /var/www/
Note :- You can run a dry run with rsync command to check which files and directories will actually copied. This will be important for you.
rsyn -n --progress * website_backup_19_02_2016/ --exclude website_backup_19_02_2016/
Read more options for rsync from man page.
This should work
cd /var/www
mkdir website_backup_19_02_2016
rsync -av --exclude='/var/www/website_backup_19_02_2016' /var/www /var/www/website_backup_19_02_2016
This answer your question but - if I were you - I would use a different date format (YYYY-MM-DD) that works better for listing and sorting. This would be easy to run in a script:
bck=website_backup_$(date +%Y-%m-%m)
cd /var/www && mkdir ${back}
rsync -av --exclude="$bck" /var/www/{,/$bck}

Linux folder move access

Is a Linux file system able to allow or deny the right to move a folder? Active Directory does not, as far as I can tell. I'm curious, and 3 different wordings generated no results.
Yes. If you have a folder foo/bar/, you could make the folder foo read-only, which would prevent people from moving bar:
$ chmod a-w foo
$ mv foo/bar ack
mv: cannot move ‘foo/bar’ to ‘ack’: Permission denied
The can't move bar, but they can still change what's inside of it:
$ echo hello > foo/bar/hello.txt
$ rm foo/bar/hello.txt
In linux you can use chattr to make a file or folder immutable like so:
chattr +i file
This way, not even the super can move, modify or delete the file.
To revert it you can use:
chattr -i file
This works for on ext filesystems

How do I create a multi-level softlink in Linux or can this be done? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have inherited old scripts which cannot be touched - don't ask. It references software installed at location /SuperSoft/SomeSoft/
The new version of the software, remade since the buyout, installs at location
/usr/local/SomeSoft
I've been having a bear trying to create the following softlink at the root level:
ln -s SuperSoft/SomeSoft/ /usr/local/SomeSoft/
I would hate to create a SuperSoft directory at the root level. Can this be done?
Having the same files in two parts of the filesystem can also be accomplished with mount.
From "man mount" on linux:
Since Linux 2.4.0 it is possible to remount part of the file
hierarchy somewhere else. The call is
mount --bind olddir newdir
or shortoption
mount -B olddir newdir
or fstab entry is:
/olddir /newdir none bind
After this call the same contents is accessible in two places.
Was hard to get want you want. Use this link:
ln -s /usr/local/SuperSoft/ /SuperSoft/
Now you can use the following ls to browse the contents of /SuperSoft/SomeSoft:
ls -al /SuperSoft/SomeSoft
You're looking for the first form of ln:
SYNOPSIS
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
Using -s as an option, since you want a symbolic link. The TARGET is the "value" of the symlink--i.e., what the link is going to be pointing to. The LINK_NAME is the actual location of the link being created. So, to create a symlink at /SuperSoft/SomeSoft that points to /usr/local/SomeSoft, you would do:
ln -s /usr/local/SomeSoft /SuperSoft/SomeSoft
Which would look like this in a long listing:
$ ls -l /SuperSoft/SomeSoft
lrwxrwxrwx 1 user group 18 May 23 13:43 /SuperSoft/SomeSoft -> /usr/local/SomeSoft
So you can install the new version of your software as normal to /usr/local, and your existing scripts which cannot be modified will be pointed to /usr/local when they try to access /SuperSoft/SomeSoft.
Note that doing it this way assumes there exists a directory called /SuperSoft. If this isn't an option for you (or if you just don't want to do it), then you can create a symlink at /SuperSoft that points to /usr/local (ln -s /usr/local /SuperSoft), since accessing /Supersoft/SomeSoft will turn into /usr/local/SomeSoft. I'd recommend against this though, as it's not very clean.
UPDATE:
Another way to make it so that /SuperSoft is a symlink is to do:
mkdir /usr/local/SuperSoft
ln -s /usr/local/SuperSoft /SuperSoft
ln -s /usr/local/SomeSoft /SuperSoft/SomeSoft
In any case, there needs to be a directory that houses the link pointing to /user/local/SomeSoft.
No, you cannot create a symlink that is a directory path. A symlink is just an entry in an ordinary directory, so it must conform to all regular naming rules.
If you want a symlink "/SuperSoft/SomeSoft", then "/SuperSoft" must exist. It could be a directory, or it could be a symlink to elsewhere, but it has to be something.
If you absolutely want to avoid creating a new directory in /, then you could create a fake / with the appropriate directories/symlinks/etc and run the scripts chrooted() there. But that's a bunch more setup than just making one directory.

moving files to subdirectory in linux

I am trying to figure out how to:
move the contents of
/var/www/html/1/ to /var/www/html/
in linux?
mv -i /var/www/html/1/* /var/www/html
The -i is there for safety; it will ask confirmation before overwriting an existing file.

Resources