General :: Checking If Multiple Directories Exist?
Apr 27, 2011
I have one file called test.sh and in that file I have the below code. All this code is, is paths to three directories (as you can you can clearly see!).
Code:
#!/bin/bash
BACKUP="Documents /bin /sbin"
Now I have this other file which reads the directories (by using $BACKUP) and creates a tar file of everything in that folder. But what I am unsure of what to is create a bit of code that will simply look in test.sh, read all the directories and print a line saying either they all exist or some are missing. If possible it would be good to know which directories are missing too!
I have fiddled around with using -d but I can only get it to work for one directory or manually having to write out each directory.
View 4 Replies
ADVERTISEMENT
May 15, 2011
I want to make a webserver with multiple users allowed to login through SFTP to a specific folder, www.Multiple users are added, lets say user1 and user2, and all of them belonging to the www-data group. The www directory has an owner www-data and a group www-data.
I have used chmod -R 775 on the www folder, but after I try to create a folder test through my SFTP server (using Filezilla) the group of the directory created has only r and x permissions, and I am not able to log in with the second user user2 and create a directory within www/test due to a lack of w permission to the group.
I also tried using chmod 2775 on www directory, but without luck. Can somebody explain to me, how can I make it so that a newly created directory inherits the root directory group permissions?
View 2 Replies
View Related
Aug 23, 2010
I am to rename all the files within a directory (which contains multiple subdirectories) recursively without invalid characters.
I tried the coding posted above.
find . -type f -printf '%p
' | while read file; do
oldfile=$(basename "$file")
newfile=$(echo "$oldfile" | sed 's/[^A-Za-z0-9_.]/_/g')
if [ ! "$newfile" == "$oldfile" ]; then
echo mv "$file" "${file%$oldfile}$newfile"
code....
but I get an error on both of them stating "find: bad option -printf find: [-H | -L] path-list predicate-list"
View 9 Replies
View Related
May 8, 2010
I can do:mkdir messages and then: touch messages/hello.txt Is there a command that will do both - create the directory if it doesn't exist, and then the empty file? Something like: touch -p messages/hello.txt
View 1 Replies
View Related
Jun 28, 2011
Not sure if this is the right place fo this but....I'm just learning to write bash scripts. I'm experimenting on a ubuntu server 11.04 virtual machine.As part of the script I want to automate user creation.Is there a way to check if a user already exists in a script. so i can do something like
Code:
if userexists; then
do this
else
do this instead
fi
View 6 Replies
View Related
Mar 28, 2010
I need to create subdirectories in about 300 existing directories - the subdirectory will have the same name in all 300 existing directories. How do I do this using the mkdir command using a regular expression or globbing?
View 3 Replies
View Related
May 10, 2011
I am trying to exclude multiple directories when using tar. I can do it for just one directory with exclude= directory.I can also do it for multiple directories by typing that code again and again.As you can see im trying to call this variable that has endless amounts of directories in it seperated by a space.. but when run it doesnt work! It will however work if i just put one directory in the variable. Any ideas?
View 2 Replies
View Related
May 15, 2011
I have found ways to tar a directory and exclude certain directories but is there a way to simply tar multiple directories (they are in the same directory) in to one .tgz file?
View 8 Replies
View Related
Aug 5, 2010
I need to find if, in a folder any directories exist, except a certain one named "mes croquis".What I am trying to say, is that the re already is a directory named "my croquis", which I have to ignore. IF any other directory appears, I have to archive them.I got everything so far, except the starting condition.In other terms , I am lookign for something like this:
IF anyDir EXIST AND name != "mes croquis"
do something
else
[code]....
View 2 Replies
View Related
Feb 1, 2010
I have 60+ directory's each containing multiple .doc files. I need to move them to a single directory and keep their file name intact. I don't think cp will do that with out listing all the file names. I was thinking of something like: cp -r /dir/*.doc /newdir . Or should I use a combo like find -type *.doc|cp /newdir?
View 5 Replies
View Related
May 20, 2010
I found a script on webmaster world that mostly does what I need it to, but have been making modifications to tailor it to my specific needs.I know that //..*/ tells awk to ignore hidden directories, how do I define more directories to ignore? (i.e. temp, var, etc)? I've tried playing with prune before the awk command with limited success...I know that there are many ways to do the same thing and keep running into brick walls.
View 11 Replies
View Related
Mar 15, 2010
I have hundreds of directories in various subdirs that I need to remove. I want to remove all of these dirs, but can only find solutions on how to do remove files (or how to remove subdirs from within the current dir).
I think I need something like
find -iname 'testfile*' | xargs rm -i
where I want to remove every directory that contains the word 'testfile' within the directory name. I know xargs wont work for dirs,
View 9 Replies
View Related
Aug 31, 2010
Need to replace the following string :
By
In multiple .exp files and in sub directories.
View 5 Replies
View Related
Jun 17, 2010
I'd like to move a selection of files from all the sub-directories within an overall directory to a single destination. I don't want any of the directory structure, just the files themselves. This is what I tried so far:
mv /dir1/*/igs*.sp3.Z /dir2
There are other .sp3.Z files in the * directories within /dir1 but I just need the ones that start with igs..
View 4 Replies
View Related
Jan 30, 2009
I'm not sure if this is possible or even where to start. I assume that this can be done with an sh script using tar or similar.I have several very large zip files that contain images for all of the products in my online store. Each image is named after its 13 digit SKU (for example, 9987788000012.jpg). In order to import products into my store, all images are placed into a media directory. Unfortunately, there are over 100,000 images.
So I would like to break the images into sub-folders based on file name. For example, when I extract store_images.zip (or tar or whatever), my extract script would create directories (if they don't already exist) based on the first three digits of each image name, placing each image into the appropriate bottom level directory. For example, "9987788000012.jpg" would be placed in the following directory "media/9/9/8", with media as the root and "8" as the directory that holds any images that start with "998". Perhaps two sub-folders would be less cumbersome.Assuming this requires a script, particularly since it involves scanning image names, creating folders, and saving images to specific directories, which language would serve my needs best? PHP? Has anyone had to do something similar?
View 13 Replies
View Related
Apr 11, 2011
I have 5 FTP users that upload files (and subdirectories) in their home directory, i need to mirror theese directories beetween them and with a "master" directory (accessible from a 6th user). Files can contain spaces or others special caracters. All the files are in the same filesystem, and i want to use hard link because i don't want to waste 5 time the space of a single file. I tried with find but i cannot handle spaces in it.
View 1 Replies
View Related
Nov 5, 2010
I am attempting to copy a set of sub folders from their multiple parent directories to a new location.
For example, I have three folders to copy:
I would like them to be copied to:
In actuality there are many folders besides folder1, folder2, folder3, and no numerical order exists. So, the folder named 'photos' would be copied to its parent folder's name in a new location. I would need this to occur for all folders in the '/home/user' directory.
View 6 Replies
View Related
Sep 30, 2009
Description: I am a newly appointed system engineer taking care of linux servers. We have a new set of data coming in which need below configuration: How to do a script with function?:
for files with ".txt" in sm
copy each of the files to folder : sm1 and sm2 (log every copy)
if succesful:
remove original
log into the log file
if not successful: (not successful copying 1 particular file to all the folders)
retain and retry
log into the log file
mail out the admin with that particular file name
I have already do try a bit:
cd /export/home/
for dir in sm1 sm2; do
cp -p sm/*.txt $dir/
done
Is my starting right? How to do the rest parts?
View 6 Replies
View Related
Apr 8, 2010
i am searching a string(with multiple words) in a file that file contains the string but words are separated with multiple white space.
ex: pattern to be matched "hello how are you" all single white space and file contains " hello how are you" variable white space between words
grep "pattern" file_in_which_to_search i am reading the "pattern" so i cannot modify the "pattern"
so my pattern match does not take place, though i want it to match.
View 3 Replies
View Related
Jan 31, 2010
I need to replace ":" from multiple files names, since I am going to copy those files from a linux partition, which admit the ":" to a FAT32 partition, which does not.
Example:
original name: eg06_ana_21-05-06_09:21:03.JPG
wished name: eg06_ana_21-05-06_09-21-03.JPG
I have googled a lot but I have not been able to adapt the examples given by people to my aim.
It seems that rename command is what I should use, but I have no idea to build the correct pearl expression.
View 3 Replies
View Related
Aug 25, 2009
How can you create a script to move or copy files from a main directory into multiple directories below the main directory.
View 7 Replies
View Related
May 11, 2009
I'm facing this problem since a month on Fedora 10. I have some 45 packages for upgrade through KPackageKit which belong to KDE.
While I give it to upgrade, it gives me a strange message which says
Multiple packages exist that are not compatible with each other.
This is usually due to mixing packages from different software sources.
When I press the details button, I get these details.
ERROR with rpm_check_debug vs depsolve:
libkwalletbackend.so.4 is needed by kdebase-runtime-4.2.0-7.fc10.i386
Please report this error at [URL]
I get this message only for the KDE packages. I have libkwalletbackend.so.4 in my /usr/lib directory.
View 1 Replies
View Related
Apr 16, 2010
I have a directory tree with lots of folders. I need to gather all files of same type, say .txt, and place them in a different folder all by themselves.
I know I can use the mv command, but it won't let me go through all the subdirectories of my folder, just the current one. How can I search through all subdirectories for all .txts or whatever and move them to a folder of my choosing?
View 2 Replies
View Related
Dec 19, 2009
i am in need of linux help. iam at college and i need this back/restore script to pass this final part of an assessment. i require a backup script that will not only backup but also restore files to the relevent directories. e.g. users are instructed to store all wordprocessor files in a directory named wp. so i am needing to create a backup directory and 3 directories within that and some files within the 3 directories and then back them up ot restore them. l know i should/have to do this myself by been trying to get/understand info for the last few days and came up with zero.
View 14 Replies
View Related
Apr 21, 2011
So I have a share hosting account with 60 sites all running wordpress.
There is a plugin I want to delete from all 60 wordpress sites.
The plugin is in the same path in all 60 sites.
mysite.com/wp-content/plugins/carter Is there a way I can search the entire home directory with filezilla or another ftp and delete every folder with that name in every site or I have to do it the tedious 1by1 sucky way?
View 4 Replies
View Related
Apr 16, 2010
I currently have samba setup and connecting. What I am trying to do is have multiple users with access to different directories. For example , let's say there are folders A B C on my Linux machine. I want one guy to see A and C and another guy to see B and C and a third guy to see them all. But I want each user to have access to change delete or execute the files within these directories that they have access to
View 4 Replies
View Related
Jan 25, 2011
What I need to do is gather a bunch of log files from various directories and move them into one spot. Below shows the directory structure.Quote:
dir1
-a.log
-b.log
[code]....
View 4 Replies
View Related
Feb 4, 2010
I become to use tar with incremental feature for archiving data under ubuntu.But when I try to extract archive later under windows (using gnu tar also) it creates many directories like this:
<...>
11324447220
11324447221
[code]...
View 2 Replies
View Related
Jan 21, 2011
I have two non-system drives with archive files. Each drive is formatted with one primary partition only, occupying all the drive space. In each drive there will be a number of directories with files in them, like this:
Drive 1:
/directory1/directoryXXX/files
/directory2/directoryXXX/files
/directory3/directoryXXX/files
Drive 2:
/directory4/directoryXXX/files
[Code]...
View 2 Replies
View Related
Mar 23, 2011
I am writing a script, in that my requirement is, if all the fill types stored in one directory from that we need to separate different different directories based on the file types.
for example in a directory(anish). 5 different types files
1- directory
2- .txt files
2- .sh files
like that and my requirement is the (1- directory is moved to one new directory(dir) which we are given in the script)and (2 .txt files are moved to another new directory(test) which we are given in the script)and ( 2 .sh files are moved to another new directory(bash) which we are given in the scrip)finally the directory anish should be empty..using bash script.how it is possible !!
View 7 Replies
View Related