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.
Related
With PHP I am using exec("tar -xf archive.tar -C /home/user/target/folder") to extract the contents of a specific archive (archive.tar) into the target directory (/home/user/target/folder), so that all existing contents of the target directory will be overwritten by the new ones that are contained in the archive.
It works fine and all files in the target directory are being overwritten after extract, but there is one directory in the archive that I would like to omit (from extracting and thus overwriting the existing one in the target folder)...
For example, the archive.tar contains:
folderA/
folderB/
folderC/
folderD/
fileA.php
fileB.php
fileC.xml
How could I extract (and overwrite) all except (for example) folderC/? In other words, I want folderC and its contents to remain intact in the user's directory and not be overwritten by the one contained in the tar archive.
Any suggestions?
(Tar on the hosting server is GNU version 1.23.)
You can use '--exclude' to omit a folder:
tar -xf archive.tar -C /home/user/target/folder" --exclude="folderC"
There is the --exclude PATTERN option in the tar tool.
Check: tar on linuxcommand.org
To be on the safe side, you could remove all write permissions from the folder. For example:
$ chmod 000 folderC/
An then do a normal tar extract (as regular user). You'll get some error messages on console, but your folder will remain untouched.... At the end of the tar, change back your folder original permissions. For example:
$ chmod 775 folderC/
Of course '--exclude' tar option is the right solution to this particular problem, but, if you are not completely 100% sure about a command syntax, and yor're handling critical data, my solution puts you on the safe side :-).
Write --exclude='./folder' at the beginning of the tar command.
In your case that is,
exec("tar -x --exclude='./C' -f archive.tar -C /home/user/target/folder")
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
I want to remove xyz_DB.lock.db file. I tried as root but couldn't delete it. How to remove it in terminal. My initial requirement was remove a folder. but it includes this locked file. And is there anyway to delete folder directly which include a locked file ?
Check with lsattr command if the immutable bit is set for the file, it will show (i)
# lsattr file
----i--------e- file
If so, change it using following command:
# chattr -i file
And then try to remove it.
Try either changing the files permissions through the GUI or use rm -rf on the directory that contains it.
try "chown" to provide permission to your file/folder and then delete it,
e.g: assume username= amol and filename=myfile.txt,,
For File:--- sudo chown amol:amol myfile.txt
For Folder:-- sudo chown -R amol:amol directory_name
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
I currently have a number of drives mounted under "/media/" I want to recursively scan all the drives mounted looking for files with a specific extension "*.foo". Once found I want to symlink these files into a directory elsewhere. One requirement is that I keep the basename of the file the same when creating the symlink. I wasn’t able to come up with a an easy solution using "find -exec" on my own. Is there an easy way to do this?
find /media/ -name *.foo | xargs ln -s -t DIRECTORYYOUWANTLINKSIN