Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

We all have to use ls |more and also some other commands.

So i just need info is there a way to bind multiple commands together like I want to bind ls|more together.So when i simply pass ls command it should display some data and wait for user to press key (space bar) to show rest of the data.

Is it possible in linux?????

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Yes, you can use an alias to overwrite a command. In fact, this is already the case for ls as default this is aliased as ls --color=auto

Create a file called '~/.bash_aliases' and enter the following line

alias ls='ls | more'

Now when you type ls in your terminal, it will instead execute ls | more.

In this case it does has an issue with parameters. ls /some/directory will not work anymore because the parameters are applied to more instead of ls (ls | more /some/directory will be executed)

share|improve this answer

If you want the ls command to still accept command-line switches you need to use a shell-script function, something like this should do:

ls() { command ls $@ | more; }

Put it into ~/.bashrc to make it persistent.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.