Tuesday, April 30, 2024
65
rated 0 times [  65] [ 0]  / answers: 1 / hits: 26500  / 2 Years ago, fri, may 13, 2022, 7:03:27

When running commands, sometimes maybe you need to run a command with the argument from the last command. How can you do this?



Of course, excepting the use of the arrow keys and Del keys: ...DelDelDel...Del<new_command>.


More From » command-line

 Answers
2

For example, if you run this command:



mkdir long_path_here/new_dir


most likely you'd want to go in the recently created directory. You can do this using next "shortcuts":




  • cd Esc. - type cd and after press Esc followed by . (not in the same time). If the previous command has no arguments, you will get the previous command itself.

  • cd !* - in this case you will get all arguments from the previuos command. If the previous command has no arguments, you will get nothing.

  • cd Alt+. - type cd and after press Alt and . (in the same time). In fact, using this way and continuing to press . (without to release Alt), you will get the last argument for every command from history. If a command has no arguments, you will get the command itself.



In general: <command> Esc. or <command> !* or <command> Alt+..


[#30849] Saturday, May 14, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
riffnkful

Total Points: 390
Total Questions: 123
Total Answers: 110

Location: Puerto Rico
Member since Sat, Mar 13, 2021
3 Years ago
riffnkful questions
Thu, Nov 17, 22, 04:24, 1 Year ago
Mon, Nov 28, 22, 01:40, 1 Year ago
Mon, Jul 11, 22, 13:24, 2 Years ago
Sun, Feb 5, 23, 05:06, 1 Year ago
;