Search code examples
linuxbashaliascd

How to cd into a folder using linux alias?


This alias searching a folder and printing out the location of the folder.

findme 1234567                  --> Searching and printing 
/xxx_data/xxe/TK/1234567/       --> This is the output of above alias.
alias findme='program -x SR $1' --> This is the alias. 

is there way to redefine this alias that when I run findme 1231412 it will directly pass the user input into cd and enter to subfolder.

Example

findme 1234567                   
/xxx_data/xxe/TK/1234567 <-- From here I do cd /xxx_data/xxe/TK/1234567/Allfiles

Find me searched and printed the folder location, but I wanted this alias to actually do cd into subfolder(Allfiles) of the finded folder. like this

/xxx_data/xxe/TK/1234567/Allfiles <-- so how can I define an alias that can read user input findme and pass it to cd command 

in this file structure only thing change is the number /xxx_data/xxe/TK//Allfiles


Solution

  • Aliases do not take arguments. Use a function

    findme () {
      cd  "$(program -x SR "$1")"
    }