How to use ls with pattern and including path?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use ls with pattern and including path?
# 8  
Old 08-20-2014
Are you sure you are not using *abc*.txt ?
abc*.txt WILL all start with abc...

Manually using CygWin...
Code:
AMIGA:~> cd /tmp
AMIGA:/tmp> ls st*
stackit.sh  string_shift.sh  strings.sh
AMIGA:/tmp> ls *st*
kbstore  stackit.sh  string_shift.sh  strings.sh  sub_str.sh
AMIGA:/tmp> _

Show us a copy'n'paste of what you input and what results you see...
# 9  
Old 08-20-2014
You man find stat a little easier to get file attributes than parsing the ls -l output:

Code:
$ stat -c "size: %s mod-epoch: %Y file: %n" I*
size: 182412 mod-epoch: 1392406500 file: Invoice 266.pdf
size: 185593 mod-epoch: 1392407640 file: Invoice 267.pdf
size: 183923 mod-epoch: 1393205880 file: Invoice 268.pdf

# 10  
Old 08-20-2014
Hello wisecraker,

Thanks for the answer. Yes, I'm entering without *abc*.txt. I've tried in cygwin and it works, only in the other system prints
others files that not begin with abc. Maybe an issue with the ls of that system.

Hello Chubler_XL,

Thank you. I didn't use stat before, it works very nice. Only one question.
If I send the command from another directory I need add the path like below, but in the output
appears the filename concatenated with the path (Myfiles/files01/filename):
Code:
$ stat -c "size: %s mod-epoch: %Y file: %n" Myfiles/files01/abc*
size: 5 mod-epoch: 1408573510 file: Myfiles/files01/abc-bmns1.dat
size: 5 mod-epoch: 1408573510 file: Myfiles/files01/abc-bmns11.dat
size: 5 mod-epoch: 1408573510 file: Myfiles/files01/abc-bmns113.dat
size: 5 mod-epoch: 1408573510 file: Myfiles/files01/abc-bmns114.dat
size: 5 mod-epoch: 1408573510 file: Myfiles/files01/abc-bmns115.dat

How to print the only the filenames without the path?

Like this:
Code:
size: 5 mod-epoch: 1408573510 file: abc-bmns1.dat
size: 5 mod-epoch: 1408573510 file: abc-bmns11.dat
size: 5 mod-epoch: 1408573510 file: abc-bmns113.dat
size: 5 mod-epoch: 1408573510 file: abc-bmns114.dat
size: 5 mod-epoch: 1408573510 file: abc-bmns115.dat

Thanks again.

Regards
# 11  
Old 08-20-2014
The same as with ls: cd into the folder first:

Code:
$ cd Myfiles/files01/
$ stat -c "size: %s mod-epoch: %Y file: %n" abc*

# 12  
Old 08-20-2014
Quote:
Originally Posted by Ophiuchus
Hello wisecraker,

Thanks for the answer. Yes, I'm entering without *abc*.txt. I've tried in cygwin and it works, only in the other system prints
others files that not begin with abc. Maybe an issue with the ls of that system.
I repeat:

It has NOTHING to do with ls.

Absolutely nothing whatsoever.

Using * in that fashion is a property of the shell.

One weird property of Cygwin though -- it has case insensitive filenames, because Windows does, it's unavoidable. Any decent UNIX or UNIX-like has case-sensitive filenames, and will be more picky.

In short, if you don't want to match *abc*, don't use *abc*.
# 13  
Old 08-20-2014
Quote:
Originally Posted by Chubler_XL
The same as with ls: cd into the folder first:

Code:
$ cd Myfiles/files01/
$ stat -c "size: %s mod-epoch: %Y file: %n" abc*

Thank you Chubler_XL for your help!

Quote:
In short, if you don't want to match *abc*, don't use *abc*.
Hello Corona688,

* In Cygwin if I use abc*.txt I get exactly only files that begin with abc.
* In Linux machine (2010 x86_64 x86_64 x86_64 GNU/Linux) where I have the real files I want to list, when I use abc*.txt I get files that begin with abc and files that contain abc but begins with numbers or other letters (i.e. 17abc-khj.txt, 01xabc-ui.txt). Maybe is the shell like you say.

Thanks again
# 14  
Old 08-20-2014
Quote:
Originally Posted by Ophiuchus
Thank you Chubler_XL for your help!


