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?????


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)


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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