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 8164727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:22:51+00:00 2026-06-06T19:22:51+00:00

Its a interview question. Interviewer asked this basic shell script question when he understand

  • 0

Its a interview question. Interviewer asked this “basic” shell script question when he understand i don’t have experience in shell scripting. Here is question.

Copy files from one directory which has size greater than 500 K to another directory.

I can do it immediately in c lang but seems difficult in shell script as never tried it.I am familiar with unix basic commands so i tried it, but i can just able to extract those file names using below command.

du -sk * | awk  '{ if ($1>500) print $2 }'

Also,Let me know good shell script examples book.

  • 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-06T19:22:52+00:00Added an answer on June 6, 2026 at 7:22 pm

    du recurses into subdirectories, which is probably not desired (you could have asked for clarification if that point was ambiguous). More likely you were expected to use ls -l or ls -s to get the sizes.

    But what you did works to select some files and print their names, so let’s build on it. You have a command that outputs a list of names. You need to put the output of that command into the command line of a cp. If your du|awk outputs this:

    Makefile
    foo.c
    bar.h
    

    you want to run this:

    cp Makefile foo.c bar.h otherdirectory
    

    So how you do that is with COMMAND SUBSTITUTION which is written as $(...) like this:

    cd firstdirectory
    cp $(du -sk * | awk '{ if ($1>500) print $2 }') otherdirectory
    

    And that’s a functioning script. The du|awk command runs first, and its output is used to build the cp command. There are a lot of subtle drawbacks that would make it unsuitable for general use, but that’s how beginner-level shell scripts usually are.

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

Sidebar

Related Questions

I was asked this question in a .net/C# interview: If we have two threads
Today in an interview (junior web developer) the interviewer asked me this question: How
One of my friend was asked this question in an interview - You have
This question was asked in interview and deals with recursion/backtracking. Suppose we have two
I am aware that this is a very basic question, but an interviewer asked
I was asked the following interview-question: Suppose you have a HashSet implementation providing its
Interview question- Often its pretty easier to debug a program once you have trouble
Its more of a best practices sort of question. Here it goes... I have
I was asked this question in an interview: Is string a reference type or
This is a question that I was asked on a job interview some time

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.