Jump to content

how to make ls do cd and vice versa

don't ask why but in ubuntu 18.04 how do i swap cd and ls so that ls does what cd should and cd does what ls should

 

 

 

thanks

Link to comment
Share on other sites

Link to post
Share on other sites

if you are using bash, you can issue the below commands

 

alias ls="cd"

alias cd="ls"

 

however i really have to ask.... why ?

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, factorialandha said:

if you are using bash, you can issue the below commands

 

alias ls="cd"

alias cd="ls"

 

however i really have to ask.... why ?

to confuze people

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, factorialandha said:

if you are using bash, you can issue the below commands

 

alias ls="cd"

alias cd="ls"

 

however i really have to ask.... why ?

i just tried that but it didnt work

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Cupar19 said:

i just tried that but it didnt work

What do you get? need to make sure you are using a compatible bash shell and not a different one.

 

works for me here.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, factorialandha said:

What do you get? need to make sure you are using a compatible bash shell and not a different one.

 

works for me here.

odd they just do the normal command, but something like alias  ls='pickle' works

Link to comment
Share on other sites

Link to post
Share on other sites

are you sure they are doing the normal command ? 

 

ls and cd on there own dont return anything if the folder you are in is empty.

 

try doing and past the output.

 

alias ls="cd"

ls /var/

 

below is my output.

 

root@localhost:~# alias ls="cd"
root@localhost:~# ls /var/
rroot@localhost:/var# 

 

also find out which shell you are using by doing the below


root@localhost:/var# echo $0
bash
 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, factorialandha said:

are you sure they are doing the normal command ? 

 

ls and cd on there own dont return anything if the folder you are in is empty.

 

try doing and past the output.

 

alias ls="cd"

ls /var/

 

below is my output.

 

root@localhost:~# alias ls="cd"
root@localhost:~# ls /var/
rroot@localhost:/var# 

 

also find out which shell you are using by doing the below


root@localhost:/var# echo $0
bash
 

backups  crash  local  log   metrics  run   spool  www
cache    lib    lock   mail  opt      snap  tmp
 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Cupar19 said:

backups  crash  local  log   metrics  run   spool  www
cache    lib    lock   mail  opt      snap  tmp
 

-bash

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Cupar19 said:

backups  crash  local  log   metrics  run   spool  www
cache    lib    lock   mail  opt      snap  tmp
 

then im a little stumped, there should be no reason it doesnt work. 

 

as you are using bash, aliases should be fine. 

Link to comment
Share on other sites

Link to post
Share on other sites

What does your ~/.bashrc show? Paste it in Pastebin and put the link here.

Link to comment
Share on other sites

Link to post
Share on other sites

So I've sort of done something similiar in AIX, I think what you need to do is rename the ls command in /usr/bin (or where ever it's stored in Ubuntu) to say nols, then set your alias for cd

 ie :

mv ls nols

alias cd = ls

or you could just symlink cd to ls

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×