Show only the filenames under a directory without relative and absolute paths.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Show only the filenames under a directory without relative and absolute paths.
# 1  
Old 06-20-2017
Tools Show only the filenames under a directory without relative and absolute paths.

I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux

Code:
find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev

Desired Output:

Code:
THIRDPARTYLICENSEREADME.txt
javaws
libjavaplugin_oji.so
libjavaplugin_oji.so
sun_java.png
sun_java.desktop

But this command does not work on Solaris

Code:
bash-3.2$ find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev
bash: rev: command not found
  
 bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-40 sun4v sparc sun4v

I don't wish to use PERL

How can I get a generic command to give me the desired output on both Solaris and Linux ? If a generic command is not possible can you let me how can I get the desired output on Solaris ?

Last edited by Scrutinizer; 06-20-2017 at 06:10 PM.. Reason: Changed [quote] tags to [code] tags....
# 2  
Old 06-20-2017
awk can easily print the last field
Code:
find /tmp/ -type f \! -name blent.tar | awk -F/ '{print $NF}'

This filters out exactly blent.tar (but not xblent.tar or blent.tar.Z or blent-tar).
If you want to keep the unsharp filter then let awk do it
Code:
find /tmp/ -type f | awk -F/ '$NF!~/blent.tar/ {print $NF}'

BTW also awk can do the exact filter
Code:
find /tmp/ -type f | awk -F/ '$NF!="blent.tar" {print $NF}'


Last edited by MadeInGermany; 06-20-2017 at 02:11 PM..
# 3  
Old 06-20-2017
Doesn't Solaris' find allow for the \! -iname "brent.tar" negated test?
# 4  
Old 06-21-2017
The find in Solaris 11 supports \! -iname "brent.tar"; an older Solaris needed \! -name "[Bb][Rr][Ee][Nn][Tt].[Tt][Aa][Rr]".
But is not required here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Remove leading dot and slash on relative paths with find

When I specify a directory by name the leading ./ is not shown: $ find somedir/ somedir/a.bin somedir/target/out.binBut when I specify current dir it adds the ./ to the beginning of each result: $ find . | grep somedir ./somedir/a.bin ./somedir/target/out.binIs there any particular reason why... (2 Replies)
Discussion started by: Tribe
2 Replies

3. Solaris

exclude absolute paths when extracting Tar file?

Hi, How do I extract data from TAR excluding absolute paths for Tar? (Solaris) Thanks (3 Replies)
Discussion started by: zam
3 Replies

4. Shell Programming and Scripting

tar and relative paths

HOw can I create a tar file with relative paths find . -depth -print | xargs tar -cvf /tmp/file.tar ? Thanks to all who answer (1 Reply)
Discussion started by: BeefStu
1 Replies

5. Shell Programming and Scripting

how to remove absolute paths from zip archive

Hi, I need to write an bash script which works like it can copy files from remote machine through ssh to the server where script is running in zip format with the structure i want. I don't want to get absolute path in zip archive. Please let me know how it can be possible. ssh... (4 Replies)
Discussion started by: mirfan
4 Replies

6. UNIX for Dummies Questions & Answers

Absolute and Relative Paths?

Can someone cofirm that I have got the paths correct here? :confused: $PATH_TO_TMP_DIR='/tmp'; #$PATH_TO_TMP_DIR='home/tmp'; $PATH_TO_YOUR_IMG_DIR = '/temp_images'; #$PATH_TO_YOUR_IMG_DIR = 'home/public_html/Midwich/temp_images'; Thanks (1 Reply)
Discussion started by: stubie
1 Replies

7. UNIX for Dummies Questions & Answers

tar symlinks: relative vs absolute

I create the tar file from / like so: tar cEhf name.tar usr/us And this creates the tar with the links intact. The problem is that this tar is going to be used for testing, so we want the links to point to the files in the tar. But when I extract the tar into /tmp, I get /tmp/usr/us/... as I... (2 Replies)
Discussion started by: TreeMan
2 Replies

8. UNIX for Dummies Questions & Answers

get cygpath to leave relative paths as relative?

If I execute mypath=`cygpath -w ../` echo $mypath I get d:\unix\nextVersion\script OK, d:\unix\nextVersion\script is the correct windows version of the path, but it is in absolute form. I would prefer it if cygpath left it in relative form, i.e. echo $mypath should output ..\ ... (0 Replies)
Discussion started by: fabulous2
0 Replies

9. Shell Programming and Scripting

expanding dotted paths to absolute ones in bash or sh

I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies

10. Shell Programming and Scripting

Relative directory - NOT absolute

Here is the drill, I am using a script to login to a remote ftp, and put and get files. My question is: I want to login and automatically change to the same directory I am in on my machine. I can not use $home, pwd or anyother env variable (that I know) since the names of the machines are totally... (4 Replies)
Discussion started by: sierra_aar
4 Replies
Login or Register to Ask a Question