Welcome to Dream.In.Code
Become an Expert!

Join 149,480 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,472 people online right now. Registration is fast and FREE... Join Now!




Unix Shell Script question

 
Reply to this topicStart new topic

Unix Shell Script question

Emper0r
4 May, 2007 - 09:39 AM
Post #1

D.I.C Head
**

Joined: 7 Dec, 2006
Posts: 59


My Contributions
I'm trying to write a shell script tha takes a dir name and a file extention from the user, for example:

~/mydir txt

and returns the absolute pathname and filename and the specific permissions of that certain file, for example:

/home/me/mydir/test.txt -rw-r--r--

I'm very new to making shell scripts, here's what I have so far:

for fileName in `find $1 -name '*'.$2`
do
echo $fileName
done

This returns the absolute path with the filename but I have no idea how to return the permissions on the file. How would I achieve this? Thanks to anyone for help.
User is offlineProfile CardPM
+Quote Post

Nova Dragoon
RE: Unix Shell Script Question
4 May, 2007 - 10:23 AM
Post #2

The Innocent Shall Suffer, Big Time
Group Icon

Joined: 16 Aug, 2001
Posts: 6,145



Thanked: 8 times
Dream Kudos: 515
Expert In: Python, Linux

My Contributions
The ls command in long format "ls -l" shows file permissions as the first column, you could use cut to extract just that column and print it


ls -l filename | cut -f1 -d" "
User is offlineProfile CardPM
+Quote Post

Emper0r
RE: Unix Shell Script Question
6 May, 2007 - 09:00 PM
Post #3

D.I.C Head
**

Joined: 7 Dec, 2006
Posts: 59


My Contributions
QUOTE(Nova Dragoon @ 4 May, 2007 - 11:23 AM) *

The ls command in long format "ls -l" shows file permissions as the first column, you could use cut to extract just that column and print it


ls -l filename | cut -f1 -d" "


Thanks but is there any way to do it via pathname expansion?

Like ls-l filename | awk {print == $1} or something?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:15PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month