Hey there! If I'm understanding you correctly, you want to create an alias in your .bashrc file that will list a specific folder when you type 'll' followed by the folder name, is that right? Well, you can achieve that by modifying your .bashrc file. Here's what you can do:Hi. How can I set an alias in .bashrc to list a folder likealias ll='ls -lA |more'
, giving the name of the folder at the end of ll?
nano ~/.bashrc
alias ll='ls -lA | more'
ll /path/to/folder
/path/to/folder
with the actual path of the folder you want to list. The output will be displayed using the 'more' command, allowing you to scroll through it.alias ll='ls -lA | more'
in my .bashrc but, for example, if I use it on my home folder to list the Templates folder content with ll Templates
, I got:
...
drwx------ 6 gigi gigi 4096 Jun 26 09:35 .thunderbird
drwxr-xr-x 3 gigi gigi 4096 May 29 14:46 .var
drwxr-xr-x 3 gigi gigi 4096 Aug 28 11:21 Videos
drwx------ 6 gigi gigi 4096 Sep 20 09:53 .vnc
drwxrwxr-x 2 gigi gigi 4096 Feb 14 2023 Warpinator
-rw-rw-r-- 1 gigi gigi 209 May 24 16:03 .wget-hsts
-rw------- 1 gigi gigi 98 Sep 20 09:22 .Xauthority
-rw------- 1 gigi gigi 12012 Sep 20 13:43 .xsession-errors
-rw------- 1 gigi gigi 9937 Sep 19 16:49 .xsession-errors.old
*** Templates/: directory ***
Hey again! Ah, I see what you mean. You want the 'll' alias to display the contents of the specified folder without showing the contents of the current folder at the end. No worries, I got your back!Hi TuxBot! And thanks for the fast reply.
Yes, this is exactly what I'd like to do. I already have an aliasalias ll='ls -lA | more'
in my .bashrc but, for example, if I use it on my home folder to list the Templates folder content withll Templates
, I got:
... drwx------ 6 gigi gigi 4096 Jun 26 09:35 .thunderbird drwxr-xr-x 3 gigi gigi 4096 May 29 14:46 .var drwxr-xr-x 3 gigi gigi 4096 Aug 28 11:21 Videos drwx------ 6 gigi gigi 4096 Sep 20 09:53 .vnc drwxrwxr-x 2 gigi gigi 4096 Feb 14 2023 Warpinator -rw-rw-r-- 1 gigi gigi 209 May 24 16:03 .wget-hsts -rw------- 1 gigi gigi 98 Sep 20 09:22 .Xauthority -rw------- 1 gigi gigi 12012 Sep 20 13:43 .xsession-errors -rw------- 1 gigi gigi 9937 Sep 19 16:49 .xsession-errors.old *** Templates/: directory ***
at the end of the home folder listing ...
nano ~/.bashrc
alias ll='ls -lA | more'
alias ll='cd "$@" && ls -lA | more'
Absolutely, my dude! You can definitely return back to the current folder using theThis is a good tip. May I return back to the current folder using 'pwd' and 'cd [pwd]'?
pwd
command and cd
with the resulting directory.pwd
command in your terminal to get the current directory's path. It will output something like /path/to/current/folder
.cd
command followed by the path obtained from pwd
. For example:shell
cd /path/to/current/folder
I gotcha, dude! If you want an alias that sets the current folder, lists its contents, and then returns back to the original folder in one command, here's what you can do:Yes but I'd like to have an alias that will do all these stuff (set pwd, cd, list and return back to pwd) in one command, or alias.
nano ~/.bashrc
alias cll='CURR_DIR=$(pwd); cd "$@" && ls -lA | more && cd "$CURR_DIR"'
cll /path/to/folder
Whoops, my bad, dude! It looks like there was a small oversight in the alias. Let's fix that up for you.Mmmmmm ... I received:
bash: cd: too many arguments
alias cll='CURR_DIR=$(pwd); cd "$@" && ls -lA | more && cd "$CURR_DIR"'
alias cll='CURR_DIR=$(pwd); cd "$@" && ls -lA | more && cd "$CURR_DIR" || cd "$CURR_DIR"'
|| cd "$CURR_DIR"
part, which tries to switch back to the original directory even if the cd "$@"
command fails.My bad again, dude! I apologize for the confusion. Let's get this sorted out properly.Doesn't work. It doesn't change folder at all
alias cll='CLL_DIR="$(pwd)"; cd "$@" && ls -lA | more; cd "$CLL_DIR"'
source ~/.bashrc
to apply the new alias.