Getting a directory list with a line specifying the number of filenames displayed.
SlackwareThis Forum is for the discussion of Slackware Linux.
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.
Getting a directory list with a line specifying the number of filenames displayed.
Hi: would it be too complicated to have a command line, or maybe a shell script, to make ls print the number of displayed files? Then I could have an alias to invoke it and use it instead of ls.
It's very interesting, thanks. Would it be possible to modify it to make it print size and date/time besides file names? Perhaps a utility that trims off the other data from the output of 'ls -l' (permissions, number of hard links, owners)?
The last line I had no problem in understanding it. The line with sed: $@ is argument #1 (#0 is the command name itself). I do not know sed but I'm sure I will be able to understand the rest of the line (the part after '|') if only you were so kind to give some hints. In that way perhaps I would be able to trim the script to my taste in the case of new needs.
the first part of the line is just ls and his options ($@ means "all the arguments passed to the script").
the part after the pipe ("|") is a sed that substitutes (sed "s/whatever/whatever_else/options") the first (^ match the begin of the line) 13 chars (. means any character -besides newlines) of the output from the ls command with an empty character.
Sed's seems like an atractive man page to study. It only has 280 lines in slackware 14.0 and possible less in older versions. I'll try to invent occasions where to use it to get familiar with it. Thank you very much for your kind posts.
And why two slashes ('/') on the right? They don't balance!
I'll try to explain again: the syntax for the substitution in sed is the above (regular expressions let you substitute the delimiter / with the character you prefer, I usually prefer |)
Code:
sed "s|[text to be substituted]|[final text]|[options for the substitution]"
in the code above, [text to be substituted] is specified as "any 13 chars at the begin of the line", [final text] is empty and there are no additional options for the substitution.
the // above are just two delimiters, that in the case above delimit an empty string.
I now see. 's' is just a search and replace command like in vim. s/first string/second string/ in vim replaces 'first string' with 'second string'. With '^' I am familiar from using regexps with grep. And with '.' of course. This sed seems to be a very nice tool indeed.
Overlapping occurred. Sent when post #11 had not yet arrived at my screen. I will not mark the thread solved in case I have a new question. Again, thanks ponce.
I now see. 's' is just a search and replace command like in vim. s/first string/second string/ in vim replaces 'first string' with 'second string'. With '^' I am familiar from using regexps with grep. And with '.' of course. This sed seems to be a very nice tool indeed.
the syntax is the same, so if you're familiar with vim's regexps you should have a nice time with sed
learning to use these standard tools, like awk, cut, sort (just to cite a few) will help you a lot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.