by
3
7
6,824
1
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 954th place
Created
Modified Feb 6, 2014
Architecturex86_64
Languagebatchfile
LicenseMIT_X11
OSLinux

Linux one liner bash code to detect file or directory from a given list

This bash code shows how to detect if a given item in a list returned by a command is actually a file or a directory, without affecting the output format.

In this case, xargs is used to pass the '{}' reference to a shell script executed for each line returned by the tree command.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/27077/Linux-one-liner-bash-code-to-detect-file?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
tree -if --noreport /home/ | xargs -I '{}' sh -c 'if [ -d {} ]; then echo "Dir {}"; else echo "File {}"; fi'
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus