Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm doing the following command which gives me all the matching entries,but i'd like to see only the filename,not the full path,so i'm doing this..
[root@accountingdb scripts]# ls --format single-column /var/www/html/CSA20June/B_Berg/*20080620*
but i only want the filename(ipB_Berg200806200001.cgi) returned.
IS there some way in ls to throw away the full path, and only list the filename? I went through the man pages, but i could not find anything. I've tried some pipe commands to grep as well, but my grep skills is not nearly good enough it seems.
ls -1 is what you're actually doing (-1 overrides the other parameter)
Neither of those work on my machine...
$ ls /home/user/comps/srv1/chassis/*
$ ls -1 /home/user/comps/srv1/chassis/*
$ ls -m1 /home/user/comps/srv1/chassis/*
$ ls /home/user/comps/srv1/chassis/* | xargs -n1 basename
The man page for -1 says "list one file per line" and for -m says "fill width with a comma separated list of entries", neither of which claim to do what the OP is asking, and neither of which actually do what the OP is asking either (at least not on my machine).
Last edited by suicidaleggroll; 06-14-2013 at 05:02 PM.
Well, yes, you shouldn't really parse the output of 'ls', because it can, potentially, be quite variable over releases and with different set-ups, but just this once...
i) Does 'ls -D -1' do what you are asking for? I can't say that I know all that much about 'dired' mode, but superficially the output looks quite similar to what you are asking for, once it has been put into single column mode. Obviously, all the warnings of imminent doom, bad karma and possibly even garden gnomes and stone cladding, from the wooledge link apply.
ii) If you were going to parse the 'path...filename' output to just give 'filename', you would want to use 'basename' to strip, errr, the basename from the full path string (while busily noting, but ignoring for this application, its partner 'dirname'). I don't see any case whatever for doing this, but you should probably note the existence of basename/dirname in case that you have need of them, in future.