Fd – The Best Alternative to ‘Find’ Command for Quick File Searching

Certainly! The fd command is a convenient and fast alternative to the find command in Linux. Below are explanations and examples of using fd:

  1. Basic Usage: You can run fd without any arguments, and the output is similar to the ls -R command.
    # fd
  2. Filtering and Output Limit: To limit the output, you can use pipe redirection with the head command.
    # fd | head
  3. Find Files by Extension: Use the -e flag to filter files by extension. In this example, it finds all JPG files.
    # fd -e jpg
  4. Specify Search Directory: You can specify a search directory by providing it as an argument.
    # fd <pattern> <directory>
    
  5. Search for String in Files: Combine the -e flag with a pattern to search for files with a specific extension containing a given string.
    # fd -e php index
  6. Exclude Results: Use the -E flag to exclude results. For instance, exclude files from the “wp-content” directory.
    # fd -e php index -E wp-content
  7. Modify Permissions on Search Results: Utilize -x or --exec arguments for parallel command execution with search results. Here, it changes the permissions of JPG files.
# fd -e jpg -x chmod 644 {}
    • {}: Placeholder for the path of the search result (e.g., wp-content/uploads/01.jpg).
    • {.}: Placeholder without the file extension (e.g., wp-content/uploads/01).
    • {/}: Placeholder replaced by the basename of the search result (e.g., 01.jpg).
    • {//}: Parent directory of the discovered path (e.g., wp-content/uploads).
    • {/.}: Only the basename, without the extension (e.g., 01).

Conclusion: fd is a powerful and efficient tool that provides a simpler and faster alternative to find. While it might not replace find entirely, it’s a valuable addition to your toolkit, offering ease of use, efficient searching, and better performance.

 

 

#!bin/bash


echo "Enter First Metal"

read y

echo "Enter Last Metal"

read z


r=500
echo $y

for (( i = $y; i <= $z; i++ )) 

#for i in {"$y".."$z"}
    do
        j=`expr "$i" + "1"`
        echo "METAL$i" >> file
            echo "CONNECT METAL$i to METAL$j" >> file
            echo "METAL$i SIZE $r" >> file
            echo "METAL$i SPACE 3" >> file
            echo "METAL$i AREA 10" >> file
        echo "END" >> file
    done
echo "Enter First Metal"
read y

echo "Enter Last Metal"
read z

r=500
echo $y

for ((i = y; i <= z; i++)); do
    j=$((i + 1))
    echo "METAL$i"
    echo "CONNECT METAL${i}_ALL to METAL${j}_ALL"
    echo "METAL$i SIZE $r"
    echo "METAL$i SPACE 3"
    echo "METAL$i AREA 10"
    echo "END" >> file
done

 

 

 

Metal SPACE SIZE AREA LENGTH WIDTH HEIGHT
1 10 34 10 34 10 34
2 11 35 11 35 11 35
3 12 36 12 36 12 36
4 13 37 13 37 13 37
5 14 38 14 38 14 38
6 15 39 15 39 15 39
7 16 40 16 40 16 40
8 17 41 17 41 17 41

 

 

#!/bin/bash

# Assuming the lookup table is stored in a file named "lookup_table.txt"
LOOKUP_TABLE="lookup_table.txt"

echo "Enter First Metal"
read y

echo "Enter Last Metal"
read z

# Output file
OUTPUT_FILE="output.txt"

for (( i = y; i <= z; i++ )); do
    j=$((i + 1))

    # Extracting values from the lookup table
    SIZE=$(awk -v row=$i 'NR==row+1{print $3}' "$LOOKUP_TABLE")
    SPACE=$(awk -v row=$i 'NR==row+1{print $2}' "$LOOKUP_TABLE")
    LENGTH=$(awk -v row=$i 'NR==row+1{print $5}' "$LOOKUP_TABLE")
    WIDTH=$(awk -v row=$i 'NR==row+1{print $6}' "$LOOKUP_TABLE")
    HEIGHT=$(awk -v row=$i 'NR==row+1{print $7}' "$LOOKUP_TABLE")
    AREA=$(awk -v row=$i 'NR==row+1{print $4}' "$LOOKUP_TABLE")

    # Writing to the output file
    echo "METAL$i" >> "$OUTPUT_FILE"
    echo "CONNECT METAL$i to METAL$j" >> "$OUTPUT_FILE"
    echo "METAL$i SIZE $SIZE" >> "$OUTPUT_FILE"
    echo "METAL$i SPACE $SPACE" >> "$OUTPUT_FILE"
    echo "METAL$i LENGTH $LENGTH" >> "$OUTPUT_FILE"
    echo "METAL$i WIDTH $WIDTH" >> "$OUTPUT_FILE"
    echo "METAL$i HEIGHT $HEIGHT" >> "$OUTPUT_FILE"
    echo "METAL$i AREA $AREA" >> "$OUTPUT_FILE"
    echo "END" >> "$OUTPUT_FILE"
done

echo "Output written to $OUTPUT_FILE"

 

#!/bin/bash

echo "Enter First Metal"
read y

echo "Enter Last Metal"
read z

echo "Choose the type of lookup table:"
echo "1. lookup_table1.txt"
echo "2. lookup_table2.txt"
echo "3. lookup_table3.txt"

read choice

if [ "$choice" -eq 1 ]; then
    LOOKUP_TABLE="lookup_table1.txt"
elif [ "$choice" -eq 2 ]; then
    LOOKUP_TABLE="lookup_table2.txt"
elif [ "$choice" -eq 3 ]; then
    LOOKUP_TABLE="lookup_table3.txt"
else
    echo "Invalid choice"
    exit 1
fi

# Output file
OUTPUT_FILE="output.txt"

for (( i = y; i <= z; i++ )); do
    j=$((i + 1))

    # Extracting values from the selected lookup table
    SIZE=$(awk -v row=$i 'NR==row+1{print $3}' "$LOOKUP_TABLE")
    SPACE=$(awk -v row=$i 'NR==row+1{print $2}' "$LOOKUP_TABLE")
    LENGTH=$(awk -v row=$i 'NR==row+1{print $5}' "$LOOKUP_TABLE")
    WIDTH=$(awk -v row=$i 'NR==row+1{print $6}' "$LOOKUP_TABLE")
    HEIGHT=$(awk -v row=$i 'NR==row+1{print $7}' "$LOOKUP_TABLE")
    AREA=$(awk -v row=$i 'NR==row+1{print $4}' "$LOOKUP_TABLE")

    # Writing to the output file with a blank line between each line
    echo "METAL$i" >> "$OUTPUT_FILE"
    echo "CONNECT METAL$i to METAL$j" >> "$OUTPUT_FILE"
    echo "METAL$i SIZE $SIZE" >> "$OUTPUT_FILE"
    echo "METAL$i SPACE $SPACE" >> "$OUTPUT_FILE"
    echo "METAL$i LENGTH $LENGTH" >> "$OUTPUT_FILE"
    echo "METAL$i WIDTH $WIDTH" >> "$OUTPUT_FILE"
    echo "METAL$i HEIGHT $HEIGHT" >> "$OUTPUT_FILE"
    echo "METAL$i AREA $AREA" >> "$OUTPUT_FILE"
    echo "END" >> "$OUTPUT_FILE"
    echo >> "$OUTPUT_FILE"  # Adding a blank line
done

echo "Output written to $OUTPUT_FILE"

 

 

 

 

#!/bin/bash

# Assuming the lookup table is stored in a file named "lookup_table.txt"
LOOKUP_TABLE="lookup_table.txt"

# Output file
OUTPUT_FILE="output.txt"

# Check if the lookup table file exists
if [ ! -e "$LOOKUP_TABLE" ]; then
    echo "Lookup table file not found: $LOOKUP_TABLE"
    exit 1
fi

# Iterate through the lookup table
while read -r LAYER SPACE; do
    # Writing to the output file
    echo "PR to $LAYER width is $SPACE {" >> "$OUTPUT_FILE"
    echo -e "\tENC $LAYER PR < $SPACE" >> "$OUTPUT_FILE"
    echo -e "}\n" >> "$OUTPUT_FILE"
done < "$LOOKUP_TABLE"

echo "Output written to $OUTPUT_FILE"

 

 

METRIC PREFIX | SYMBOL | POWER OF TEN VALUE
--------------|--------|---------------------
femto         | f      | one-quadrillionth
pico          | p      | one-trillionth
nano          | n      | one-billionth
micro         |        | one-millionth
milli         | m      | one-thousandth
kilo          | k      | 10^3 (one thousand)
mega          | M      | 10^6 (one million)
giga          | G      | 10^9 (one billion)
tera          | T      | 10^12 (one trillion)

 

Leave a Reply

Your email address will not be published. Required fields are marked *