musicboy
Posts: 15
Joined: Fri Feb 14, 2014 6:52 pm

Creating new cd and ls function

Fri Feb 14, 2014 7:02 pm

Hi there.
I'm a fair beginner to the Pi, and have a question for the pi gods :)
The one thing that I find tedious when using the shell is doing "ls" after every time I do "cd". (I'm lazy)
Just wondering, how easy would it be to create a function combining cd and ls, say "cdl", that I could execute as one command?
And what file would I need to define it in?
Thanks very much for your patience with a beginner.

colinh
Posts: 94
Joined: Tue Dec 03, 2013 11:59 pm
Location: Munich

Re: Creating new cd and ls function

Fri Feb 14, 2014 9:44 pm

This isn't really a Raspberry Pi question, let alone a Bare Metal one. It's a Unix question...

anyway, you want

function cdl { cd $1; ls; }

added to your .bash_profile file in your home directory.


Try typing man bash.

edit: if you actually *do* this, and read it all, you'll find out about command completion and filename completion etc. Try ls TAB-key TAB-key. Then try man ls and ls -A.
Last edited by colinh on Sat Feb 15, 2014 6:12 am, edited 1 time in total.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Creating new cd and ls function

Fri Feb 14, 2014 10:56 pm

I quite like navigating and viewing text files with lynx although it's main function is text based web browsing.
To access your current directory lynx . is all you need. :)

Richard S.

Return to “Beginners”