Reuse previous arguments
The !$ command returns the last file name parameter used with a command. But what happens if you have a command that used multiple file names and you want to reuse just one of them? The !:1 operator returns the first file name used in a command. The example in Listing 1 shows how you can use this operator in combination with the !$ operator. In the first command, a file is renamed to a more meaningful name, but to preserve use of the original file name, a symbolic link is created. The file kxp12.c is renamed in a more readable manner, then the link command is used to create a symbolic link back to the original file name, in case it's still used elsewhere. The !$ operator returns the file_system_access.c file name, and the !:1 operator returns the kxp12.c file name, which is the first file name of the previous comma nd.
Listing 1. Using !$ and !:1 in combination
$ mv kxp12.c file_system_access.c |
Manage directory navigation with pushd and popd
UNIX supports a wide variety of directory-navigation tools. Two of my favorite productivity tools are pushd and popd. You're certainly aware that the cd command changes your current directory. What happens if you have several directories to navigate, but you want to be able to quickly return to a location? The pushd and popd commands create a virtual directory stack, with the pushd command changing your current directory and storing it on the stack, and the popd command removing the directory from the top of the stack and returning you to that location. You can use the dirs command to display the current directory stack without pushing or popping a new directory. Listing 2 shows how you can use the pushd and popd commands to quickly navigate the directory tree.
Listing 2. Using pushd and popd to navigate the directory tree
$ pushd . ~ ~ |
The pushd and popd commands also support parameters to manipulate the directory stack. Using the +n or -n parameter, where n is a number, you can rotate the stack left or right, as shown in Listing 3.
Listing 3. Rotating the directory stack
$ dirs /usr/local/bin /var /etc ~ ~ |
Taken from here.
Comments