- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: looking for command that would CD in first dir...
Operating System - Linux
1753406
Members
7348
Online
108793
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2009 07:13 AM
02-05-2009 07:13 AM
I would like to know how i could pipe the result of a directory search to 'CD' so that upon finding the directory, it automatically goes into it.
for example, i'm looking for directory called 'foobar', i know i have it somewhere, maybe even in more than 1 place, what i want to do is search for it
find / -name "foobar" -type d
AND, once it finds the location, the 'find' command displays where it found it, but i want to go further in my initial command and automatically CD to it.
find / -name "foobar" -type d | cd
(that doesn't work)
i've tried | cd %1 or $1 or $0,
how can this be done?
for example, i'm looking for directory called 'foobar', i know i have it somewhere, maybe even in more than 1 place, what i want to do is search for it
find / -name "foobar" -type d
AND, once it finds the location, the 'find' command displays where it found it, but i want to go further in my initial command and automatically CD to it.
find / -name "foobar" -type d | cd
(that doesn't work)
i've tried | cd %1 or $1 or $0,
how can this be done?
Si tu n'as pas ce que tu aimes, aimes ce que tu as.
Solved! Go to Solution.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2009 07:17 AM
02-05-2009 07:17 AM
Solution
You can use:
cd $(find / -name "foobar" -type d)
That is called command substitution.
Also, remember that the find command may find more than one directory with the same name, then you must filter the results somehow, for example:
cd $(find / -name "foobar" -type d | head -1)
cd $(find / -name "foobar" -type d)
That is called command substitution.
Also, remember that the find command may find more than one directory with the same name, then you must filter the results somehow, for example:
cd $(find / -name "foobar" -type d | head -1)
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP