How execute a command in a separate directory without changing current working directory in Bash
In Category Bash
The following example shows how to move to a directory before executing a command and then automatically return back to the old diretory. This effectively runs the command with current directory as a different directory.
[neo@techpulp ~]# pwd /home/neo [neo@techpulp ~]# (cd /; ls) bin boot dev etc home lib lost+found media mnt opt proc root sbin selinux srv sys tmp usr var [neo@techpulp ~]# pwd /home/neo [neo@techpulp ~]#
As you can see, the commands are grouped in parenthesis so that the current directory remains same after running the commands.
Recent Comments