alias to cd and ls a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting alias to cd and ls a directory
# 1  
Old 06-02-2010
alias to cd and ls a directory

I am trying to create an alias to cd to a directry and ls the directory I have changed to. I have the following code;

Code:
alias cd= 'cd ; ls $@'

This just cd to the directory and ls the current directory. Any suggestions?

Thanks
# 2  
Old 06-02-2010
Code:
alias example="cd \$SOMEPLACE && ls"
SOMEPLACE=/home/cold_Que
example

# 3  
Old 06-03-2010
Thanks for the response, yet how do I specifiy any argument for cd?

code:
Code:
alias cc='cd `$*` && ls'

I would like to "cc" to any directory I specify at the command prompt

ie..
$ cc ../

I would like that command to go back one directory and ls the contents
# 4  
Old 06-03-2010
try

alias cdls='cd $1 && ls'
# 5  
Old 06-03-2010
That's not working. I tried $@ which means all the command line arguments at once and it just ls the command line argument and does not cd.

Code:
alias cc='cd $@ && ls'

Any more suggestions?
# 6  
Old 06-03-2010
I don't think you can do what you are trying to, with a simple alias.

Why not write a script:
Code:
$ cat myCDLS
cd $1
ls

$ alias CD=". ./myCDLS"

Put myCDLS somewhere in your path and change your alias accordingly.
# 7  
Old 06-03-2010
Quote:
Originally Posted by jacksona2
try

alias cdls='cd $1 && ls'

Why doesn't this work? It worked for me
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Postfix: Active Directory and postfix alias

I have a mailserver with postfix i want to alias all mail for administrator@domain.fqdn to root@domain.fqdn I have the aliases configured,and i did newliases but doesn't work. How to did this?Postfix is configured for virtual domain on ad server. (2 Replies)
Discussion started by: Linusolaradm1
2 Replies

2. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

3. Shell Programming and Scripting

Define Alias for Changing Directory to Another One

Hello Friends is it possible to define an alias (say named as COMMAND) to pick a part of line and change my directory to picked. For example when I type COMMAND mfong@vhl.gov.nd/homefolder/hhk/ADS/ it would do cd /homefolder/hhk/ADS/ (1 Reply)
Discussion started by: rpf
1 Replies

4. UNIX for Dummies Questions & Answers

alias to go back to previous directory?

Some time ago I was using a linux system and someone had set up and alias called "back" that got me back to the directory I was last in, which was very useful. I've now switched to using a mac, and don't have those aliases available. Can anyone tell me how I could make a an alias that would... (2 Replies)
Discussion started by: ac2011
2 Replies

5. UNIX for Dummies Questions & Answers

Create alias to daily dated directory

Hello, I wanted to see if there's a way to shortcut to a dated logs directory that changes daily...what I'm working with is something like this: > > > . . where the log directory is named yyyymmdd I've created a shortcut to get me to the /log directory but was... (2 Replies)
Discussion started by: mojowtm6
2 Replies

6. UNIX for Dummies Questions & Answers

Help with Alias

Hi, I have a software package consisting of a group of BASH shell scripts. There is a master script which calls a series of subscripts. To run the software users must open the master script, modify and save it, and then run it. To open the script you can either double-click on it, or you can... (2 Replies)
Discussion started by: msb65
2 Replies

7. UNIX for Dummies Questions & Answers

How to get the alias,when we have the IP.

Hi, I have to set up a printer in the system.Generally the alias is given like sdclbl1 etc.So when I ping i get the IP address. This time they have provided the IP adress.Is there any way to find the alias from this.Ping did not give the alias. Thanks and Regards, Gideon. (2 Replies)
Discussion started by: preethgideon
2 Replies

8. UNIX for Dummies Questions & Answers

Creating alias for directory path

I am trying to create an alias for a frequently used directory path by using alias xyz="/proj/dir_name" and then trying to reach a sub-directoy by using cd xyz/abc but I get an error saying " No such file or directory " plz tell me wats wrong with this ... (3 Replies)
Discussion started by: jasjot31
3 Replies

9. UNIX for Dummies Questions & Answers

Help with find command on a shortcut directory(Alias)???

Hi All, I am trying to find some files on a directory( /usr/users/xyz/log) which is an alias to another directory(/spare/log). My find works fine on /spare/log but it doesnt return anything when i use it on /usr/users/xyz/log. Any Ideas on how to proceed. Thanks in advance. Swamy (2 Replies)
Discussion started by: swamy455
2 Replies

10. UNIX for Dummies Questions & Answers

Alias

How do you create an Alias that excepts command line arguments. I am trying to move files from one directory to another all within the Alias command. Please Help! (2 Replies)
Discussion started by: JSP
2 Replies
Login or Register to Ask a Question