LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-27-2012, 09:45 PM   #1
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Rep: Reputation: Disabled
shell script


i want to append / at the beginning of all my directory names and to add word 'DIR' at the beginning of the line
by using ls -l command


can anyone help me.........

thnx in advance
 
Old 02-27-2012, 10:42 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The -p option does the first. ls cannot do the second.
 
Old 02-28-2012, 12:28 AM   #3
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Original Poster
Rep: Reputation: Disabled
then how can i append dir to the starting
 
Old 02-28-2012, 09:53 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You could read the ls output and write it out again, prefixing lines that end with / with DIR.
 
Old 02-28-2012, 10:29 AM   #5
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Original Poster
Rep: Reputation: Disabled
by using what command????
i did with tr 'd' 'DIR'
but its not coming properly
 
Old 02-28-2012, 10:50 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Code:
ls -lp | sed 's|\(.*\)/$|DIR\1/|'
 
Old 02-28-2012, 11:00 AM   #7
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Original Poster
Rep: Reputation: Disabled
ya it's working nicely
can u tell me what is the meaning of
Quote:
sed 's|\(.*\)/$|DIR\1/|'
 
Old 02-28-2012, 11:05 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
http://www.grymoire.com/Unix/Sed.html#uh-4
 
Old 02-28-2012, 01:51 PM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,923
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
Member response

Hi,
Welcome to LQ!
Quote:
Originally Posted by Micky12345 View Post
i want to append / at the beginning of all my directory names and to add word 'DIR' at the beginning of the line
by using ls -l command


can anyone help me.........

thnx in advance
You seem to be asking several question(s) concerning bash scripting. Look at links 4, 5 & 6 below along with 'Rute Tutorial & Exposition'.

You will find the below FYI very useful to help you form good questions/queries. Especially your subject titles!

FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query.

Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide
10 Linux Home Networking
11 Virtualization- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
  


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
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Shell Script running in another shell script and then exit dreamervlk Linux - General 3 09-16-2011 06:40 AM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

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

All times are GMT -5. The time now is 09:20 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