List files and folders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List files and folders
# 1  
Old 12-07-2009
List files and folders

Hi,

How do I simply get a list of all files and folders in a directory with their asscoiated absolute path and then append it to a file? I need the path to be associated to each and every file/folder.

I have tried the usual ls command but it simply just gives a list of names per absolute path

Thanks
# 2  
Old 12-07-2009
Code:
find /complete/path/here -print |
while read fullpath ; do

  file=${fullpath##*/}
  echo $file $fullpath

done >> some_log_file

should do the trick.
# 3  
Old 12-07-2009
Thanks for this, does it matter what shell script I use?
# 4  
Old 12-07-2009
this is ksh. might work in sh and bash. not csh.
# 5  
Old 12-07-2009
How can you do this recursively too, listing all sub-directories?
# 6  
Old 12-09-2009
One way:

Code:
#! /bin/bash

BASE="$1"
for FILE in $( ls -1 $BASE )
do
  echo "$BASE/$FILE" >> LISTING
  if [ -d $BASE/$FILE ]
  then
    bash list.bash "$BASE/$FILE" 
  fi
done
exit 0

# Usage: bash list.bash [path]
# E.g.: bash list.bash /a/path

# 7  
Old 12-09-2009
The following find will give, filename & absolute path. sed does the format as you required...

Code:
find /path/to/dir -print -exec basename {} \; | sed -ne 'h;n;G;s/\n/ /;p'

  • find gives the filename & absolute path name. ( FILENAME\nABSOLUTEPATH )
  • sed does the 1st & 2nd line exchange, remove \n, and then prints it correctly as expected.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to list all folders in a specific directory

The below bash is trying to list the folders in a specific directory. It seems close but adds the path to the filename, which basename could strip off I think, but not sure why it writes the text file created? This list of folders in the directory will be used later, but needs to only be the... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

3. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

4. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

5. Shell Programming and Scripting

get a list of folders and find files older than...

I am trying to get a list of folders contained in a given directory and would then like to delete any folders/files older than 60mins. So far I am able to get the list of folders using: ls -l /home/uploads | grep '^d.*' the output: drwxr-xr-x 6 flk flk 4096 2010-02-11 13:30... (2 Replies)
Discussion started by: flk
2 Replies

6. Shell Programming and Scripting

Delete file from list of folders

Hi all, I amd new in UNIX programming. I have a query. I need to delete some files (like .dec files) from some folders. I have a list of folders. What will be command for it. Please help me. Thanks in Advance. (3 Replies)
Discussion started by: eclairs
3 Replies

7. Shell Programming and Scripting

Help needed to transfer list of files to FTP server, to different folders

Hello Unix Gurus, Help required from you. My requirement is something like this I want to create a concurrenct program in Oracle Applications using shell script to transfer files from Apps Server to destination FTP server. I have created custom program, where I will extract all the... (4 Replies)
Discussion started by: amazon
4 Replies

8. Shell Programming and Scripting

list only files or folders

Hi experts, i wanna to list either file or folder. please help me Thanks (in advance) :confused:Jagannath (6 Replies)
Discussion started by: jagnikam
6 Replies

9. Shell Programming and Scripting

List Files & Folders created/modified

Hello people, I want to list the files & folders created/modified since a particular date say June 2006. I know I can list recursively thru the folders and use awk to extract the date column to get the desired output. Just wanted to check whether there is an easier way to do this. Please... (2 Replies)
Discussion started by: tipsy
2 Replies

10. Shell Programming and Scripting

list folders but not symbolic links

Hii... I want to list folders (no files and no symbolic links).. But my is giving me error.. please help... Esham (7 Replies)
Discussion started by: esham
7 Replies
Login or Register to Ask a Question