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.
Hi,
Please help me how can I display the unique/distinct file name from ls in linux. Will appreciate if you could let me know the exact command in order to get the below mentioned result.
The distinct output should only list the starting name list only for example only one charlie, only one tango and only one alpha like below one :
[example@informatica-srv1 test]$
-rwxrwxrwx 1 etl etl 937 Sep 13 22:00 charlie13150913_111_222629.unl
-rwxrwxrwx 1 etl etl 186 Sep 11 01:44 tango20150911_117_112263.unl
-rwxrwxrwx 1 etl etl 186 Sep 21 01:44 alpha20150921_123_033924.unl
Above output is what i am looking for, Again I need only one charlie, tango, alpha from the below mentioned output
Please do not cross post duplicate thread here, I've asked that the duplicate thread be closed and that this one be used to address your question.
Firstly:
- What have you tried on your own?
Have you tried a script?
Have you tried different forms of the ls command?
Have you tried date qualifiers for files, or different regular expressions to filter the output as you'd like it?
You've shown example only and there can be multiple interpretations of what one, singular file you wish to identify out of a directory of many files, and further, your directory may contain a much larger variety of files beyond that limited example, so please think about a better problem description.
And finally, realize that this does appear like a homework or assignment question and if so, it is not policy for LQ responders to provide assistance with those beyond helping you beyond a blocking point, and where you've shown some effort in the first place. So if you really are just experimenting and trying to figure stuff out, go back to the part where you should illustrate some of your efforts, and next offer some explanations on a better scoping of the problem, and also state why you are attempting this particular problem. Some of the questions I've asked above can at least provide you with possible directions in exploring a solution.
I'm not doing homework either, done with that twenty years ago but I got bored - so in a directory looking like this:
Code:
total 0
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_10325_7wzQsU.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_10331_cA7TpG.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_12135_9oQG3V.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_14529_XrhYSJ.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_14810_Ndu6J3.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_16052_uJKCn9.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_21120_Ge7ySU.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_21779_Wd3qI0.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_2646_Qb7aPy.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_6418_v3MUx4.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 alpha20150921_7816_DJeBvq.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_17713_4oUIbb.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_20261_3uj2JL.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_20316_fgWEik.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_22347_fXxoiT.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_24964_TpJSJa.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_29040_hg41Hx.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_30206_y2EQLN.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_30671_NJvI4G.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_31925_FGcN1U.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_8281_RplZ9X.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 charlie20150921_9981_KgBx4q.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_10997_LK5bKL.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_12670_tgsCMs.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_14430_gQ2Yus.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_18753_9y9dxw.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_23467_xPE1XC.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_27802_EOy3uz.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_2799_2tUT04.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_279_VEvy7h.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_4870_ZYMk6Z.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_6156_w9l3uP.unl
-rw------- 1 anthony anthony 0 Sep 21 14:18 tango20150921_9364_cweOP7.unl
just for sh*** and giggles, my one liner produces:
Code:
anthony@serenity: ~/tmp/tmp_working $ ls | <binutils-fu>
alpha20150921_10325_7wzQsU.unl
charlie20150921_17713_4oUIbb.unl
tango20150921_10997_LK5bKL.unl
I can also have it produce the first file entry, any entry for each prefix, whatever...
ETA: I'm not using awk like grail. BTW grail I had mine first, but forgot to hit submit. ;P
Although this particular geek gave up that contest a long time ago. My code might be longer, but as long as it is easy to read and to modify, I am content.
Please do not cross post duplicate thread here, I've asked that the duplicate thread be closed and that this one be used to address your question.
Firstly:
- What have you tried on your own?
Have you tried a script?
Have you tried different forms of the ls command?
Have you tried date qualifiers for files, or different regular expressions to filter the output as you'd like it?
You've shown example only and there can be multiple interpretations of what one, singular file you wish to identify out of a directory of many files, and further, your directory may contain a much larger variety of files beyond that limited example, so please think about a better problem description.
And finally, realize that this does appear like a homework or assignment question and if so, it is not policy for LQ responders to provide assistance with those beyond helping you beyond a blocking point, and where you've shown some effort in the first place. So if you really are just experimenting and trying to figure stuff out, go back to the part where you should illustrate some of your efforts, and next offer some explanations on a better scoping of the problem, and also state why you are attempting this particular problem. Some of the questions I've asked above can at least provide you with possible directions in exploring a solution.
This is not any assignment. If you can help then let me know the command otherwise its fine. Below is what i did but could not make the desire output. Its shows the format types only but could not display like the one i am looking for
Although this particular geek gave up that contest a long time ago. My code might be longer, but as long as it is easy to read and to modify, I am content.
If you can fix it then please let me know the command.
What you did will only print the extension, using the field separator (-F) ".", $NF is the last field, the extension in this case. Did you mean "/" (separate filename from path)?
I am looking from command specially through ls but not through script. Please help
Well, since my solution IS a script, you will probably be better off asking the awk-ninjas. Although now I am curious myself and will try a oneliner when I get the time!
Not much chance of a decent answer if the requirements change. First post was "ls -ltr", now "ls *.*" - that changes the input data markedly. And also the result for me as I never (re-)sort a users data unless requested to do so.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.