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.
Due to shell globbing, the command line is expanded with all the files matching the pattern, such as "ls xyz1 xyz2 xyz3 xyz4 ..."
If there are too many files matching the pattern, the shell runs out of memory.
As an alternative you can use:
find ./ -maxdepth 1 -name "xyz*"
The same problem can occur in a for loop like this:
for file in xyz*; do
command(s)
done
For this you can use find and xargs:
find ./ -maxdepth 1 -name "xyz*" -print0 | xargs -0 -L 200 <command>
When you enter this command, the shell tries to expand the pattern xyz*, and then pass the resulting expanded list to ls as arguments. There is a limit to the length of the list of parameters which may be passed to a program, although it is pretty big. See here for more information.
I suspect you have a very large number of files which match the pattern xyz*, exceeding this maximum.
The limitation is in bash itself. Don't worry though, you can use other programs to work around this problem. For example, this command should do what you want:
I'm trying to compress the files starting with the String "xyz", when i gave the following command, the system again gave me the message "Arguments Too Long" .
tar -cvf My_Files.tar xyz*
So i used the following command instead
tar -cvf My_Files.tar find ./ -name "xyz"
The problem with this is that it copies all the files present in the current directory and compresses them.
Can anyone please tell me how i can modify the command so that it only includes those files which match the string.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.