Take a files' path with the command 'file' ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Take a files' path with the command 'file' ?
# 8  
Old 10-27-2010
Well, I have umbumtwo at home, if I boot over. What are the file names like:
Code:
ls -l|cat -vte | line

and what do the innards of the info files look like:
Code:
cat -vte <info_file_for_file_from_above>

?
# 9  
Old 10-27-2010
As you understand the deleted files can be any file, the info files of these files looks like:
Code:
[Trash Info]
Path=/home/alex/Desktop/adf
DeletionDate=2010-10-28T00:01:50

I don't know how to get the Path. All other are known. Smilie
# 10  
Old 10-27-2010
hi,
try this:
Code:
find . -type f -exec grep "Path" {} \;

i got output as follows:
Code:
Path=/home/user1/Pictures/Webcam/2010-06-14-203606.jpg
Path=/home/user1/.google/picasa/3.0/dosdevices/z:/home/user1/Desktop/collate/IMG_0197.JPG
Path=/home/user1/.google/picasa/3.0/dosdevices/z:/home/user1/Desktop/collate/IMG_0212.JPG

# 11  
Old 10-27-2010
Are you trying to convert a possible relative path to an absolute path?

Code:
$ readlink -m myfile.txt
/home/chubler/myfile.txt

$ readlink -m /tmp/chub.tmp
/tmp/chub.tmp


Last edited by Chubler_XL; 10-27-2010 at 07:19 PM.. Reason: Another example
# 12  
Old 10-27-2010
MySQL

readlink does the work. Thank you very much!
# 13  
Old 10-27-2010
The more general solution is realpath, which will take any sort of path and give you an absolute path without sym-links.

Man Page for realpath (All Section 1) - The UNIX and Linux Forums

I coded my own for systems lacking it:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

main( int argc, char **argv )
{
	char	buf[PATH_MAX+1];
	char	obuf[PATH_MAX+1];
	char	*cp ;
	int	i = 1 ;

	while (  (  i < argc
                 && (  strcpy( buf, argv[i++] )
                    || 1 ) )
              || ( i == 1
		 && fgets( buf, sizeof( buf ), stdin ) ) )
	{
		if ( cp = strchr( buf, '\n' ) )
		{
			*cp = NULL ;
		}

		if ( !realpath( buf, obuf ) )
		{
			fflush( stdout );
			fputs( "realpath() failure: ", stderr );
			perror( buf );
			continue ;
		}

		if ( 0 > printf( "%s\n", obuf ) )
		{
			if ( ferror( stdout ) )
			{
				perror( "stdout" );
				exit( 1 );
			}

			exit( 0 );
		}
	}

	if ( ferror( stdin ) )
	{
		fflush( stdout );
		perror( "stdin" );
		exit( 1 );
	}

	exit( 0 );
}

# 14  
Old 10-28-2010
Could also be implemented as a ksh/bash script:

Code:
fname=${1%/} # strips trailing '/'
while [ -L "$fname" ]; do
    oldfname="${fname}"
    fname="$(command ls -l $fname)"
    fname="${fname#*> }"
    if [ "$fname" = . ] ; then
        fname="${oldfname##*/}"
    elif [ "${fname#/}" = "${fname}" ]; then
        d=${oldfname#/}
        d=/${d%%/*}
        fname="${d}/$fname"
    fi
done
d=${fname%/*}
d=$([ -d "${d:-/}" ] && cd ${d:-/} ; pwd -P)
echo ${d%/}/${fname##*/}


Last edited by Chubler_XL; 11-21-2010 at 08:13 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

3. Shell Programming and Scripting

make file (include files path)

Hi All, In make file i want to include header files from my local directory and if it did not find in local directory i want to include from network directory. can any help me how i can do this?. here is the code INCLUDE=${include}/ this is point to network dir how i can add option that it... (1 Reply)
Discussion started by: goraya430
1 Replies

4. Shell Programming and Scripting

unzip few files but with same path and file name.

Hi Everyone, For exmaple, i have 5 .zip files. So i can do "unzip -L -o file1.zip -d /home/user1" for every 5 files. But the problem is those 5 zip files, have same path and file name. So if i use "-o", all will be overwirte. The output is unzip all files, but put all unzipped files... (1 Reply)
Discussion started by: jimmy_y
1 Replies

5. Shell Programming and Scripting

command to list files with path & date in a folder

Hi, I need command to display files with full path and date of files where are generated at every 5hrs in a folder. eg: /u01/app/test/orjthsd_1_1 Sun May 10 19:03:26 2009 /u01/app/test/weoiusd_1_1 Sun May 10 21:00:26 2009 thanks saha (3 Replies)
Discussion started by: saha
3 Replies

6. Red Hat

ls command to give full path to files

How can i perform a ls or other command to list the full paths of files from a ls? Looked through the man page for ls, no luck $ cd /tmp/ $ ls -l total 6 drwx------ 2 root root 4096 Nov 7 2008 keyring-7b5rMv drwx------ 2 bcr bcr 4096 Dec 7 2007 keyring-cGhir8 $ I'd be looking for... (1 Reply)
Discussion started by: brendan76
1 Replies

7. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

8. UNIX for Dummies Questions & Answers

command to find the path of a file

What is the command to find the path of a file if we know the file name and the root directory where the file resides.. For eg. if a file abc.dat resides in /home/mydir/myfiles/. I am looking for a command which will be fired from / directory, takes abc.dat as input and display the path of... (3 Replies)
Discussion started by: abhilashnair
3 Replies

9. UNIX for Advanced & Expert Users

list all files with full path of the file

How can i list every single file on a sun solaris server running 2.8 starting from '/' with the full path included in it? example. / ... ... ... /etc/inetd.conf /etc/passwd /etc/shadow ... ... ... /var/adm/messages /var/adm/messages.0 /var/adm/messages.1 ... ... ...... (4 Replies)
Discussion started by: Sowser
4 Replies

10. Shell Programming and Scripting

How would I make a find command NOT show the path of a file?

When I do find . -name "*.txt" -size +0 -exec ls {} \; I get something like ./lpi_stdout.txt ./lpi_stderr.txt What would I need to do or pipe it into to strip off those first two characters so I just get lpi_stdout.txt lpi_stderr.txt ? Thanks for the help! (1 Reply)
Discussion started by: LordJezo
1 Replies
Login or Register to Ask a Question