Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:03:06+00:00 2026-06-12T15:03:06+00:00

I am new in bash scripting and I have to write a script that

  • 0

I am new in bash scripting and I have to write a script that finds the newest .mpg file in directory and then sends it to a ftp server. So far I found command that find my file.

#! /bin/bash

find /home/user/directory -type f -mmin -50 -name *.mpg \( ! -regex ".*/\..*" \)

This works but I can’t figure out how to send the output of that command to ftp server. I’ve read that I have to use variables, but I can’t understand them so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:03:07+00:00Added an answer on June 12, 2026 at 3:03 pm

    Use can pipe the output from one command as the input to another with |

    find /home/user/directory -type f -mmin -50 -name *.mpg \( ! -regex ".*/\..*" \) | ftp ...
    

    A simpler way to find the latest mpg file:

    ls -rt /home/user/directory/*.mpg | head -1 | ftp ...
    

    If you want to send multiple files xargs will be needed i.e for the 5 newest files

    ls -rt /home/user/directory/*.mpg | head -5 | xargs ftp ...
    

    ls lists the files in the /home/user/directory/*.mpg where * is expanded to any filename where with the .mpg extention. -t tells ls to list in time order and -r is reverse sort as we want the newest first not the oldest. The head command is used to only show the number of results we want like one -1 or five -5. head is usually used for viewing only a certain number of lines in a file, to view the first line in a file we would run head -1 file.txt.

    Pipe example:

    grep is used to search for text in files/stdout

    So if you wanted to know if firefox is contained in the first line of file.txt we would pipe the output of head -1 file.txt to grep firefox

    head -1 file.txt | grep firefox

    You can pipe multiple commands together to achieve the result you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a bash script that imports a CSV file and sends
I am very new to Bash scripting. I am trying to write a script
I am new to bash scripting and would like to write a bash script
I need a bash script that goes trough a text file, finds lines starting
I am very new to bash scripting. I have the following script: cp /etc/apt/sources.list
I'm creating a bash script to create new EC2 instances and then upload a
I need to write a bash script that will take a grepable nmap output
I am trying to write a simple bash script that will use a list
I am new to bash. I need to write the script which executes the
New to bash scripting, I'm writing a script to copy my TV shows accross

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.