I wish there was a command in Linux to make a directory and change to that directory in a single command and I have a sneaking suspicion that somebody will reply with said command that I should have known about already.
Conversation
Notices
-
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 08:58:29 JST
Miakoda
-
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 09:18:34 JST
Miakoda
@tuban_muzuru Fuck yeah! Thank you! I'll try this rn.
-
Embed this notice
tuban_muzuru (tuban_muzuru@beige.party)'s status on Sunday, 14-Dec-2025 09:18:35 JST
tuban_muzuru
edit your shell config file
nano ~/.bashrcAdd the following lines
mkcd () {
mkdir "$1" && cd "$1"
}save the file and run source ~/.bashrc ( or the shell config file )
Now you can
mkcd new_project_folder
-
Embed this notice
Khalid ⚡ (khalidabuhakmeh@mastodon.social)'s status on Sunday, 14-Dec-2025 09:19:05 JST
Khalid ⚡
@hellomiakoda the command is "take" in zsh
-
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 09:19:05 JST
Miakoda
@khalidabuhakmeh like
$ take Folder\ Name
? -
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 09:24:19 JST
Miakoda
@tuban_muzuru Works precisely how I wanted. Thank you!
-
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 10:20:35 JST
Miakoda
@tuban_muzuru Does $1 work the same in an alias? Cause if it does... that's the missing piece to some aliases I've been wanting to do.
-
Embed this notice
tuban_muzuru (tuban_muzuru@beige.party)'s status on Sunday, 14-Dec-2025 10:20:38 JST
tuban_muzuru
y/w . Linux people are wired up to help others. Comes with the territory, heh.
-
Embed this notice
Miakoda (hellomiakoda@pdx.social)'s status on Sunday, 14-Dec-2025 15:11:11 JST
Miakoda
@tuban_muzuru So... that could that be used to hold the big string of yt-dlp options I use, so I could like yt-dlp-low $1
with $1 being the URL? -
Embed this notice
tuban_muzuru (tuban_muzuru@beige.party)'s status on Sunday, 14-Dec-2025 15:11:12 JST
tuban_muzuru
For standard shell aliases in Bash and Zsh (which are the most common shells), the short answer is No, $1 does not work as you might expect.
The positional parameters like $1 (for the first argument), $2, etc., and $@ (for all arguments) are typically expanded when the alias is defined, not when you use it. When you define an alias like alias foo='bar $1', the shell substitutes $1 right away. Since you're not passing arguments when you define the alias, $1 usually expands to nothing.
The recommended and reliable way to create a shortcut that takes arguments is to define a shell function. Functions are simple to write and are handled correctly by the shell when you execute them, allowing you to use $1, $2, and $@ just like in a script.
Example Function (Bash/Zsh)Let's say you want to create a command mkcd that makes a directory and then immediately changes into it, and it needs the directory name as an argument.
Instead of trying this (which won't work):
alias mkcd='mkdir -p $1 && cd $1'Do this instead (which works):
mkcd() { mkdir -p "$1" && cd "$1"; }P.S. : there is the concept of an anonymous function in bash, but it is bullshit. Use a proper function.
-
Embed this notice