Hello Corona688,

* In Cygwin if I use abc*.txt I get exactly only files that begin with abc.
* In Linux machine (2010 x86_64 x86_64 x86_64 GNU/Linux) where I have the real files I want to list, when I use abc*.txt I get files that begin with abc and files that contain abc but begins with numbers or other letters (i.e. 17abc-khj.txt, 01xabc-ui.txt). Maybe is the shell like you say.

Thanks again
Please show us your entire script. What shell are you using on Linux? With default options, abc*.txt should only match files with names starting with abc and ending with .txt.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete a pattern including any whitespace before it and after it

Hello. A_LIGNE="cnezJ,V ,FMZ fd,Mok CODKJ,F SOME_WORD fcnQ, VMQKV Q" A_PATTERN="SOME_WORD" sed 's/'$A_PATTERN'//g' <<< "$A_LINE"will remove 'SOME_WORD' and give : "cnezJ,V ,FMZ fd,Mok CODKJ,F fcnQ, VMQKV Q"A_PATTERN="SOME_WORD]" sed 's/'$A_PATTERN'//g' <<< "$A_LINE"will remove... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

Comment all lines which are not already commented for each full path pattern matched

Hello. Question 1 : I want to comment out all lines of a cron file which are not already commented out for each full path pattern matched. Example 1 nothing to do because line is already commented out; pattern = '/usr/bin/munin-cron' # */5 * * * * munin test -x... (3 Replies)
Discussion started by: jcdole
3 Replies

3. Shell Programming and Scripting

Find and replace the path value in files, pattern is not full known.

Hi, I need to do find and replace, but the pattern is not full known. for example, my file has /proj/app-d1/sun or /data/site-d1/conf here app-d1 and site-d1 is not constant. It may be different in different files. common part is /proj/xx/sun and /data/xxx/conf i want to find where ever... (6 Replies)
Discussion started by: rbalaj16
6 Replies

4. Shell Programming and Scripting

Pattern match a path anywhere in the line and replace it with new path

I want to pattern match only path part from below and replace them with new path string. LoadModule jk_module /fldrA/fldrBaf/fldrCaa/modules/mod_jk.so JkWorkersFile /fldrA/fldrBaf/fldrCaa/config/OHS/ohs1/workers.properties JkLogFile... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

Including EOL in egrep pattern for multiple lines

Hi all I need your help to get a high-performance solution. I am working on a extensive script to automate file restores using the bprestore tool on a Solaris 5.10 server (bash 3.00). I will only paste the needed parts of the script to avoid any confusion. To use the script the user has to... (2 Replies)
Discussion started by: Anonym
2 Replies

6. Shell Programming and Scripting

Find file and zip without including directory path

Does anyone know of a way to zip the resulting file from a find command? My approach below finds the file and zips the entire directory path, which is not what I need. After scanning the web, it seems to be much easier to perform gzip, but unfortunately the approach must use zip. find `$DIR`... (5 Replies)
Discussion started by: koeji
5 Replies

7. Shell Programming and Scripting

remove contents including the tag if pattern matches

Hi all, Can anyone help me on this. I have several WP sites that are affected by sql injections. But the contents are different as follows western union india belgaum western union india bolegaon western union india barhaj western union india budhana western union india belda western... (6 Replies)
Discussion started by: sanjuabraham
6 Replies

8. Shell Programming and Scripting

Search for Pattern and Print including Lines in between

Gurus, I have a big file that needs to be sorted out and I cant figure out what to do. The file name is as below: Name: xxxx yyyy nnnn Description: dfffgs sdgsgsf hsfhhs afgghhjdgj fjklllll gsfhfh Updated: jafgadsgg gsg Corrected: date today The file consists of line like these. ... (13 Replies)
Discussion started by: The One
13 Replies

9. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

10. Shell Programming and Scripting

Reading a path (including ref to shell variable) from file

Hi! 1. I have a parameter file containing path to log files. For this example both paths are the same, one is stated directly and the second using env variables. /oracle/admin/orcl/bdump/:atlas:trc:N ${ORACLE_BASE}/admin/${ORACLE_SID}/bdump/:${ORACLE_SID}:trc:N 2. I try to parse the path... (1 Reply)
Discussion started by: lojzev
1 Replies
Login or Register to Ask a Question