Sponsored Content
Top Forums Shell Programming and Scripting want the current directory without the absolute path Post 302087461 by olimiles on Friday 1st of September 2006 06:16:43 AM
Old 09-01-2006
want the current directory without the absolute path

Hi guys

I'm trying to move an empty directory to the $TRASH directory. Say the directory i have is ./hello/hello1/hello2 and i'm in hello2, and i want hello2 moved.

this code:
Code:
TRASH=$home/deleted

find "$TRASH/$1" -type d -exec rmdir { } \; 2>/dev/null
mv -f $1 $TRASH 2>/dev/null

works when the $TRASH directory is empty, but if hello2 is already there it won't move it. So using find i'm trying to delete hello2 from $TRASH, but it won't because it's looking for the value of $1 which is the absolute path of hello2 ie ./hello/hello1/hello2, which of course isn't there.

Does that make sense?

The question is: is there a way to get the current directory without the ./hello/hello1/ bit? And if so, how! Or if not is there another way i can get the same result?

Many thanks in advance

Oliver
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question about Restricting Search path of FIND to current directory

Hi, By default FIND command searches for matching files in all the subdirectories within the specified path. Is there a way to restrict FIND command's search path to only the specified directory and NOT TO scan its subdirectories. Any help would be more than appreciated. Thanks and Regards (2 Replies)
Discussion started by: super_duper_guy
2 Replies

2. UNIX for Dummies Questions & Answers

vi - replacing a relative path with absolute path in a file

Hi, I have a file with about 60 lines of path: app-defaults/boxXYZ....... I want to change this to /my/path/goes/here/app-defaults/boxXYZ, but of course vi doesn't like the regualr :s/old/new/ command. Is there any other quick way to do this? Thanks ;) (2 Replies)
Discussion started by: Yinzer955i
2 Replies

3. UNIX for Dummies Questions & Answers

tag/mark a file with current absolute path

Hi all, I need to mark a file with it's current location in the file system before being moved. This will enable the file to be restored back to it's original location. Can anyone provide any ideas about the best way to do this, at present i'm trying to use readlink -m to strip off the... (1 Reply)
Discussion started by: skinnygav
1 Replies

4. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

5. Shell Programming and Scripting

How to change Absolute path to Relative path

Hello, I have a doubt:- --------------------- Current script:- ################################################################################################ prefix=user@my-server: find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do ( cd "$path" || exit $?... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

6. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

7. UNIX for Dummies Questions & Answers

Setting the current directory path to terminal title

In ubuntu, I want to update the title of the terminal window with the current directory path. Any ideas how this can be achieved? ---------- Post updated at 02:22 PM ---------- Previous update was at 02:08 PM ---------- Done it ---------- Post updated at 02:30 PM ---------- Previous update... (2 Replies)
Discussion started by: kristinu
2 Replies

8. UNIX for Dummies Questions & Answers

How to convert relative path to absolute path?

Hello Everyone, I want to convert Relative Path - /home/stevin/data/APP_SERVICE/../datafile.txt to Absolute Path - /home/stevin/data/datafile.txt Is there a built-in tool in Unix to do this or any good ideas as to how can I implement this. -Steve (5 Replies)
Discussion started by: qwarentine
5 Replies

9. UNIX for Dummies Questions & Answers

How to get the current directory Path?

How to get the current directory Path in your prompt? i am getting a $ mark only in my prompt? Please help me with this (3 Replies)
Discussion started by: Abhishek0683
3 Replies

10. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies
rmdir(1)						      General Commands Manual							  rmdir(1)

NAME
rmdir - remove directories SYNOPSIS
dir ... DESCRIPTION
removes the directory entry for each dir operand that refers to an empty directory. Directories are removed in the order specified. Consequently, if a directory and a subdirectory of that directory are both specified as arguments, the subdirectory must be specified before the parent directory so that the parent directory will be empty when tries to remove it. Removal of a directory requires write and search (execute) permission in its parent directory, but no permissions on the directory itself; but if the sticky bit is set on the parent directory, only the owner of the directory, the owner of the parent directory, or a user having appropriate privileges can remove the directory. Options recognizes the following options: Force each directory to be removed without prompting for confirmation, regardless of the presence of the option. This option also suppresses diagnostic messages regarding non-exis- tent operands. This option does not suppress any diagnostic messages other than those regarding non-existent operands. To suppress all error message and interactive prompts, the option should be used while redirecting the standard error output to This option ignores any previous occurrence of the option. Write a prompt to the standard error output requesting confirmation before removing each directory. This option ignores any previous occurrence of the option. Path removal. If, after removing a directory with more than one pathname component, the parent directory of that directory is now empty, removes the empty parent directory. This continues until encounters a non-empty parent directory, or until all components of the original pathname have been removed. When used in conjunction with the option, asks whether to remove each directory component of a path. EXTERNAL INFLUENCES
Environment Variables provides a default value for the internationalization variables that are unset or null. If is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, will behave as if all internationalization variables are set to "C". See environ(5). If set to a non-empty string value, overrides the values of all the other internationalization variables. determines the interpretation of dir names as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informa- tive messages written to standard output. determines the location of message catalogues for the processing of International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS
Generally self-explanatory. Note that the option does not suppress all diagnostic messages. EXAMPLES
To remove directories with a prompt for verification: directories To remove as much as possible of a path, type: SEE ALSO
rm(1), rmdir(2), stat(2). STANDARDS CONFORMANCE
rmdir: SVID2, XPG2, XPG3, XPG4 rmdir(1)
All times are GMT -4. The time now is 02:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy