LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2018, 11:09 AM   #1
allego0227
LQ Newbie
 
Registered: Mar 2018
Posts: 1

Rep: Reputation: Disabled
How can I add specific files into another folder ?


Hi everyone

This is our school's homework :

1. add a folder named : "tmp"
2. use instruction to let directory : " /usr/share/shotwell/icons " files which file name is match the following condition :
(a) "s" begining
(b) last 3 characters is "svg" or "png"
copy to "tmp" folder , and keep all file attributes.
3.verify step 2. copy is correct.

Sorry, the original topic is Chinese and I just translate it into English

I use instruction is :
grep -E "^s"|"grep -E "svg$|png$" | cp -r /usr/share/shotwell/icons/ /tmp


But it cannot work
Which part should I correct my instruction ?
Thank U all for responding
 
Old 03-10-2018, 11:44 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,076

Rep: Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576Reputation: 1576
Quote:
Originally Posted by allego0227 View Post
Hi everyone

This is our school's homework :

1. add a folder named : "tmp"
2. use instruction to let directory : " /usr/share/shotwell/icons " files which file name is match the following condition :
(a) "s" begining
(b) last 3 characters is "svg" or "png"
copy to "tmp" folder , and keep all file attributes.
3.verify step 2. copy is correct.

Sorry, the original topic is Chinese and I just translate it into English

I use instruction is :
grep -E "^s"|"grep -E "svg$|png$" | cp -r /usr/share/shotwell/icons/ /tmp


But it cannot work
Which part should I correct my instruction ?
Thank U all for responding
What have you tried, to get it to work?

While we're happy to try and help, you really should read the second link in my signature.
 
Old 03-10-2018, 11:54 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,139

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Quote:
Originally Posted by allego0227 View Post
Hi everyone

This is our school's homework :

1. add a folder named : "tmp"
2. use instruction to let directory : " /usr/share/shotwell/icons " files which file name is match the following condition :
(a) "s" begining
(b) last 3 characters is "svg" or "png"
copy to "tmp" folder , and keep all file attributes.
3.verify step 2. copy is correct.

Sorry, the original topic is Chinese and I just translate it into English

I use instruction is :
grep -E "^s"|"grep -E "svg$|png$" | cp -r /usr/share/shotwell/icons/ /tmp


But it cannot work
Which part should I correct my instruction ?
Thank U all for responding
Code:
grep -E "^s"|"grep -E "svg$|png$" | cp -r /usr/share/shotwell/icons/ /tmp
you are trying to pipe too much, you have not fed grep properly.

using
Code:
find path -type f -name "pattern using wild card" -o -name "pattern using wild card" -exec cp -t "destination" {} +
will give you better results. You need to fill in the needed information to make it work correctly.
Code:
removed '/tmp/system-run-symbolic.symbolic.png'
removed '/tmp/system-run.png'
removed '/tmp/system-search-symbolic.symbolic.png'
removed '/tmp/system-search.png'
removed '/tmp/system-shutdown-symbolic.symbolic.png'
removed '/tmp/system-shutdown.png'
removed '/tmp/system-software-install-symbolic.symbolic.png'
removed '/tmp/system-software-install.png'
removed '/tmp/system-software-update.png'
removed '/tmp/system-suspend-hibernate.png'
removed '/tmp/system-suspend.png'
removed '/tmp/system-switch-user.png'
removed '/tmp/system-users-symbolic.symbolic.png'
removed '/tmp/system-users.png'
removed '/tmp/system.png'
is me getting rid of my results .

Last edited by BW-userx; 03-10-2018 at 12:02 PM.
 
Old 03-10-2018, 11:55 AM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
You should learn about regular expressions.
Code:
$ ls s*red*.jpg
will list all files and directories beginning with the character 's' with any number of other characters before 'red', with any number of other characters before '.', and with a 'jpg' after that.

But the attempt to use grep is inventive. In that example you should use '-' as the first operand. I also don't think you need 'E' in the grep command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Add new FTP user & give him specific folder permission only on AWS EC2 taru.tarak Linux - Newbie 2 04-26-2017 12:46 PM
I cannot copy some files to specific folder xombboxer Linux - Newbie 4 07-21-2011 04:52 AM
Best way to automatically copy files off of a cd to a specific folder? valunthar Linux - Software 2 06-24-2011 05:27 PM
[SOLVED] zipping files into a specific folder josecolella Linux - Newbie 28 01-07-2011 02:33 AM
[SOLVED] Moving files from folders and subfolders to a specific folder mrj2 Linux - Newbie 12 08-22-2010 12:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration