List files in the current directory - BOURNE SHELL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List files in the current directory - BOURNE SHELL
# 1  
Old 09-20-2011
List files in the current directory - BOURNE SHELL

i am trying to write a program, that will list .txt files and .png files.
it will ask the user what type of files do they want to list! so if the user inputs txt files.. how would you list all the .txt files in the current directory (the directory the program is running)!!

thanks
# 2  
Old 09-20-2011
Welcome to the forum.

You can do something like..
Code:
echo -n 'enter your pattern: '
read p
ls *${p}

Execution:

Code:
$ bash myscript.sh
enter your pattern: txt 
100.txt          250.txt          checklength.txt  create2.txt      infile.txt       op.txt           str.txt          test2.txt
150.txt          arop.txt     create.txt       day.txt          item.txt         outfile.txt      test.txt         testing.txt
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

List all files and directories in the current directory separated by commas and sorted by crtime

What I know so far: ls -A will list all files except those starting with a dot ls -d will list all directories ls -m will separate contents by commas For getting crtimes use: stat filename will give me the inode number or ls -i filename will give... (13 Replies)
Discussion started by: chstewar
13 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

4. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

5. Shell Programming and Scripting

How to strip ^M at end of each files for all files found in current directory

I am trying to use a loop to strip of the funny character ^M at the end of all lines in each file found in current directory and I have used the following in a script: find . -type f -name '*.txt' | while read file do echo "stripping ^M from ..." ex - "$file" > $tempfile %s/^M//g wq! # mv... (4 Replies)
Discussion started by: bisip99
4 Replies

6. UNIX for Dummies Questions & Answers

Bourne shell viewing files in directory

Hi, I have a program that get a directory name from the user, then the program should go through one by one of the file, asking the user whether to move it to another folder. I tried to list the time of the file one by one. But it seems like it doesn't work. The code is as follow: check() {... (10 Replies)
Discussion started by: mInGzaiii
10 Replies

7. Shell Programming and Scripting

mget * (obtein files from current directory but not the files form sub-directories)

Hello, Using the instruction mget (within ftp) and with "Interactive mode off", I want to get all files from directory (DirAA), but not the files in sub-directories. The files names don't follow any defined rule, so they can be just letters without (.) period Directory structure example: ... (0 Replies)
Discussion started by: Peter321
0 Replies

8. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

9. UNIX for Dummies Questions & Answers

How to find the list of 5 largest file in current directory?

Hello, How to find the list of 5 largest(size wise) file in current directory?i tried using ls -l | sort -t " " -r +5 -6 -n | head -5 but this is not giving correct output as ls -l command gives 1 extra line of output that is how many total files are there!so by running the above... (4 Replies)
Discussion started by: salman4u
4 Replies

10. UNIX for Dummies Questions & Answers

List files that are not directories from current directory

I can't manage to list all files that are not directories from current directory. (2 Replies)
Discussion started by: beni22sof
2 Replies
Login or Register to Ask a Question