LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-31-2008, 05:49 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Scripting help needed.


Hi all,


To listing the files in the directory , am using the following command along with the absolute path .
Code:
$ls -lt /home/zamo/test/*  |grep -v total
-rw-r--r--  1 zamo zamo 7736 Oct  7 12:54 /home/zamo/test/mytestfile
The output is good as i need , but i need the output as
Code:
-rw-r--r--  1 zamo zamo 7736 Oct  7 12:54 mytestfile
How can I get it? I use ls -lt|awk -F\/ '{print $NF}' which gives me the file name only. I want the complete output as i shown above excluding the absolute path.

Thanks
 
Old 12-31-2008, 05:54 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
You could cd to a directory first and then ls:
Quote:
cd /home/zamo/test && ls -lt
 
Old 12-31-2008, 06:03 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Thanks.. It will work. I need to do this in a script file and it is advised to use the absolute path . Futher I will execute the above said command to a remote machine which will not be good to use "cd " to the directory.
 
Old 12-31-2008, 06:18 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
What about:

Quote:
ls -lt /home/zamo/test/* | sed 's/\/home\/zamo\/test\///g'
edit: actually the 'g' flag at the end is not necessary

Last edited by sycamorex; 12-31-2008 at 06:22 AM.
 
Old 12-31-2008, 06:31 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Thanks sycamorex for putting your efforts for me.
Its Working .......

Wish You a Happy and Prosperous New Year 2009.
 
Old 12-31-2008, 06:36 AM   #6
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Thanks and same to you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
help needed in scripting ZAMO Linux - General 2 10-31-2008 08:23 AM
Scripting help needed. ZAMO Linux - General 1 09-17-2008 10:35 PM
Scripting help needed. ZAMO Linux - General 2 09-09-2008 06:11 AM
a little scripting help needed!! vatsan1 Linux - General 6 09-02-2007 08:50 AM
Scripting help needed. stonelee Linux - Software 2 09-29-2003 09:47 AM

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

All times are GMT -5. The time now is 05:32 AM.

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