LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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.

Notices


Reply
  Search this Thread
Old 03-10-2007, 08:29 PM   #1
akamad
LQ Newbie
 
Registered: Mar 2007
Distribution: Debian Squeeze
Posts: 16

Rep: Reputation: 0
Listing all write access files on command line


Hi all.
I'm a bash newbie and was wondering what script/command line command I can use to list all files that I have write access to.
Thanks.
 
Old 03-10-2007, 08:50 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
To do this for all files in the current directory, use this script:

Code:
#!/usr/bin/bash

for xxx in *
do
  if access -w $xxx
  then
    echo $xxx
  fi
done
For something which covers more than one directory, do this:

Code:
man find
Hope this helps.
 
Old 03-10-2007, 09:08 PM   #3
akamad
LQ Newbie
 
Registered: Mar 2007
Distribution: Debian Squeeze
Posts: 16

Original Poster
Rep: Reputation: 0
I tried your script. But unfortunately it says that the "access" command is not found. I'm using Kubuntu 6.06, would that make a difference?
 
Old 03-11-2007, 01:18 AM   #4
rch1231
Member
 
Registered: Mar 2007
Location: Bedford, Texas
Posts: 31

Rep: Reputation: 15
try this:

find . -user <username> -exec ls -lad {} \;

this will give you a list of all files you own in the current directory and below. You can refine it if you want with a few options. The . implies current directory which can be replaced with / if you want to look everywhere you are allowed to.
 
Old 03-12-2007, 04:47 PM   #5
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
To my surprise, I found that whether one has the access command is, indeed distribution-related.

For a more complete solution, and one that gives you a greater working knowledge of Unix/Linux, follow rch1231's solution.

But mine will work on the current working directory if you change it so it doesn't use access:

Code:
#!/usr/bin/bash

for xxx in *
do
  bash -c "cat >> $xxx < /dev/null" 2>/dev/null
  if [ $? = 0 ]
  then
    echo $xxx
  fi
done
 
Old 03-13-2007, 04:58 PM   #6
akamad
LQ Newbie
 
Registered: Mar 2007
Distribution: Debian Squeeze
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wjevans_7d1@yahoo.co
To my surprise, I found that whether one has the access command is, indeed distribution-related.

For a more complete solution, and one that gives you a greater working knowledge of Unix/Linux, follow rch1231's solution.

But mine will work on the current working directory if you change it so it doesn't use access:

Code:
#!/usr/bin/bash

for xxx in *
do
  bash -c "cat >> $xxx < /dev/null" 2>/dev/null
  if [ $? = 0 ]
  then
    echo $xxx
  fi
done
That seems to do the trick at first glance. I'll play around with it as well as rch1231's command. Thank you all.
 
Old 03-14-2007, 11:37 AM   #7
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Something just occurred to me.

In addition to other differences, my solution finds files you can write to; rch1231's solution finds files you own. It's possible for a given file to be in either of those two sets but not in the other.

rch1231's solution is based on the find command. I'm not aware of any option to find which allows you to test whether you have permissions to write to a file.

Last edited by wjevans_7d1@yahoo.co; 03-14-2007 at 11:39 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
command line device listing and info aquaboot Ubuntu 4 05-19-2006 04:15 PM
how to write command line program? vito_huang Linux - Software 3 04-14-2006 12:20 AM
How write new MBR using command line only lonecrow Linux - Newbie 2 11-02-2005 10:17 AM
Can somebody like share me to write files to DVD disc in command line? exper Linux - Software 3 08-11-2004 07:58 PM
Write to MBR while in the command line? EThitop Linux - Newbie 10 05-11-2004 11:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration