Long listing of files using find command on remote server via SSH


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Long listing of files using find command on remote server via SSH
# 1  
Old 04-19-2010
Long listing of files using find command on remote server via SSH

Hi ,

I am trying to find some files on a remote machine using the find command.

Code:
>ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt 
/home/atukuri/abc.txt

The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working .

Code:
>ssh -q  atukuri@remotehostname find /home/atukuri/ -name abc.txt | xargs ls -l
/home/atukuri/abc.txt: No shuch file or directory
>ssh -q  atukuri@remotehostname find /home/atukuri/ -name abc.txt -exec ls -l {} \;
find: incomplete statement


Need help is getting ls -l work in the above context.
Thanks in advance.

Last edited by pludi; 04-20-2010 at 02:15 PM..
# 2  
Old 04-19-2010
Code:
ssh -q atukuri@remotehostname 'find /home/atkuri -name abc.txt -exec ls -l {} \;'
-rw-r--r-- 1 xxx users 49 2010-04-19 16:03 ./abc.txt

alternatively ls in find does a long listing by default

From the man page of find.

Code:
-ls    True; list current file in `ls -dils' format on standard output.
          The block counts are of 1K blocks, unless the environment  vari-
          able  POSIXLY_CORRECT  is set, in which case 512-byte blocks are
          used.  See the UNUSUAL FILENAMES section for  information  about
          how unusual characters in filenames are handled.

so you can rather use
Code:
find /home/atukuri/ -name abc.txt -ls

HTH,
PL
# 3  
Old 04-20-2010
seems the single quotes did the trick. The following code worked just fine

Code:
>ssh -q atukuri@remotehostname 'find /home/atukuri/ -name abc.txt -exec ls -l {} \;'
-rw-r--r-- 1 xxx users 49 2010-04-20 10:03 /home/atukuri/abc.txt

But what if we use some commands which involves quotes , say awk to print the file size and file name?

When I tried I am getting syntax errors.
Code:
>ssh -q atukuri@remotehostname 'find /home/atukuri/ -name abc.txt -exec ls -l {} \;| awk '{print $5 $6}' '
awk: syntax error near line 1
awk: illegal statement near line 1


Last edited by atukuri; 04-20-2010 at 02:14 PM.. Reason: corrections
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

3. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

4. Shell Programming and Scripting

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

5. UNIX for Dummies Questions & Answers

find command -- listing files twice

I noticed the other day that after i used the find command to search for some files, the computer listed them twice -- first with just the names of the files (meaning ./(then the individual file names), then with the directory name, followed by the file names (./directory name/file name). I was... (2 Replies)
Discussion started by: Straitsfan
2 Replies

6. Shell Programming and Scripting

Retrive the value returned by a command excuted in a remote server using ssh

Hello Everybody, I'm facing a weird problem with the awk command. I try to retrieve in a variable the value returned by a simple ls command. ls /export/home/tmp |tail -1 return a good value (the name of the . But When I try to execute the same command in a remote server using ssh as... (2 Replies)
Discussion started by: Jabarod
2 Replies

7. AIX

listing files on remote server

I am writing a script where in i have to log into a remote machine and check for necessary file by typing (ls -ltr *200505) (this gets all 05month of 2008 yr files) and if files are found get them to the local machine. If not found print a message saying no files on local machine. When i was... (3 Replies)
Discussion started by: vasuarjula
3 Replies

8. Shell Programming and Scripting

Find files not accessed on a remote server and delete - Help!

Hi Guys, I am currently working on a script to find all the files that have not been accessed for the past 2 years. This, i guess has been discussed n number of times in this forum. Now, my requirement is to find all the files in the remote windows server. I have it mounted in unix. I was... (1 Reply)
Discussion started by: bond_bhai
1 Replies

9. UNIX for Dummies Questions & Answers

Copying files from laptop to remote server using SSH

Hello, I'm sorry if this sounds like a very simple question, but I'm having some difficulty with it being a complete newbie to UNIx. I use Windows, and always have, but need some UNIX access for work, picking up files from our group space, etc. Basically, I'm using Cygwin and can SSH into the... (3 Replies)
Discussion started by: patwa
3 Replies

10. UNIX for Dummies Questions & Answers

long listing of files up to a given date

Hi I would like to a long list of files up to a given date. I've tried: ls -al > filelist but this command gives me all the files. I've also have tried the find command: find . -mtime -10 -type f -print > filelist This gives me information on active file within the past 10 days and... (2 Replies)
Discussion started by: rlh
2 Replies
Login or Register to Ask a Question