Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need the equivalent .sh script to Windows batch file that I use:
Nakamichify_16MB.bat:
Code:
@if '%1'=='' goto usage
Chunkerito.exe "%1" 16777216
dir "chunkerito.???,???"/b/on>q
@echo Processing these...
@FOR /F %%i in (q) do @echo %%i
@FOR /F %%i in (q) do "Nakamichi_Ryuugan-ditto-1TB_btree.exe" %%i x 25 13000 i
copy/b *.Nakamichi "%1.NKM"
ren "%1.NKM" "%1.Nakamichi"
"Nakamichi_Ryuugan-ditto-1TB_btree.exe" "%1.Nakamichi" /bench
:finish
goto realend
:usage
@echo Usage: Nakamichify filename
@echo.
:realend
Also, please point out the help resource describing used commands:
- how to concatenate (as binary) files;
- how to handle command line options (the %1 and %2 in Windows);
- how to print files (one-by-one) from a list file;
- how to rename a file.
Having the correct counterpart will allow me to look the right places.
Or if you are interested in using Python, there's resources to review there.
Please understand that people here are volunteers, like yourself, and not necessarily here to write on-demand scripts for you. As you know the way the LQ site works is that you should be learning how to help yourself on technical Linux topics. Therefore some background effort would be very helpful so that people can make script suggestions where you'll understand what they are about.
Quote:
Originally Posted by Sanmayce
Also, please point out the help resource describing used commands:
- how to concatenate (as binary) files;
- how to handle command line options (the %1 and %2 in Windows);
- how to print files (one-by-one) from a list file;
- how to rename a file.
Having the correct counterpart will allow me to look the right places.
Are you familiar with the Linux command line? All of those capabilities are commands which you'd encounter and use as part of the command line on an everyday basis. Afraid I don't have a favorite resource to recommend for the command line, however all of it is highly visible/accessible with web searches.
The problem is that I still don't have a working *nix environment, after some days I intend to play with RUFUS which will make me a bootable LIVE UBUNTU USB stick, hopefully then I will be able to try making the counterpart. I already downloaded the .ISO file but booting UBUNTU and working in its shell is a new thing to me. Also, by "script" I don't know what to expect, I need the basic and portable scripting language, as far as I know, BASH is only one variant, don't know whether it is the standard for common shell tasks as in Windows. Don't need advanced scripting just as a start this one.
#!/bin/bash
function usage
{
echo "Usage ${0} filename"
}
if [ "$1" = "" ] ; then
usage
exit 1
fi
split --bytes=16777216 -d $1 $1_
for f in $1_* ; do
echo $f
done
for f in $1_* ; do
Nakamichi_Ryuugan-ditto-1TB_btree.exe $f
done
# I don't really understand the point of thesecopy and rename lines.
cp *.Nakamichi $1.NKM
mv $1.NKM $1.Nakamichi
Nakamichi_Ryuugan-ditto-1TB_btree.exe $1.Nakamichi --bench
Please note that I don't really understand the point of your original script or the commands used in it.
Thank you ehartman, JJJCR and evo2, that is helpful, learning from actual examples is the way I like to do things.
>Is Virtualbox not an option?
Heard how good it is, but never have seen it, on top of that currently I am limited to using old Windows XP 32bit, kinda all the software seems to deprecate it. Have to try it, but having worked a bit with an old 32bit Knoppix live CD, years ago, I prefer some full fledged environment as UBUNTU, in too many cases I see people using it, maybe it is the primary choice!
When have time, want to have a modern 64bit *nix GCC environment (LIVE - on a RAM drive) with GCC 7.3.0 as a minimum in order to create ELFs (the counterparts for my EXEs).
Exactly what I needed, evo2, will try it when enter the *nix prompt and share whether it does the same as my .BAT file.
> echo "Usage ${0} filename"
Oh, this ${0} actually stands for the executed script name, I guess, nice refinement it is.
>if [ "$1" = "" ] ; then
> usage
> exit 1
Good, just now I saw the counterpartS of handling the parameter and "goto" - using a function within the "batch" is new to me.
>split --bytes=16777216 -d $1 $1_
Oof-oof, nice, never heard of 'split', wonder are the $1_ files "numbered".
># I don't really understand the point of thesecopy and rename lines.
>cp *.Nakamichi $1.NKM
The task is to glue them (in BINARY mode) into $1.NKM, the actual ordering is also important, could you say whether 'cp' copies in binary mode as it is given.
Also, if the first line "#!/bin/bash" is omitted, in order not only bash (but other shells) to be able to exectute it, will it be more "portable" i.e. universal.
See, this script is important to me (to have and share it with a small compression package), since Perl/Python/Bash is Dark India to me, I PREFER some fellow experienced member to write it instead of my crippled attempt done.
># I don't really understand the point of thesecopy and rename lines.
>cp *.Nakamichi $1.NKM
The task is to glue them (in BINARY mode) into $1.NKM, the actual ordering is also important, could you say whether 'cp' copies in binary mode as it is given.
Also, if the first line "#!/bin/bash" is omitted, in order not only bash (but other shells) to be able to exectute it, will it be more "portable" i.e. universal.
If you want to make it more portable you can use /bin/sh but then you should remove any "bashisms".
Quote:
See, this script is important to me (to have and share it with a small compression package), since Perl/Python/Bash is Dark India to me, I PREFER some fellow experienced member to write it instead of my crippled attempt done.
Hmm, not sure what is so special about the compression you are using. There is already a huge number of well established ones to choose from.
I experienced problems with 'cp' and couldn't do it!
My first attempt:
Code:
>cp -v *.Nakamichi q
cp: target `q' is not a directory
My second attempt:
Code:
>cp -T -v *.Nakamichi q
cp: extra operand `Chunkerito.000,003.Nakamichi'
Looked up the man page and couldn't figure out how to copy it, then I had a flashback and remembered 'cat' being somewhat the counterpart of 'type' in Windows:
Code:
>cat *.Nakamichi>q
Looking into current directory, I saw 'q' being exactly the size of concatenated 6 Chunkerito files. Success. Why 'cp' failed me?
Also, I experienced problem with $f, don't know why but instead of 6 instances:
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,001"
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,002"
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,003"
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,004"
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,005"
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,006"
It executed one instance with $f being:
Nakamichi_Ryuugan-ditto-1TB_btree.exe "Chunkerito.000,001 Chunkerito.000,002 Chunkerito.000,003 Chunkerito.000,004 Chunkerito.000,005 Chunkerito.000,006"
In that fragment:
Code:
for f in $1_* ; do
Nakamichi_Ryuugan-ditto-1TB_btree.exe $f
done
Finally, I succeeded in making Nakamichify_32MB.sh:
Code:
./Chunkerito.elf $1 33554432
for f in `ls Chunkerito.???,???` ; do ./Nakamichi_Ryuugan-ditto-1TB_btree.elf $f x 20 14000 i; done
#for f in `ls Chunkerito.???,???` ; do echo $f; done
cat *.Nakamichi>$1.NKM
mv $1.NKM $1.Nakamichi
./Nakamichi_Ryuugan-ditto-1TB_btree.elf $1.Nakamichi /bench
IT WORKS!
>Hmm, not sure what is so special about the compression you are using.
Nothing special really, just a Zennish Microdeduplicator, a natural continuation of Prof. Okumura's shared LZSS.C back in 1989, 30 years later instead of 256 Binary Trees we now can have 2^31 or 2 billion B-trees - to boost the matchfinding. The purpose of Nakamichi is to speed up huge textual traversals (full-text) by reducing the I/O, f.e. if 3 TB DNA files are to be traversed in full-text mode then Nakamichi screams - BUT! You need first a bunch of tiny supercomputers to compress them.
Heh-heh, love koans - the only way to express the truth - via paradoxes:
Funny guys were those Zen/Tao masters, borrowing wisdom from them, my next variant will be named 中道乾屎橛 Nakamichi 'Kanshiketsu' - a multi-threaded (OpenMP) decompressor of these chunks able to compete with the fastest ones.
>There is already a huge number of well established ones to choose from.
A huge number you say, curious I am what is your TOP 5, regarding superfast textual decompression?
These days I am playing with DNA corpora, despite Nakamichi targeting English Texts. A quick look what above script should deliver:
Benchmark machine: Our reference machine is a reasonably standard Linux workstation.
CPU: dual Xeon E5-2643v3 (3.4 GHz, 6 cores)
RAM: 128 GB DDR4-2133 ECC Registered
Benchmark machine for Nakamichi:
Sanmayce's reference machine is a reasonably standard Windows laptop.
CPU: i7-3630QM (3.4 GHz, 4 cores)
RAM: 16 GB DDR3-1600
I experienced problems with 'cp' and couldn't do it!
My first attempt:
Code:
>cp -v *.Nakamichi q
cp: target `q' is not a directory
cp isn't cat.
It has two modes:
EXACTLY two arguments: copy the first filename to the 2nd, optionally to another directory too.
When the first argument contains wildcards (*, ?, etc) it must evaluate to exactly one single filename for this mode to work.
MORE then 2 arguments (your *.Nakamichi probably expands to multiple filenames):
the destination argument must be a directory where to copy all of these files TO, under their present filenames.
So it never will concatenate files together, that is what cat is for, cp will copy files as (separate) files.
For all rookies like me, my suggestions, these are the two books I chose to learn from:
- Apress.Pro.Bash.Programming.Scripting.the.GNU.Linux.Shell.Oct.2009.pdf
- Aho A., Kernighan B., Weinberger P. - The AWK Programming Language - 1988.pdf
The first one is exactly the style I like - a practical cookbook covering many usecases that I need, as if it was written for me :P
Next one, I chose in order to get portability, my inclination is to write sh scripts, not bash ones, also while looking for a way to get the free RAM into a variable found an one-liner using awk:
As far as I get, using 'free' also delivers portability, like such tiny techniques, intend to gather similar ones in order to enrich my sh/awk vocabulary.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.