[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
no way to compare when less than two revisions
Diferencias
Muestra las diferencias entre dos versiones de la página.
Próxima revisión | |||
— | es:howtos:software:efficient_cli_navigation [2019/02/28 01:44 (UTC)] – creado slackwarespanol | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
+ | <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). --> | ||
+ | <note important> | ||
+ | |||
+ | ====== Efficient CLI Navigation ====== | ||
+ | |||
+ | The CLI (Command Line Interface) is a very powerful, flexible and programmable environment. If you use the command line interface on a regular basis, you know how important it is to customise your working environment and develop shortcuts to ensure efficient workflow. Below are some tips on navigating through directories in an quick and easy way. | ||
+ | |||
+ | ===== Go Back Home ===== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | $ cd | ||
+ | $ pwd | ||
+ | / | ||
+ | |||
+ | ===== Go Back to the Previous Directory ===== | ||
+ | |||
+ | To go back to the previous directory, you can use '' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | $ cd ~/ | ||
+ | $ pwd | ||
+ | / | ||
+ | $ cd - | ||
+ | / | ||
+ | $ pwd | ||
+ | / | ||
+ | |||
+ | |||
+ | ===== Use the Last Argument of the Previous Command ===== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | $ cp i3status.tar.gz ~/ | ||
+ | $ cd $_ | ||
+ | $ pwd | ||
+ | / | ||
+ | |||
+ | < | ||
+ | $ $_ | ||
+ | (This will execute script.sh)</ | ||
+ | |||
+ | The same can be achieved using the combination < | ||
+ | ===== Bash Completion ===== | ||
+ | |||
+ | Bash offers < | ||
+ | |||
+ | < | ||
+ | |||
+ | It will expand the path with a directory starting with '' | ||
+ | |||
+ | < | ||
+ | data/ downloads/</ | ||
+ | |||
+ | Now press < | ||
+ | |||
+ | It can greatly reduce the number of keystrokes when accessing directories. For example: | ||
+ | < | ||
+ | |||
+ | The keystrokes I used: | ||
+ | < | ||
+ | |||
+ | If each directory contained only one subdirectory, | ||
+ | |||
+ | < | ||
+ | |||
+ | Not only does the bash completion reduce the number of key strokes, but it also comes handy if you do not remember directory names. | ||
+ | |||
+ | Please note that bash completion works also on files: | ||
+ | |||
+ | < | ||
+ | |||
+ | Keystrokes used: | ||
+ | |||
+ | < | ||
+ | |||
+ | The dot (.) represents the current directory so the command will copy '' | ||
+ | |||
+ | ===== Programmable Bash Completion ===== | ||
+ | |||
+ | To take advantage of all Bash completion features, you need to install an additional package from ''/ | ||
+ | |||
+ | < | ||
+ | FIXME | ||
+ | ===== CDPATH ===== | ||
+ | |||
+ | If you work in certain directories on a regular basis, you might want to include them in the $CDPATH variable. Suppose you often work in the '' | ||
+ | |||
+ | < | ||
+ | $ ls | ||
+ | i3 i3status yajl dmenu libev</ | ||
+ | |||
+ | Add it to the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Please note the path included in the CDPATH variable is the path to the **parent directory** where the said directories are located. | ||
+ | |||
+ | After you have sourced '' | ||
+ | |||
+ | < | ||
+ | / | ||
+ | $ cd yajl | ||
+ | / | ||
+ | |||
+ | If you would like to enable Tab completion within the directories added through the CDPATH variable, you need to install '' | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | ===== Symlinks ===== | ||
+ | |||
+ | In some situations you may consider using [[slackbook: | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | ===== Bash Aliases ===== | ||
+ | |||
+ | You can make your life easier by creating aliases (= shortcuts) for commands that you use often. The syntax is very simple: | ||
+ | |||
+ | < | ||
+ | |||
+ | You can place your aliases in '' | ||
+ | |||
+ | < | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | |||
+ | When it comes to navigation, one could, for example, create a few aliases to speed up navigating up the directory tree: | ||
+ | |||
+ | < | ||
+ | alias 2.='cd ../.. ; pwd' | ||
+ | alias 3.='cd ../../.. ; pwd' | ||
+ | alias 4.='cd ../../../.. ; pwd'</ | ||
+ | |||
+ | The value of an alias can be quite complex. As you can see, '' | ||
+ | |||
+ | < | ||
+ | $ 4. | ||
+ | /home/user | ||
+ | $ cd - | ||
+ | / | ||
+ | $ 3. | ||
+ | / | ||
+ | |||
+ | Aliases can be used in a number of different ways. A few more examples: | ||
+ | |||
+ | < | ||
+ | alias slacktop=' | ||
+ | |||
+ | ===== Directory Stack ===== | ||
+ | |||
+ | BASH features some helpful directory stack buildins that help you navigate recently visited directories. | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ==== How does it work in practice? ==== | ||
+ | |||
+ | First of all, add a directory to the stack. Please note that it also automatically switches to the directory (the '' | ||
+ | |||
+ | < | ||
+ | ~/ | ||
+ | user@darkstar: | ||
+ | |||
+ | Alternatively, | ||
+ | |||
+ | < | ||
+ | |||
+ | After adding a few directories you can display the content of the stack: | ||
+ | |||
+ | < | ||
+ | 0 ~/ | ||
+ | 1 ~/ | ||
+ | 2 ~/ | ||
+ | 3 ~/ | ||
+ | 4 ~/ | ||
+ | 5 ~/ | ||
+ | 6 ~/ | ||
+ | |||
+ | Please note that the first entry always displays the current working directory so if it also sits at the top of the stack, you'll see what seems like duplicate lines. The '' | ||
+ | |||
+ | To switch to one of the directories in the stack you could issue: | ||
+ | |||
+ | < | ||
+ | user@darkstar: | ||
+ | |||
+ | Admittedly, this is not the most concise way of changing directories. To make it shorter we can add an alias and a function to the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | List the current stack by simply typing '' | ||
+ | |||
+ | < | ||
+ | { | ||
+ | position=$1 | ||
+ | if [ -z $position ]; then | ||
+ | echo "You need to specify the position of the directory in the stack" | ||
+ | else | ||
+ | cd $(dirs +$1 -l) | ||
+ | fi | ||
+ | }</ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | |||
+ | ====== Sources ====== | ||
+ | <!-- If you are copying information from another source, then specify that source --> | ||
+ | * Original source: [[http:// | ||
+ | <!-- * Contributions by [[wiki: | ||
+ | |||
+ | <!-- Please do not modify anything below, except adding new tags.--> | ||
+ | <!-- You must remove the tag-word " | ||
+ | {{tag> |