basename problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting basename problem
# 1  
Old 04-06-2009
basename problem

Hi guys if i do

a=`basename -e -s /home/j/john/*`

du -k -h $a | sort -nr | head -10

why when i run the script does it work but also say usage basename string [suffix]

any ideas thanks
# 2  
Old 04-06-2009
Hi,
What did You expect for output? I don't think basename has the options -e and -s, are You perhaps thinking of some other command?

/L
# 3  
Old 04-06-2009
Well i took the -s sand -e and i get the same

i just want to cut the /home/j/john and print the directory names in that path

so rather then

/home/j/john/directory/
/home/j/john/directory2/pictures

it should list it

.directory
.pictures

im trying to list the 10 largest files in the users home directory but i dont want to display the whole path just the last folder
# 4  
Old 04-06-2009
Hi again,
yes because even if You remove the -s and -e it may still be syntactically wrong, probably because the wild card * expands to more arguments than base name expects.

A few ways to get the dir names from a directory could be

Code:
ls -d /home/lakris/*/

Code:
find /home/lakris  -maxdepth 1 -type d

or even
Code:
tree -d -L 1 /home/lakris

if You have it. But perhaps not so good for scripting!
After You've got the names, You can treat hem with basename to get the basic file (dir) name You want.

An example:

ls -1 -d /home/lakris/*/|while read line; do basename $line;done

Last edited by Lakris; 04-06-2009 at 02:17 PM.. Reason: added an example
# 5  
Old 04-09-2009
still have problem

i do this and i get the expected correct result but i still get an error saying no such file or directory found

Code:
a=`ls -1 -d /home/j/jdongs/*/|while read line; do basename $line;done`

not sure why
# 6  
Old 04-09-2009
Hi, I am not sure what that could be, can You post some output? Maybe there are dirnames with space in them? To handle that, use quotes around the variable, do basename "$line".
And will You do any operations based on the variable "a" or on the read input in the while loop? I would recommend the latter. The var "a" will contain a row of words and if a directory contains of several words You won't be able to discriminate between the words/directory names in "a". Otherwise You may have to use an array.



/Lakris
# 7  
Old 04-09-2009
/home/j/jdongs/*/: No such file or directory

The 10 biggest directories are:
size Directory
960 k ./dir1
928 k ./.tin
808 k ./files

it just prints 10 of the biggest directories but for some reason does it correcty but comes up wth No such file or directory
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pipe to basename

I would like to use basename with wc .. I know I can use awk, but want to use basename. Change this wc -l txt* 106 /home/popeye/txt1 154 /home/popeye/txt2 159 /home/popeye/txt3 420 total to this wc -l txt* 106 txt1 154 txt2 159 txt3 420 total (4 Replies)
Discussion started by: popeye
4 Replies

2. Shell Programming and Scripting

$(basename $0)

what is the meaning of "script_name=$(basename $0)", can someone please explain? (1 Reply)
Discussion started by: abhi200389
1 Replies

3. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

4. UNIX for Dummies Questions & Answers

awk and basename

im trying to extract the basename of a process running on a host processx is running at host1 as /applications/myapps/bin/processx i wanted to check if its running, then extract the basename only using: $ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}' ... (10 Replies)
Discussion started by: kaboink
10 Replies

5. Shell Programming and Scripting

Difference between $0 and basename

Hi, Could you please help me to know the difference between $0 and basename in unix how they useful in shell scripting. Thanks in advance (3 Replies)
Discussion started by: lnviyyapu
3 Replies

6. Shell Programming and Scripting

Need help with basename command

I have a file fileinput.txt: File home/me/fileA.doc is size 232 File home/you/you/fileB.doc is size 343 File /directory/fileC.doc is size 433 File /directory/filed.doc cannot find file size I want to use the basename command (or any other command) to output: File fileA.doc is... (3 Replies)
Discussion started by: linuxkid
3 Replies

7. UNIX for Dummies Questions & Answers

basename

Hi, can anyone let me know how to interpret the below third line in the following code. Gone through the man pages of "basename", but no go. for f in *.foo; do base=`basename $f .foo` mv $f $base.bar done Thanks. (2 Replies)
Discussion started by: venkatesht
2 Replies

8. Shell Programming and Scripting

basename $0

hi, can anyone help me by saying what is basename.. i have seen this in many programs where the basename is used.... thanks, Krips (4 Replies)
Discussion started by: kripssmart
4 Replies

9. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

10. Shell Programming and Scripting

reverse of basename

Hi, Can someone let me know how to find the reverse of the basename i.e i have /apps/tiv/pmon/xxxx.dat and I want /apps/tiv/pmon/ Thanks (7 Replies)
Discussion started by: braindrain
7 Replies
Login or Register to Ask a Question