LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-25-2013, 02:46 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
command to print out the full path of directory


so part of my job is to create there backup diretories and place files in them.
when i mv or cp files over i have to user the cp - p to preserve the timestamp/

any how i am starting to script this whole thing and just want to verify that they directories were made .

I want to verify the full path of the new directory. I figured that the find command will give me the full path of the directory.
i tried the find command to display the path but it resulted i all sorts of nonsense – it seemed to list every directory that it searches and if It can’t get to that directory it
flashed a permissions denied.

Code:

 [casper@casper2013Oct09]$ for i in broker1 broker2 Energy external1 external2 trader1 trader2 ; 

do  

find / -type d  -name "/production/archive/2013Oct09/production/web/docs/$i/docs/etc/etc_html" ;

 done
if i do a ls -lrtr i just get the contents of the file – ls does not print the full path of the new directory.

[CODE]
[icapfo@usprvauth01s 2013Oct09]$ for i in ps-broker1 ps-broker2 ps-Energy ps-external1 ps-external2 ps-trader1 ps-trader2 ;

do

ls -ltr /production/archive/2013Oct09/production/web/docs/$i/docs/etc/etc_html ;

done
total 0
total 0
total 0
total 0
total 0
total 0
total 0
[\CODE]

this i what i get when i run the ls -ltr before i create the directories – which funny enough - it just what I want – a printer list of the full path.
Code:
[icapfo@usprvauth01s 2013Oct09]$ for i in ps-broker1 ps-broker2 ps-Energy ps-external1 ps-external2 ps-trader1 ps-trader2
> do
> ls -ltr /production/archive/2013Oct09/TT29282/production/web/docs/$i/docs/etc/
> done
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-broker1/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-broker2/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-Energy/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-external1/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-external2/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-trader1/docs/etc/: No such file or directory
ls: /production/archive/2013Oct09/TT29282/production/web/docs/ps-trader2/docs/etc/: No such file or directory
[icapfo@usprvauth01s 2013Oct09]$

That I what I want – I want a test where I can view the whole path.
Is there a command that can do this?
 
Old 10-25-2013, 03:09 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
I am not sure I follow?? You want to use ls or find to look for something that doesn't exist but then complain because the system tells you it doesn't exist???

Try re-explaining what your actual requirement is?
 
1 members found this post helpful.
Old 10-25-2013, 03:57 PM   #3
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
after i create a directory path, with mkdir -p, i want to print out that directory path.
when i use ls -ltr i get just a zero (for directory contents)
when i use find, i get a bunch of 'permission denied' notifications.
find seems to print every directory it searches.
 
Old 10-25-2013, 04:22 PM   #4
dt64
Member
 
Registered: Sep 2012
Distribution: RHEL5/6, CentOS5/6
Posts: 216

Rep: Reputation: 38
what you could do after you mkdir command:

use 'cd' to jump into the newly created directory and issue the 'pwd' command. This will then give you the full directory path string.

'pwd' always gives you the current directories full path.
 
1 members found this post helpful.
Old 10-25-2013, 04:26 PM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,182
Blog Entries: 10

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
Code:
mkdir -p LQRocks && cd $_ && pwd

Last edited by Habitual; 10-25-2013 at 04:27 PM.
 
1 members found this post helpful.
Old 10-25-2013, 04:27 PM   #6
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
yeah write a script that cd's to last directory in the path and then does a pwd, and then goes back to the working directory - that will work - thanks
 
Old 10-25-2013, 04:30 PM   #7
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,182
Blog Entries: 10

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
Quote:
Originally Posted by casperdaghost View Post
yeah write a script that cd's to last directory in the path and then does a pwd, and then goes back to the working directory - that will work - thanks
or now that you mention "that"...
Code:
mkdir -p LQRocks && echo `pwd`/$_
/home/jj/LQRocks
 
1 members found this post helpful.
Old 10-25-2013, 05:02 PM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Code:
mkdir -pv ~/DELETEME/Foo/bar
results in
Code:
mkdir: created directory ‘/home/firerat/DELETEME’
mkdir: created directory ‘/home/firerat/DELETEME/Foo’
mkdir: created directory ‘/home/firerat/DELETEME/Foo/bar’
you probably only want the last line
Code:
rm -r ~/DELETEME # just example cleanup
mkdir -pv ~/DELETEME/Foo/bar | tail -n 1
mkdir: created directory ‘/home/firerat/DELETEME/Foo/bar’
lets create some error ( as normal user, not root )
Code:
mkdir -pv /DELETEME/Foo/bar
mkdir: cannot create directory ‘/DELETEME’: Permission denied
But that is output to stderr
so redirect stderr to stdout

Code:
NewDir="/DELETEME/Foo/bar"
mkdir -pv "${NewDir}" 2>&1 | tail -n1
I will leave the error capture/reporting to you
 
1 members found this post helpful.
Old 10-25-2013, 05:06 PM   #9
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
@habitual - that is exactly what i was looking for.
@Grail thank you for asking for clarification to the issue.
 
Old 10-25-2013, 05:08 PM   #10
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
@FIRERAT - i am going to see if we can get pv installed at work!!!!
 
Old 10-25-2013, 05:49 PM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by casperdaghost View Post
@FIRERAT - i am going to see if we can get pv installed at work!!!!
it should be standard

longer would be

Code:
mkdir -p -v
Code:
mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z, --context=CTX  set the SELinux security context of each created
                      directory to CTX
      --help     display this help and exit
      --version  output version information and exit

Report mkdir bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'mkdir invocation'
-v does similar things with mv and cp

I like to use the verbose options with scripts, just to give the user feedback and save me some work writing echo or printf functionality
 
Old 10-25-2013, 07:55 PM   #12
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,182
Blog Entries: 10

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
Quote:
Originally Posted by casperdaghost View Post
@habitual - that is exactly what i was looking for.
@Grail thank you for asking for clarification to the issue.
Great, but
Code:
mkdir -p /tmp/LQRocks && echo $_
works also.

ie:
Code:
mkdir -p /tmp/LQRocks && echo $_
/tmp/LQRocks
Glad I could help.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to zip file without full directory path kenp11 Linux - Newbie 2 10-23-2013 07:44 PM
[SOLVED] Print full path+working folder by awk astroumut Programming 4 11-30-2009 09:27 AM
command to show full directory path cuco76 Linux - Newbie 2 10-12-2006 09:36 PM
get full path of a command (in C) Hady Programming 9 11-21-2003 11:50 AM
get full path of a command (in C) Hady Linux - Software 1 11-19-2003 06:46 PM


All times are GMT -5. The time now is 10:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration