Pass output of "whereis" command to "cd" to change directory in one step

Vicky Dev

I can't find a way to pass output of whereis command to cd command in same line so I don't have to do cd in the second step.

I have tried passing like below:

cd $(whereis node_modules)

Or

cd "`dirname $(whereis node_modules)`"

Also

cd "$(whereis node_modules)"

But none of the above method works.

Can somebody find what should be wrong in above codes ?

Rahul

You can do that with,

cd "`which node_modules`"

With dirname to get the directory:

cd "$(dirname "$(which node_modules)" )"

as you have mentioned in the comment I am expecting to do this in one step & assuming nod_module is a directory, so you can do that with the following command:

cd $(whereis node_modules | cut -d ' ' -f2)

(Note that the latter command assumes that the Linux whereis is being used, not the BSD one, and that the path does not contain any spaces.)

As suggested by @Dani_I, you can have a look at this Why not use "which"? What to use then?, which might be more useful.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Terminal command cd (change directory)

分類Dev

Jenkins doesn't change directory through sh 'cd directory' command

分類Dev

Difference in cd.. and cd .. (Change Directory)

分類Dev

How to put whereis result into cd?

分類Dev

How use cd command to access a directory with space

分類Dev

How to append another directory to an aliased `cd` command?

分類Dev

How to 'cd' to the output of the 'find' command in terminal

分類Dev

Using output of one command as is

分類Dev

cd into all directories, execute command on files in that directory, and return to previous current directory

分類Dev

How to change permissions for a folder and its subfolders/files in one step?

分類Dev

Problem IN piping the output of one command to other

分類Dev

How can I pass all the filenames in a directory as an argument to a command in Bash?

分類Dev

writing the output from split command to a separate directory (redux)

分類Dev

Redirecting the output directory of 'mvn package' or 'mvn compile' command

分類Dev

How to `cd` into directory with the name `-`?

分類Dev

How do I move to directory "Program Files (x86)" with CD command?

分類Dev

How to change current directory inside IF statement and reference its path with environment variable CD?

分類Dev

Makefile process all files in one directory, output to another.

分類Dev

What is the correct output of !(notThisDir) ? Copying all except one directory

分類Dev

What is the `Cd` command?

分類Dev

How to copy and add prefix to file names in one step from another directory?

分類Dev

Command prompt won't change directory to another drive

分類Dev

How to drop into docker bash and navigate to the log directory in one command

分類Dev

How to copy one directory to another with window command prompt?

分類Dev

How to refer to multiple files from a directory to one command

分類Dev

change text-color of my output on command prompt?

分類Dev

How can a command have more than one output?

分類Dev

cd to a directory and execute many commands

分類Dev

Change SQL script to output to own fields instead on one field

Related 関連記事

  1. 1

    Terminal command cd (change directory)

  2. 2

    Jenkins doesn't change directory through sh 'cd directory' command

  3. 3

    Difference in cd.. and cd .. (Change Directory)

  4. 4

    How to put whereis result into cd?

  5. 5

    How use cd command to access a directory with space

  6. 6

    How to append another directory to an aliased `cd` command?

  7. 7

    How to 'cd' to the output of the 'find' command in terminal

  8. 8

    Using output of one command as is

  9. 9

    cd into all directories, execute command on files in that directory, and return to previous current directory

  10. 10

    How to change permissions for a folder and its subfolders/files in one step?

  11. 11

    Problem IN piping the output of one command to other

  12. 12

    How can I pass all the filenames in a directory as an argument to a command in Bash?

  13. 13

    writing the output from split command to a separate directory (redux)

  14. 14

    Redirecting the output directory of 'mvn package' or 'mvn compile' command

  15. 15

    How to `cd` into directory with the name `-`?

  16. 16

    How do I move to directory "Program Files (x86)" with CD command?

  17. 17

    How to change current directory inside IF statement and reference its path with environment variable CD?

  18. 18

    Makefile process all files in one directory, output to another.

  19. 19

    What is the correct output of !(notThisDir) ? Copying all except one directory

  20. 20

    What is the `Cd` command?

  21. 21

    How to copy and add prefix to file names in one step from another directory?

  22. 22

    Command prompt won't change directory to another drive

  23. 23

    How to drop into docker bash and navigate to the log directory in one command

  24. 24

    How to copy one directory to another with window command prompt?

  25. 25

    How to refer to multiple files from a directory to one command

  26. 26

    change text-color of my output on command prompt?

  27. 27

    How can a command have more than one output?

  28. 28

    cd to a directory and execute many commands

  29. 29

    Change SQL script to output to own fields instead on one field

ホットタグ

アーカイブ