Click to See Complete Forum and Search --> : Command line to sort files


satimis
06-28-2005, 01:04 AM
Hi folks,

I have following files inside a directory, e.g.;
/parent_directory/
package-01
package-02
package-03
etc.
file-01.patch
file-02.patch
file-03.patch
etc.

What single command line shall I use to send all .patches to a new sub_directory
/parent_directory/patches/

and all packages to a new sub_directory
/parent_directory/packages/

respectively. Both sub_directories have to be created in executing the command line.

TIA

B.R.
satimis

Gertrude
06-28-2005, 01:47 AM
mv /some/directory/*.patch /some/other/directory/patches/

satimis
06-28-2005, 02:17 AM
Hi Gertrude,

Tks for your advice.

Tried following command lines but failed

# cd /parent_directory/
# mv /parent_directory/patches/*.patch /parent_directory/packages/
mv: cannot stat `/parent_directory/patches/*.patch': No such file or directory

# mv *.patch /parent_directory/patches/ ; * /parent_directory/packages/
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
bash: autoconf-2.59.tar.bz2: command not found

B.R.
satimis

Gertrude
06-28-2005, 02:32 AM
Well the directories need to exist before you try moving files there..

Is this a real directory or just something you are making up? "/parent_directory"



mv /sourcelocation/*.patch /destination/patches/

if /destination/patches/ does not exist..


mkdir /destination/patches/ ; mv /sourcelocation/*.patch /destination/patches/

satimis
06-28-2005, 04:05 AM
Hi Gertrude]

Is this a real directory or just something you are making up? "/parent_directory"The real directory is '/mnt/lfs/source/'

mkdir /destination/patches/ ; mv /sourcelocation/*.patch /destination/patches/Noted. That meant 2 commands combined together.

If need to move remaning files to ~/packages then

mkdir -/patches ; mkdir -/packages ; mv /sourcelocation/*.patch ~/patches/ ; mv /sourcelocation/* ~/packages/
would follow work
mkdir -/patches -/packages

B.R.
satimis

Gertrude
06-28-2005, 04:38 AM
Just try to use the commands and see if it works or not. Look at the error, and see if it gives you any hints as to the source of the problem.

Your mkdir commands will not work with a dash in front of the directory tree as it will try to pass "-/patches" into the command as a option. Maybe you ment to use a ~ instead?

satimis
06-28-2005, 05:48 AM
Hi Gertrude,

Tried following command line without success;

# cd /parent_directory
# mkdir ./patches ./packages ; mv *.patch ./patches/ ; mv * ./packages/
mkdir: cannot create directory `./packages': File exists
mv: cannot move `packages' to a subdirectory of itself, `./packages/packages'

# ls
packages

# ls ~/packages/
autoconf-2.59.tar.bz2 groff-1.19.1.tar.bz2
......
All packages and read files moved to this directory and a subdirectory '/patches' was created here.

# ls ~/packages/patches/
All patch files moved to this directory

Your mkdir commands will not work.....Sorry it was my typing mistake. It should be '~'

B.R.
satimis

techwise
06-28-2005, 01:12 PM
Are you having Justlinux do your homework for you?

bwkaz
06-28-2005, 06:53 PM
It looks like he's trying to get through the LFS book, not do homework (though I could be wrong).

I'm guessing you're between chapter 5 and 6, right? Where you need to move the tarballs and patches to the new partition, so you can get at them after doing the chroot?

# mkdir ./patches ./packages ; mv *.patch ./patches/ ; mv * ./packages/ Well, let's see what this does, one command at a time. First:

mkdir ./patches ./packages

Makes two directories. You got a warning from this command because one of the directories already existed, but that's no problem.

mv *.patch ./patches/

Moves every *.patch file into the just-created patches directory. No problem here.

mv * ./packages/

Moves EVERY file, which includes the ./patches/ and ./packages directories, into the ./packages directory. You got another warning here (about not moving packages to a subdirectory of itself), but you also moved the patches directory that you had just created.

This is why your file tree looks like:

+-parent_directory
|
+-packages
|
+-patches
| |
| +-all *.patch files
|
+-all *.tar.* files To fix it:

# cd /parent_directory
# mv ./packages/patches . This will move the patches directory back to where I think you wanted it.

satimis
06-29-2005, 01:09 AM
Hi bwkaz,

Yes, you are right. I'm building LFS on a FC3 box and from it to make my LiveCD later.

As curiostiy I was first trying to discover whether there are flags on 'Tar' command which will direct the files to respective designated directories during extraction. Unfortunately I could find them. Late I switched my searching to a 'single and simple' command line to do the job. In fact it is quite simple to complete this job, just untar the tarball and moving the files around in 'Konqueror'. It is solely to learn something new for myself.

mv * ./packages/

Moves EVERY file, which includes the ./patches/ and ./packages directories, into the ./packages directory. You got another warning here (about not moving packages to a subdirectory of itself), but you also moved the patches directory that you had just created.Ah, noted with thanks. I tried to find an '--exclude' flag on 'man mv' with no result. Is there any other way?

# cd /parent_directory
# mv ./packages/patches . This will move the patches directory back to where I think you wanted it.Noted with thanks

TIA
satimis

bwkaz
06-29-2005, 06:14 PM
My system's mv command does not take an --exclude command line option. It's also not in the manpage or info page for mv. Hmm...

In this specific case, I'd do something like:

mv *.tar* ./packages/

to get all the packages into that directory. That way it won't match the "patches" directory, but will match all the tarballs.

satimis
06-29-2005, 09:25 PM
Hi bwkaz,

Tks for your advice.

mv *.tar* ./packages/

to get all the packages into that directory. That way it won't match the "patches" directory, but will match all the tarballs.I tried this trick before. However there are some read files which still have to be moved manually.

Up to now in my personal opinion the simple and straight-forward method is extracting the parent_tarball and moving files around in Konqueror as 'root'

B.R.
satimis