alias to list a specific folder with |more

GigiG

New Member
Joined
Sep 20, 2023
Messages
9
Reaction score
1
Credits
65
Hi all, I'm new here. Tryed to solve this with TuxBot with no success. Someone can help? Thanks and regards
 


dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
2,112
Reaction score
1,728
Credits
15,288
To create a Bash alias that lists the contents of a specific folder and pipes it through the more command for pagination, you can add the following line to your ~/.bashrc or ~/.bash_aliases file (create the file if it doesn't exist):

alias listfolder='ls /path/to/your/folder | more'

Replace /path/to/your/folder with the actual path to the folder you want to list. After adding this line to your configuration file, you can use the listfolder alias in your terminal to list the contents of the specified folder with pagination. For example:

listfolder
 
OP
G

GigiG

New Member
Joined
Sep 20, 2023
Messages
9
Reaction score
1
Credits
65
Sorry, with specific folder I mean any existing folder in my PC. For example, while I'm currently in my home folder, I'd like to list the content of its child folder named Templates. With the already existing alias ll='ls - laF |more' (ll Templates) I got the listing of the current home folder and, at the end, a message like * Templates/: directory *
 
Last edited:

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
1,125
Reaction score
1,102
Credits
10,705
One alternative is to write a function that outputs the info desired, and have it written into the .bashrc file so that it's available after logging in. For example, add the following contents to the .bashrc file (source the file in the same terminal if not rebooting):
Code:
lsdir() { ls -alF $1 | more ; }

This version requires one option for the function to run, as follows:
Code:
[flip@flop ~]$ lsdir /home/flip
total 1324
drwxr-xr-x 101 flip  flip   12288 Sep 20 23:47 ./
drwxr-xr-x   5 root root   4096 Mar 14  2022 ../
drwxr-xr-x   2 flip flip    4096 Sep 19 20:50 apple/
drwx------   2 flip flip    4096 Feb  5  2023 .aptitude/
drwxr-xr-x   2 flip flip    4096 Sep 19 20:51 articles/
<snip>

If the output is too long for the screen, the "more" pager operates, but if not then not.

Note that this is just a proof of concept, and really needs a little more code to make sure that there's only one option provided to the function. Any directory can be entered as an option.

On the other hand, it may not be quite what you want.
 
Last edited:
OP
G

GigiG

New Member
Joined
Sep 20, 2023
Messages
9
Reaction score
1
Credits
65
Thanks a lot. This is just what I searched for. Now I only have to find a way to reproduce colors, as for 'ls -laF' alone
 

Members online


Latest posts

Top