Programming :: Bash - Recursive Find - Create Parent Folder - Moving File
Dec 5, 2010
I'm starting bash shell script and I'm looping without any solution.
I'm trying to find some files under a folder hierarchy and in case of errors moving these files to a destination folder under the same hierarchy recreating this hierarchy if not exists.
Finding all ._* files under /src and moving them to /dest recreating folder1 or the others which contains ._* files but without moving files which does not correspond to the pattern.
Code:
I tried find command and I'am getting all needed files
Code:
But I don't know how to use the output to get the parent folder of files which are found to
1- create folder with mkdir -p /dest/folder1 or /dest/folder1/folder4
2- move found files from /src/... to /dest/... with rm command
I'm working on a find command as this trying to do all in the same line but ... little lost
Code:
View 8 Replies
ADVERTISEMENT
Jun 29, 2010
is there a recursive shell or Perl script to delete files with the same name as the parent folder? i wish to include the starting folder name as argument to the script.
View 2 Replies
View Related
Aug 3, 2010
I'm wanting to mod some PHP files across a hierarchy and thought I'd drive it with find + grep + xargs
I built up a command line which I was confident would do the job, but now can't save the results.
First I tried this:
Code:
find . -name *.php | xargs grep serialize | cut -d: -f1| sort -u | xargs sed -i s/serialize/serialise/g
but that didn't work:
Code:
sed: illegal option -- i
so I thought I'd try using
Code:
[Code].....
View 10 Replies
View Related
May 16, 2010
Way to test permissions on all files/folders into a folder recursive, then if those are not user:user then do :
Code:
chown user:user thatconcernedfile
The problem with that
Code:
chown user:user -R /folder
is that it is doing changes on file permissions whihch are already ok. If you wanna maintain a specific permission on a folder this is really not good this :
Code:
while [ 1 ] ; do
chown user:user -R /folder
# /folder contains 6.0 Tb
sleep 2s
done
View 1 Replies
View Related
Jul 29, 2011
I need this script but I don't know how to do it I have one folder with several folders inside.On each folder a have one MKV or AVI file inside...What I need is a script to change the "modification date" of each folder to the "modification date" of each MKV or AVI that the folder has inside.
View 16 Replies
View Related
Aug 2, 2011
how to use find command to search for all the file in the particular folder?my script as below
find . -name "*" > $BASE/file
if [ `more file | wc -l` -gt 0 ]; then
echo "dp"
fi
output of my results will always include a . (dot)which I dunwan it include the dot.
View 11 Replies
View Related
Jul 14, 2011
I am looking for a one liner to search for a string in file(s) which are in a tar ball (.tar.bz2 in my case)
Code:
-bash-3.2$ tar -tjf /var/log/ABC/07142011-1412.tar.bz2
var/log/ABC/07142011-1412/
var/log/ABC/07142011-1412/live_hosts.txt
var/log/ABC/07142011-1412/all_hosts.txt
var/log/ABC/07142011-1412/LOGS.txt
How can I recursively look inside all the txt files in this tar file ?
View 10 Replies
View Related
Apr 17, 2011
write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.
For example. File: PHP Code: PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22)
[Code].....
View 1 Replies
View Related
Feb 14, 2011
I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
View 5 Replies
View Related
Jun 1, 2010
I have a bash script that is tracking ERROR connections (running in a cron every 15 minutes), sometimes the errors are true and are not connecting. But most of the time, the disconnects/reconnects are between 30 seconds are sending out false positives. I am looking for a time comparison code to pick out the 30 second disconnects and know that this is and "ok" error. Here is a section of the log with timestamps, errors, etc.
Tue 2010-06-01 22:01:30 ERROR [DataBufferSendService] 172.31.0.1:8016 caught exception: [NetworkAPI] Exception: [SocketStream] socket error
Tue 2010-06-01 22:01:32 ERROR [DataBufferSendService] 172.31.0.2:8016 caught exception: [NetworkAPI] Exception: [SocketStream] socket error
Tue 2010-06-01 22:02:00 INFO [Client] 172.31.0.1:8016 connecting to 172.31.0.1 on port 8016
Tue 2010-06-01 22:02:02 INFO [Client] 172.31.0.2:8016 connecting to 172.31.0.2 on port 8016
View 8 Replies
View Related
Jun 11, 2010
I have a folderA that contains folderB that contains a lot of files. I would like to get rid of folderB, but not its contents. I want those contents to be inside of folderA. How can I accomplish this on the commandline?
View 2 Replies
View Related
Jan 29, 2010
I have no Bash skills but Im badly in need of a script to move the first 20,000 or whatever number of files from a directory containing over 200,000 files to a new directory. The problem is that I cant access the directory because its so large so I want to break it into chunks, but keep the files in order if possible. If you know of a script to meet my needs, please post it. Otherwise Ill post my fumblings with Bash until I find the right way to fix my problem.
View 14 Replies
View Related
Feb 13, 2011
this is posable but am trying to do this "Create folder from a filename and move the file into the folder" i have 500000+ file's i need to do with is there a easy way?I really don't want to download them all make/move them with filemonkey just to re-upload them
View 2 Replies
View Related
Nov 24, 2010
i want to move a file. User will give (file_name,current_path,destination_path)as command
View 2 Replies
View Related
Jul 26, 2010
Where is my parent folder?
View 1 Replies
View Related
Jun 7, 2010
However, can I run a command and create symbolic links for all files in a given folder and its subfolders and have all the links be in one folder?
I have a file structure such as:
FolderA
FolderB
FolderC
and I want to have symbolic links for all the files in the A, B, and C all in one new folder (FolderALL) for example. I have hundreds of folders that need to be done, so a simple 1 line command would be ideal if possible.
View 13 Replies
View Related
May 23, 2011
Im wondering how to create a menu in c like bash's select. I imagine there is already something out but I don't know what it would be. Im a c newb but been scripting for a long time now and trying to pick up a little c.this would be what I am looking to display:
Code:
1) option 1
2) option 2
3) option 3
Make a selection:obviously 1,2,3 would be the only valid selection and anything else would say invalid or something like that.
View 2 Replies
View Related
May 11, 2011
I use "zip -r" to zip the following folder:
/root/Desktop/administration/backup
....My only grip is that when you open the zip file, the parent directories are there too.
So within the zip file I have to navigate through "/root/Desktop/administration" just to get to the directory called backup.
Is there a way for me to zip the directory backup, and not include the parent directories? I want to be able to open the zip file and see only the backup directory listed.
View 9 Replies
View Related
Feb 5, 2010
I used to be able to open any folder in Nautilus and from there navigate to the parent folder. There was this arrow pointing up that had this function but I don't have the option any more.
View 9 Replies
View Related
May 7, 2011
Im pretty new to linux and Ive hit a wall. I have a folder 'forum'. I need all files and subfolders but I dont want them in forum. I have tried it with the gui, but it wont let me paste them. How do I move all the folder data without moving the folder itself via terminal?
View 4 Replies
View Related
Oct 19, 2010
I want to delete all files within a specific folder without actually deleting the folder, what is a good bash command for this?. I found this one but encountered some errors even though I am executing it within the specific folder:
useratdebian:/home/user/folder# find . -type f -exec rm -rf {} ;
[1] 5052
useratdebian:/home/user/folder# find: missing argument to `-exec'
[1]+ Exit 1 find . -type f -exec rm -rf
The command as it appears is:
find . -type f -exec rm -rf {} ;
how to delete only the files contained within the folder called "folder" for example?
View 4 Replies
View Related
Jun 7, 2011
Question for people good with Bash scripts.
In a script, how do you name a file after a folder?
For example code...
View 9 Replies
View Related
Jul 22, 2010
I have a Directory of files over time the directory has become a pain to manage... Its now a few 100GBs each file has a partner .log file so id would want some logic in keeping these together..So I want a script to move the files into sub-directories with a limit or 4GB and then i'll burn each of the directories to DVD.
View 14 Replies
View Related
Aug 8, 2011
Whenever I go inside a directory in Linux, it shows the file path at prompt like:
root@vivek-HP-Pavilion-dv6-Notebook-PC:/var/www/abc/def/
How can I change it to show short names instead?
View 1 Replies
View Related
Apr 26, 2011
I have setgid permission on my home directory (/home/XXXX) the permission look like below.
Code:
drwxrws--- 2 toshi jadu 4096 Apr 26 16:54 getset
If I create new directory in this getset folder the permission of getset folder could not inherit.
Code:
#cd getset
#mkdir test2
#ls |grep test2
drwxr-s--- 2 toshi jadu 4096 Apr 26 16:56 test2
As I know the setgid utility allow to inherit the permission from parent directory to child directory.
View 4 Replies
View Related
Feb 7, 2011
Is there a Commend to move the content of a folder -only image files no subfolders- to another destination folder?Actully, I had a look on the following post:Post tilte:Using mv to move the content of one directory into anotherFrom it, I tried that:
Code:
# rsync -a SOURCE/ DEST/
But, it copy a folder as all to the distination.
[code]...
View 10 Replies
View Related
Mar 28, 2011
I been using linux for a while, but I havent had the time to really learn it. Something Id like to get more familiar with is bash so here is a simple example of something I would like to do:
I have a directory full of files. For each file in the directory create a new subdirectory with each files name.
I tried this:
#im already in this directory
aaa=./*
for a in $aaa
do mkdir $a
done
One of the problems is that there are spaces () and - in the filenames so I get many subfolders with names like "-" which i don't want.
I tried stuff like:
aaa=./*
for a in $aaa
do mkdir "'"$a"'"
done
This of course also did not work.
Additional I tried just creating a folder with the name of one of the files and I got this:
mkdir: cannot create directory `(audio) - R56339.EXE': File exists
Well yeah a file exsists with that name, but I want to create a folder- why is there a conflict?
Just to be clear here are the contents of this folder:
~/Desktop/LAB/Media/Drivers - (Image Deployment)/Optiplex_GX260/XP> ls
(audio) - R56339.EXE (NIC-Onboard-Intel) - R54402.EXE
(Modem-datafax-V92) - R54403.EXE OEM_Applications
[Code].....
View 1 Replies
View Related
Aug 9, 2010
I'm trying to write a script that will prompt the user for a username/password, then create that user/password in the right groups on all my machines. I know this is kind of a long way around to avoid a NIS server, but I like making my life more difficult.
This is what I have so far:
Code:
the script has 2 problems: The "if" functions return an error and do not compare the strings successfully. whatever password is entered does get applied properly and the user is unable to login
View 7 Replies
View Related
May 18, 2011
shell scripting in Fedora14I want a script"Find in curent folder for files, and it copy first file he find with name gived by user, if name already exist then echo error message and finish"command usage " bash scriptname copyASname"
smthing like Code: #!/bin/bash
for files in /home/user/*
do
[code]....
View 1 Replies
View Related
Mar 28, 2011
I do have an Ubuntu Headless server which is running Samba on it. My mp3 file collection resides on that server on is being share.
So far, no problems connecting to that drive and writing from my Windows box on that share. But if I use my main laptop, which runs Ubuntu Lucid and download an mp3 song from Amazon, the moment I move that to the share, I got permissions problems from the Windows machine. This is clearly a permission issue with group and others; the song is being created on the share without read and write permissions to others or the samba group I created.
My question is. How can I make this process simple or automatic, when moving songs to the share? I don't want to go there everytime and run ...
Code:
Which was basically how I reset or fixed the problem.
I've read about umask, but not sure if that applies here or not, because I'm not creating the file but moving it.
View 5 Replies
View Related